10 def thread(maildir, notmuch):
11 """Return a single thread with one matched message."""
12 msgid, _ = maildir.deliver(body='foo')
13 maildir.deliver(body='bar',
14 headers=[('In-Reply-To', '<{}>'.format(msgid))])
16 with notmuch2.Database(maildir.path, config=notmuch2.Database.CONFIG.EMPTY) as db:
17 yield next(db.threads('foo'))
20 def test_type(thread):
21 assert isinstance(thread, notmuch2.Thread)
22 assert isinstance(thread, collections.abc.Iterable)
25 def test_threadid(thread):
26 assert isinstance(thread.threadid, notmuch2.BinString)
27 assert thread.threadid
31 assert len(thread) == 2
34 def test_toplevel_type(thread):
35 assert isinstance(thread.toplevel(), collections.abc.Iterator)
38 def test_toplevel(thread):
39 msgs = thread.toplevel()
40 assert isinstance(next(msgs), notmuch2.Message)
41 with pytest.raises(StopIteration):
45 def test_toplevel_reply(thread):
46 msg = next(thread.toplevel())
47 assert isinstance(next(msg.replies()), notmuch2.Message)
50 def test_iter(thread):
51 msgs = list(iter(thread))
52 assert len(msgs) == len(thread)
54 assert isinstance(msg, notmuch2.Message)
57 def test_matched(thread):
58 assert thread.matched == 1
60 def test_matched_iter(thread):
62 msgs = list(iter(thread))
66 assert count == thread.matched
68 def test_authors_type(thread):
69 assert isinstance(thread.authors, notmuch2.BinString)
72 def test_authors(thread):
73 assert thread.authors == 'src@example.com'
76 def test_subject(thread):
77 assert thread.subject == 'Test mail'
80 def test_first(thread):
81 # XXX Someone seems to treat things as local time instead of
82 # UTC or the other way around.
83 now = int(time.time())
84 assert abs(now - thread.first) < 3600*24
87 def test_last(thread):
88 # XXX Someone seems to treat things as local time instead of
89 # UTC or the other way around.
90 now = int(time.time())
91 assert abs(now - thread.last) < 3600*24
94 def test_first_last(thread):
95 # Sadly we only have second resolution so these will always be the
96 # same time in our tests.
97 assert thread.first <= thread.last
100 def test_tags_type(thread):
101 assert isinstance(thread.tags, notmuch2.ImmutableTagSet)
104 def test_tags_cache(thread):
105 assert thread.tags is thread.tags
108 def test_tags(thread):
109 assert 'inbox' in thread.tags