]> git.notmuchmail.org Git - notmuch/blob - bindings/python-cffi/tests/test_thread.py
emacs: Add new option notmuch-search-hide-excluded
[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, config=notmuch2.Database.CONFIG.EMPTY) 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 def test_matched_iter(thread):
61     count = 0
62     msgs = list(iter(thread))
63     for msg in msgs:
64         if msg.matched:
65             count += 1
66     assert count == thread.matched
67
68 def test_authors_type(thread):
69     assert isinstance(thread.authors, notmuch2.BinString)
70
71
72 def test_authors(thread):
73     assert thread.authors == 'src@example.com'
74
75
76 def test_subject(thread):
77     assert thread.subject == 'Test mail'
78
79
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
85
86
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
92
93
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
98
99
100 def test_tags_type(thread):
101     assert isinstance(thread.tags, notmuch2.ImmutableTagSet)
102
103
104 def test_tags_cache(thread):
105     assert thread.tags is thread.tags
106
107
108 def test_tags(thread):
109     assert 'inbox' in thread.tags