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) 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
61 def test_authors_type(thread):
62 assert isinstance(thread.authors, notmuch2.BinString)
65 def test_authors(thread):
66 assert thread.authors == 'src@example.com'
69 def test_subject(thread):
70 assert thread.subject == 'Test mail'
73 def test_first(thread):
74 # XXX Someone seems to treat things as local time instead of
75 # UTC or the other way around.
76 now = int(time.time())
77 assert abs(now - thread.first) < 3600*24
80 def test_last(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.last) < 3600*24
87 def test_first_last(thread):
88 # Sadly we only have second resolution so these will always be the
89 # same time in our tests.
90 assert thread.first <= thread.last
93 def test_tags_type(thread):
94 assert isinstance(thread.tags, notmuch2.ImmutableTagSet)
97 def test_tags_cache(thread):
98 assert thread.tags is thread.tags
101 def test_tags(thread):
102 assert 'inbox' in thread.tags