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, config=dbmod.Database.CONFIG.EMPTY) as db0:
27 db0.config['spam'] = 'ham'
28 with dbmod.Database(maildir.path, config=dbmod.Database.CONFIG.EMPTY) 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):
38 return x.startswith('TEST.')
40 assert [ x for x in db.config if has_prefix(x) ] == []
41 db.config['TEST.spam'] = 'TEST.ham'
42 db.config['TEST.eggs'] = 'TEST.bacon'
43 assert { x for x in db.config if has_prefix(x) } == {'TEST.spam', 'TEST.eggs'}
44 assert { x for x in db.config.keys() if has_prefix(x) } == {'TEST.spam', 'TEST.eggs'}
45 assert { x for x in db.config.values() if has_prefix(x) } == {'TEST.ham', 'TEST.bacon'}
46 assert { (x, y) for (x,y) in db.config.items() if has_prefix(x) } == \
47 {('TEST.spam', 'TEST.ham'), ('TEST.eggs', 'TEST.bacon')}
49 def test_len(self, db):
50 defaults = len(db.config)
51 db.config['spam'] = 'ham'
52 assert len(db.config) == defaults + 1
53 db.config['eggs'] = 'bacon'
54 assert len(db.config) == defaults + 2
56 def test_del(self, db):
57 db.config['spam'] = 'ham'
58 assert db.config.get('spam') == 'ham'
60 assert db.config.get('spam') is None