unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
blob afdbcfe071f721cc88e36b093bcc384aab291214 2403 bytes (raw)
name: bindings/python-cffi/tests/test_thread.py 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
 
import collections.abc
import time

import pytest

import notmuch2


@pytest.fixture
def thread(maildir, notmuch):
    """Return a single thread with one matched message."""
    msgid, _ = maildir.deliver(body='foo')
    maildir.deliver(body='bar',
                    headers=[('In-Reply-To', '<{}>'.format(msgid))])
    notmuch('new')
    with notmuch2.Database(maildir.path, config=notmuch2.Database.CONFIG.EMPTY) as db:
        yield next(db.threads('foo'))


def test_type(thread):
    assert isinstance(thread, notmuch2.Thread)
    assert isinstance(thread, collections.abc.Iterable)


def test_threadid(thread):
    assert isinstance(thread.threadid, notmuch2.BinString)
    assert thread.threadid


def test_len(thread):
    assert len(thread) == 2


def test_toplevel_type(thread):
    assert isinstance(thread.toplevel(), collections.abc.Iterator)


def test_toplevel(thread):
    msgs = thread.toplevel()
    assert isinstance(next(msgs), notmuch2.Message)
    with pytest.raises(StopIteration):
        next(msgs)


def test_toplevel_reply(thread):
    msg = next(thread.toplevel())
    assert isinstance(next(msg.replies()), notmuch2.Message)


def test_iter(thread):
    msgs = list(iter(thread))
    assert len(msgs) == len(thread)
    for msg in msgs:
        assert isinstance(msg, notmuch2.Message)


def test_matched(thread):
    assert thread.matched == 1


def test_authors_type(thread):
    assert isinstance(thread.authors, notmuch2.BinString)


def test_authors(thread):
    assert thread.authors == 'src@example.com'


def test_subject(thread):
    assert thread.subject == 'Test mail'


def test_first(thread):
    # XXX Someone seems to treat things as local time instead of
    #     UTC or the other way around.
    now = int(time.time())
    assert abs(now - thread.first) < 3600*24


def test_last(thread):
    # XXX Someone seems to treat things as local time instead of
    #     UTC or the other way around.
    now = int(time.time())
    assert abs(now - thread.last) < 3600*24


def test_first_last(thread):
    # Sadly we only have second resolution so these will always be the
    # same time in our tests.
    assert thread.first <= thread.last


def test_tags_type(thread):
    assert isinstance(thread.tags, notmuch2.ImmutableTagSet)


def test_tags_cache(thread):
    assert thread.tags is thread.tags


def test_tags(thread):
    assert 'inbox' in thread.tags

debug log:

solving afdbcfe0 ...
found afdbcfe0 in https://yhetil.org/notmuch.git/

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).