5 import notmuch2._database as dbmod
7 import notmuch2._config as config
13 def db(self, maildir):
14 with dbmod.Database.create(maildir.path) as db:
17 def test_type(self, db):
18 assert isinstance(db.config, collections.abc.MutableMapping)
19 assert isinstance(db.config, config.ConfigMapping)
21 def test_alive(self, db):
22 assert db.config.alive
24 def test_set_get(self, maildir):
25 # Ensure get-set works from different db objects
26 with dbmod.Database.create(maildir.path) as db0:
27 db0.config['spam'] = 'ham'
28 with dbmod.Database(maildir.path) as db1:
29 assert db1.config['spam'] == 'ham'
31 def test_get_keyerror(self, db):
32 with pytest.raises(KeyError):
33 val = db.config['not-a-key']
36 def test_iter(self, db):
37 assert list(db.config) == []
38 db.config['spam'] = 'ham'
39 db.config['eggs'] = 'bacon'
40 assert set(db.config) == {'spam', 'eggs'}
41 assert set(db.config.keys()) == {'spam', 'eggs'}
42 assert set(db.config.values()) == {'ham', 'bacon'}
43 assert set(db.config.items()) == {('spam', 'ham'), ('eggs', 'bacon')}
45 def test_len(self, db):
46 assert len(db.config) == 0
47 db.config['spam'] = 'ham'
48 assert len(db.config) == 1
49 db.config['eggs'] = 'bacon'
50 assert len(db.config) == 2
52 def test_del(self, db):
53 db.config['spam'] = 'ham'
54 assert db.config.get('spam') == 'ham'
56 assert db.config.get('spam') is None