import pytest
-import notdb
-import notdb._errors as errors
-import notdb._database as dbmod
-import notdb._message as message
+import notmuch2
+import notmuch2._errors as errors
+import notmuch2._database as dbmod
+import notmuch2._message as message
@pytest.fixture
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
db.create(tmppath)
def test_create_existing(self, tmppath, db):
- with pytest.raises(errors.FileError):
+ with pytest.raises(errors.DatabaseExistsError):
dbmod.Database.create(path=tmppath)
def test_close(self, db):
with pytest.raises(errors.UnbalancedAtomicError):
ctx.force_end()
+ def test_abort(self, db):
+ with db.atomic() as txn:
+ txn.abort()
+ assert db.closed
+
class TestRevision:
@pytest.fixture
def db(self, maildir, notmuch):
- """Return a read-only notdb.Database.
+ """Return a read-only notmuch2.Database.
The database will have 3 messages, 2 threads.
"""
maildir.deliver(body='baz',
headers=[('In-Reply-To', '<{}>'.format(msgid))])
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
def test_count_messages(self, db):
def test_message_match(self, db):
msgs = db.messages('*')
msg = next(msgs)
- assert isinstance(msg, notdb.Message)
+ assert isinstance(msg, notmuch2.Message)
def test_count_threads(self, db):
assert db.count_threads('*') == 2
def test_threads_match(self, db):
threads = db.threads('*')
thread = next(threads)
- assert isinstance(thread, notdb.Thread)
+ assert isinstance(thread, notmuch2.Thread)
+
+ def test_use_threaded_message_twice(self, db):
+ thread = next(db.threads('*'))
+ for msg in thread.toplevel():
+ assert isinstance(msg, notmuch2.Message)
+ assert msg.alive
+ del msg
+ for msg in thread:
+ assert isinstance(msg, notmuch2.Message)
+ assert msg.alive
+ del msg