1import collections.abc 2import time 3 4import pytest 5 6import notmuch2 7 8 9@pytest.fixture 10def 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 20def test_type(thread): 21 assert isinstance(thread, notmuch2.Thread) 22 assert isinstance(thread, collections.abc.Iterable) 23 24 25def test_threadid(thread): 26 assert isinstance(thread.threadid, notmuch2.BinString) 27 assert thread.threadid 28 29 30def test_len(thread): 31 assert len(thread) == 2 32 33 34def test_toplevel_type(thread): 35 assert isinstance(thread.toplevel(), collections.abc.Iterator) 36 37 38def test_toplevel(thread): 39 msgs = thread.toplevel() 40 assert isinstance(next(msgs), notmuch2.Message) 41 with pytest.raises(StopIteration): 42 next(msgs) 43 44 45def test_toplevel_reply(thread): 46 msg = next(thread.toplevel()) 47 assert isinstance(next(msg.replies()), notmuch2.Message) 48 49 50def 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 57def test_matched(thread): 58 assert thread.matched == 1 59 60 61def test_authors_type(thread): 62 assert isinstance(thread.authors, notmuch2.BinString) 63 64 65def test_authors(thread): 66 assert thread.authors == 'src@example.com' 67 68 69def test_subject(thread): 70 assert thread.subject == 'Test mail' 71 72 73def 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 80def 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 87def 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 93def test_tags_type(thread): 94 assert isinstance(thread.tags, notmuch2.ImmutableTagSet) 95 96 97def test_tags_cache(thread): 98 assert thread.tags is thread.tags 99 100 101def test_tags(thread): 102 assert 'inbox' in thread.tags 103