]> git.notmuchmail.org Git - notmuch/blob - bindings/python-cffi/tests/test_thread.py
test/T391-python-cffi
[notmuch] / bindings / python-cffi / tests / test_thread.py
1 import collections.abc
2 import time
3
4 import pytest
5
6 import notmuch2
7
8
9 @pytest.fixture
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))])
15     notmuch('new')
16     with notmuch2.Database(maildir.path) as db:
17         yield next(db.threads('foo'))
18
19
20 def test_type(thread):
21     assert isinstance(thread, notmuch2.Thread)
22     assert isinstance(thread, collections.abc.Iterable)
23
24
25 def test_threadid(thread):
26     assert isinstance(thread.threadid, notmuch2.BinString)
27     assert thread.threadid
28
29
30 def test_len(thread):
31     assert len(thread) == 2
32
33
34 def test_toplevel_type(thread):
35     assert isinstance(thread.toplevel(), collections.abc.Iterator)
36
37
38 def test_toplevel(thread):
39     msgs = thread.toplevel()
40     assert isinstance(next(msgs), notmuch2.Message)
41     with pytest.raises(StopIteration):
42         next(msgs)
43
44
45 def test_toplevel_reply(thread):
46     msg = next(thread.toplevel())
47     assert isinstance(next(msg.replies()), notmuch2.Message)
48
49
50 def test_iter(thread):
51     msgs = list(iter(thread))
52     assert len(msgs) == len(thread)
53     for msg in msgs:
54         assert isinstance(msg, notmuch2.Message)
55
56
57 def test_matched(thread):
58     assert thread.matched == 1
59
60
61 def test_authors_type(thread):
62     assert isinstance(thread.authors, notmuch2.BinString)
63
64
65 def test_authors(thread):
66     assert thread.authors == 'src@example.com'
67
68
69 def test_subject(thread):
70     assert thread.subject == 'Test mail'
71
72
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
78
79
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
85
86
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
91
92
93 def test_tags_type(thread):
94     assert isinstance(thread.tags, notmuch2.ImmutableTagSet)
95
96
97 def test_tags_cache(thread):
98     assert thread.tags is thread.tags
99
100
101 def test_tags(thread):
102     assert 'inbox' in thread.tags