aboutsummaryrefslogtreecommitdiff
path: root/bindings/python-cffi/tests/test_database.py
diff options
context:
space:
mode:
authorLars Kotthoff <lars@larsko.org>2025-02-05 19:52:51 -0700
committerDavid Bremner <david@tethera.net>2025-02-07 12:13:16 -0400
commit9c1f6cf746725af7bbbb66e746c5d694723ac0eb (patch)
treef3c1b7b0fc87fa2970bddadb1f9efedf2102bee0 /bindings/python-cffi/tests/test_database.py
parent409ad6b2a897c1571044bf6e4021a35fbd85b122 (diff)
fix segfaults in Python cFFI API and add tests
Several iterators in the Python cFFI API destroyed the objects they iterated over too early (when the iterator was exhausted), causing subsequent segfaults in common cases like creating a list from the iterator. This patch fixes the segfaults and add tests to ensure that they don't happen again.
Diffstat (limited to 'bindings/python-cffi/tests/test_database.py')
-rw-r--r--bindings/python-cffi/tests/test_database.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/bindings/python-cffi/tests/test_database.py b/bindings/python-cffi/tests/test_database.py
index f1d12ea6..1557235d 100644
--- a/bindings/python-cffi/tests/test_database.py
+++ b/bindings/python-cffi/tests/test_database.py
@@ -303,6 +303,18 @@ class TestQuery:
msgs = db.messages('*')
assert isinstance(msgs, collections.abc.Iterator)
+ def test_messages_iterator(self, db):
+ for msg in db.messages('*'):
+ assert isinstance(msg, notmuch2.Message)
+ assert isinstance(msg.messageid, str)
+
+ def test_messages_iterator_list(self, db):
+ msgs = list(db.messages('*'))
+ assert len(msgs) == 3
+ for msg in msgs:
+ assert isinstance(msg, notmuch2.Message)
+ assert isinstance(msg.messageid, str)
+
def test_message_no_results(self, db):
msgs = db.messages('not_a_matching_query')
with pytest.raises(StopIteration):
@@ -320,6 +332,25 @@ class TestQuery:
threads = db.threads('*')
assert isinstance(threads, collections.abc.Iterator)
+ def test_threads_iterator(self, db):
+ for t in db.threads('*'):
+ assert isinstance(t, notmuch2.Thread)
+ assert isinstance(t.threadid, str)
+ for msg in t:
+ assert isinstance(msg, notmuch2.Message)
+ assert isinstance(msg.messageid, str)
+
+ def test_threads_iterator_list(self, db):
+ threads = list(db.threads('*'))
+ assert len(threads) == 2
+ for t in threads:
+ assert isinstance(t, notmuch2.Thread)
+ assert isinstance(t.threadid, str)
+ msgs = list(t)
+ for msg in msgs:
+ assert isinstance(msg, notmuch2.Message)
+ assert isinstance(msg.messageid, str)
+
def test_threads_no_match(self, db):
threads = db.threads('not_a_matching_query')
with pytest.raises(StopIteration):