]> git.notmuchmail.org Git - notmuch/blob - bindings/python-cffi/tests/test_config.py
test/T391-python-cffi
[notmuch] / bindings / python-cffi / tests / test_config.py
1 import collections.abc
2
3 import pytest
4
5 import notmuch2._database as dbmod
6
7 import notmuch2._config as config
8
9
10 class TestIter:
11
12     @pytest.fixture
13     def db(self, maildir):
14         with dbmod.Database.create(maildir.path) as db:
15             yield db
16
17     def test_type(self, db):
18         assert isinstance(db.config, collections.abc.MutableMapping)
19         assert isinstance(db.config, config.ConfigMapping)
20
21     def test_alive(self, db):
22         assert db.config.alive
23
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'
30
31     def test_get_keyerror(self, db):
32         with pytest.raises(KeyError):
33             val = db.config['not-a-key']
34             print(repr(val))
35
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')}
44
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
51
52     def test_del(self, db):
53         db.config['spam'] = 'ham'
54         assert db.config.get('spam') == 'ham'
55         del db.config['spam']
56         assert db.config.get('spam') is None