mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-27 13:17:56 +01:00
bindings/python-cffi: search for config by default
The previous (pre-0.34.2) constructor searched for a config file but only if the database path was not specified, and only to retrieve database.path. Neither of the available options (CONFIG.SEARCH or CONFIG.NONE) matches this semantics exactly, but CONFIG.SEARCH causes less breakage for people who relied on the old behaviour to set their database.path [1]. Since it also seems like the friendlier option in the long run, this commit switches to CONFIG.SEARCH as default. This requires a certain amount of updating the pytest tests, but most users will actually have a config file, unlike the test environment. [1]: id:87fsqijx7u.fsf@metapensiero.it
This commit is contained in:
parent
9e7ea628e6
commit
8b737af28b
5 changed files with 15 additions and 12 deletions
|
@ -139,7 +139,7 @@ class Database(base.NotmuchObject):
|
||||||
path = os.fsencode(path)
|
path = os.fsencode(path)
|
||||||
return path
|
return path
|
||||||
|
|
||||||
def __init__(self, path=None, mode=MODE.READ_ONLY, config=CONFIG.EMPTY):
|
def __init__(self, path=None, mode=MODE.READ_ONLY, config=CONFIG.SEARCH):
|
||||||
if isinstance(mode, str):
|
if isinstance(mode, str):
|
||||||
mode = self.STR_MODE_MAP[mode]
|
mode = self.STR_MODE_MAP[mode]
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
|
|
|
@ -23,9 +23,9 @@ class TestIter:
|
||||||
|
|
||||||
def test_set_get(self, maildir):
|
def test_set_get(self, maildir):
|
||||||
# Ensure get-set works from different db objects
|
# Ensure get-set works from different db objects
|
||||||
with dbmod.Database.create(maildir.path) as db0:
|
with dbmod.Database.create(maildir.path, config=dbmod.Database.CONFIG.EMPTY) as db0:
|
||||||
db0.config['spam'] = 'ham'
|
db0.config['spam'] = 'ham'
|
||||||
with dbmod.Database(maildir.path) as db1:
|
with dbmod.Database(maildir.path, config=dbmod.Database.CONFIG.EMPTY) as db1:
|
||||||
assert db1.config['spam'] == 'ham'
|
assert db1.config['spam'] == 'ham'
|
||||||
|
|
||||||
def test_get_keyerror(self, db):
|
def test_get_keyerror(self, db):
|
||||||
|
|
|
@ -13,7 +13,7 @@ import notmuch2._message as message
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def db(maildir):
|
def db(maildir):
|
||||||
with dbmod.Database.create(maildir.path) as db:
|
with dbmod.Database.create(maildir.path, config=notmuch2.Database.CONFIG.EMPTY) as db:
|
||||||
yield db
|
yield db
|
||||||
|
|
||||||
|
|
||||||
|
@ -293,7 +293,7 @@ class TestQuery:
|
||||||
maildir.deliver(body='baz',
|
maildir.deliver(body='baz',
|
||||||
headers=[('In-Reply-To', '<{}>'.format(msgid))])
|
headers=[('In-Reply-To', '<{}>'.format(msgid))])
|
||||||
notmuch('new')
|
notmuch('new')
|
||||||
with dbmod.Database(maildir.path, 'rw') as db:
|
with dbmod.Database(maildir.path, 'rw', config=notmuch2.Database.CONFIG.EMPTY) as db:
|
||||||
yield db
|
yield db
|
||||||
|
|
||||||
def test_count_messages(self, db):
|
def test_count_messages(self, db):
|
||||||
|
|
|
@ -23,7 +23,7 @@ class TestImmutable:
|
||||||
"""
|
"""
|
||||||
maildir.deliver()
|
maildir.deliver()
|
||||||
notmuch('new')
|
notmuch('new')
|
||||||
with database.Database(maildir.path) as db:
|
with database.Database(maildir.path, config=database.Database.CONFIG.EMPTY) as db:
|
||||||
yield db.tags
|
yield db.tags
|
||||||
|
|
||||||
def test_type(self, tagset):
|
def test_type(self, tagset):
|
||||||
|
@ -33,7 +33,7 @@ class TestImmutable:
|
||||||
def test_hash(self, tagset, maildir, notmuch):
|
def test_hash(self, tagset, maildir, notmuch):
|
||||||
h0 = hash(tagset)
|
h0 = hash(tagset)
|
||||||
notmuch('tag', '+foo', '*')
|
notmuch('tag', '+foo', '*')
|
||||||
with database.Database(maildir.path) as db:
|
with database.Database(maildir.path, config=database.Database.CONFIG.EMPTY) as db:
|
||||||
h1 = hash(db.tags)
|
h1 = hash(db.tags)
|
||||||
assert h0 != h1
|
assert h0 != h1
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ class TestImmutable:
|
||||||
|
|
||||||
def test_neq(self, tagset, maildir, notmuch):
|
def test_neq(self, tagset, maildir, notmuch):
|
||||||
notmuch('tag', '+foo', '*')
|
notmuch('tag', '+foo', '*')
|
||||||
with database.Database(maildir.path) as db:
|
with database.Database(maildir.path, config=database.Database.CONFIG.EMPTY) as db:
|
||||||
assert tagset != db.tags
|
assert tagset != db.tags
|
||||||
|
|
||||||
def test_contains(self, tagset):
|
def test_contains(self, tagset):
|
||||||
|
@ -159,7 +159,8 @@ class TestMutableTagset:
|
||||||
_, pathname = maildir.deliver()
|
_, pathname = maildir.deliver()
|
||||||
notmuch('new')
|
notmuch('new')
|
||||||
with database.Database(maildir.path,
|
with database.Database(maildir.path,
|
||||||
mode=database.Mode.READ_WRITE) as db:
|
mode=database.Mode.READ_WRITE,
|
||||||
|
config=database.Database.CONFIG.EMPTY) as db:
|
||||||
msg = db.get(pathname)
|
msg = db.get(pathname)
|
||||||
yield msg.tags
|
yield msg.tags
|
||||||
|
|
||||||
|
@ -195,7 +196,8 @@ class TestMutableTagset:
|
||||||
_, pathname = maildir.deliver(flagged=True)
|
_, pathname = maildir.deliver(flagged=True)
|
||||||
notmuch('new')
|
notmuch('new')
|
||||||
with database.Database(maildir.path,
|
with database.Database(maildir.path,
|
||||||
mode=database.Mode.READ_WRITE) as db:
|
mode=database.Mode.READ_WRITE,
|
||||||
|
config=database.Database.CONFIG.EMPTY) as db:
|
||||||
msg = db.get(pathname)
|
msg = db.get(pathname)
|
||||||
msg.tags.discard('flagged')
|
msg.tags.discard('flagged')
|
||||||
msg.tags.from_maildir_flags()
|
msg.tags.from_maildir_flags()
|
||||||
|
@ -205,7 +207,8 @@ class TestMutableTagset:
|
||||||
_, pathname = maildir.deliver(flagged=True)
|
_, pathname = maildir.deliver(flagged=True)
|
||||||
notmuch('new')
|
notmuch('new')
|
||||||
with database.Database(maildir.path,
|
with database.Database(maildir.path,
|
||||||
mode=database.Mode.READ_WRITE) as db:
|
mode=database.Mode.READ_WRITE,
|
||||||
|
config=database.Database.CONFIG.EMPTY) as db:
|
||||||
msg = db.get(pathname)
|
msg = db.get(pathname)
|
||||||
flags = msg.path.name.split(',')[-1]
|
flags = msg.path.name.split(',')[-1]
|
||||||
assert 'F' in flags
|
assert 'F' in flags
|
||||||
|
|
|
@ -13,7 +13,7 @@ def thread(maildir, notmuch):
|
||||||
maildir.deliver(body='bar',
|
maildir.deliver(body='bar',
|
||||||
headers=[('In-Reply-To', '<{}>'.format(msgid))])
|
headers=[('In-Reply-To', '<{}>'.format(msgid))])
|
||||||
notmuch('new')
|
notmuch('new')
|
||||||
with notmuch2.Database(maildir.path) as db:
|
with notmuch2.Database(maildir.path, config=notmuch2.Database.CONFIG.EMPTY) as db:
|
||||||
yield next(db.threads('foo'))
|
yield next(db.threads('foo'))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue