unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
blob b6d3d62cb71f8db41fe3c77920194bc8625b5acf 2658 bytes (raw)
name: bindings/python-cffi/tests/test_base.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
 
import pytest

from notdb import _base as base
from notdb import _errors as errors


class TestNotmuchObject:

    def test_no_impl_methods(self):
        class Object(base.NotmuchObject):
            pass
        with pytest.raises(TypeError):
            Object()

    def test_impl_methods(self):

        class Object(base.NotmuchObject):

            def __init__(self):
                pass

            @property
            def alive(self):
                pass

            def _destroy(self, parent=False):
                pass

        Object()

    def test_del(self):
        destroyed = False

        class Object(base.NotmuchObject):

            def __init__(self):
                pass

            @property
            def alive(self):
                pass

            def _destroy(self, parent=False):
                nonlocal destroyed
                destroyed = True

        o = Object()
        o.__del__()
        assert destroyed


class TestMemoryPointer:

    @pytest.fixture
    def obj(self):
        class Cls:
            ptr = base.MemoryPointer()
        return Cls()

    def test_unset(self, obj):
        with pytest.raises(errors.ObjectDestroyedError):
            obj.ptr

    def test_set(self, obj):
        obj.ptr = 'some'
        assert obj.ptr == 'some'

    def test_cleared(self, obj):
        obj.ptr = 'some'
        obj.ptr
        obj.ptr = None
        with pytest.raises(errors.ObjectDestroyedError):
            obj.ptr

    def test_two_instances(self, obj):
        obj2 = obj.__class__()
        obj.ptr = 'foo'
        obj2.ptr = 'bar'
        assert obj.ptr != obj2.ptr


class TestBinString:

    def test_type(self):
        s = base.BinString(b'foo')
        assert isinstance(s, str)

    def test_init_bytes(self):
        s = base.BinString(b'foo')
        assert s == 'foo'

    def test_init_str(self):
        s = base.BinString('foo')
        assert s == 'foo'

    def test_bytes(self):
        s = base.BinString(b'foo')
        assert bytes(s) == b'foo'

    def test_invalid_utf8(self):
        s = base.BinString(b'\x80foo')
        assert s == 'foo'
        assert bytes(s) == b'\x80foo'

    def test_errors(self):
        s = base.BinString(b'\x80foo', errors='replace')
        assert s == '�foo'
        assert bytes(s) == b'\x80foo'

    def test_encoding(self):
        # pound sign: '£' == '\u00a3' latin-1: b'\xa3', utf-8: b'\xc2\xa3'
        with pytest.raises(UnicodeDecodeError):
            base.BinString(b'\xa3', errors='strict')
        s = base.BinString(b'\xa3', encoding='latin-1', errors='strict')
        assert s == '£'
        assert bytes(s) == b'\xa3'

debug log:

solving b6d3d62c ...
found b6d3d62c 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).