It is tempting to use a generator function instead, but this would
not correctly respect the :class:`NotmuchObject` memory handling
protocol and in some unsuspecting cornercases cause memory
- trouble. You probably want to sublcass this in order to wrap the
+ trouble. You probably want to subclass this in order to wrap the
value returned by :meth:`__next__`.
:param parent: The parent object.
def __next__(self):
if not self._fn_valid(self._iter_p):
- self._destroy()
raise StopIteration()
obj_p = self._fn_get(self._iter_p)
self._fn_next(self._iter_p)
def getall(self, prefix='', *, exact=False):
"""Return an iterator yielding all properties for a given key prefix.
- The returned iterator yields all peroperties which start with
+ The returned iterator yields all properties which start with
a given key prefix as ``(key, value)`` namedtuples. If called
with ``exact=True`` then only properties which exactly match
the prefix are returned, those a key longer than the prefix
def __next__(self):
if not self._fn_valid(self._iter_p):
- self._destroy()
raise StopIteration
key = capi.lib.notmuch_message_properties_key(self._iter_p)
value = capi.lib.notmuch_message_properties_value(self._iter_p)
This executes the query and returns an iterator over the
:class:`Message` objects found.
"""
- msgs_pp = capi.ffi.new('notmuch_messages_t**')
+ msgs_pp = capi.ffi.new('notmuch_messages_t **')
ret = capi.lib.notmuch_query_search_messages(self._query_p, msgs_pp)
if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
raise errors.NotmuchError(ret)
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):
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):
props.add('foo', 'a')
assert set(props.getall('foo')) == {('foo', 'a')}
+ def test_getall_iter(self, props):
+ props.add('foo', 'a')
+ props.add('foobar', 'b')
+ for prop in props.getall('foo'):
+ assert isinstance(prop.value, str)
+
+ def test_getall_iter_list(self, props):
+ props.add('foo', 'a')
+ props.add('foobar', 'b')
+ res = list(props.getall('foo'))
+ assert len(res) == 2
+ for prop in res:
+ assert isinstance(prop.value, str)
+
def test_getall_prefix(self, props):
props.add('foo', 'a')
props.add('foobar', 'b')