3 from notdb import _base as base
4 from notdb import _errors as errors
7 class TestNotmuchObject:
9 def test_no_impl_methods(self):
10 class Object(base.NotmuchObject):
12 with pytest.raises(TypeError):
15 def test_impl_methods(self):
17 class Object(base.NotmuchObject):
26 def _destroy(self, parent=False):
34 class Object(base.NotmuchObject):
43 def _destroy(self, parent=False):
52 class TestMemoryPointer:
57 ptr = base.MemoryPointer()
60 def test_unset(self, obj):
61 with pytest.raises(errors.ObjectDestroyedError):
64 def test_set(self, obj):
66 assert obj.ptr == 'some'
68 def test_cleared(self, obj):
72 with pytest.raises(errors.ObjectDestroyedError):
75 def test_two_instances(self, obj):
76 obj2 = obj.__class__()
79 assert obj.ptr != obj2.ptr
85 s = base.BinString(b'foo')
86 assert isinstance(s, str)
88 def test_init_bytes(self):
89 s = base.BinString(b'foo')
92 def test_init_str(self):
93 s = base.BinString('foo')
97 s = base.BinString(b'foo')
98 assert bytes(s) == b'foo'
100 def test_invalid_utf8(self):
101 s = base.BinString(b'\x80foo')
103 assert bytes(s) == b'\x80foo'
105 def test_errors(self):
106 s = base.BinString(b'\x80foo', errors='replace')
108 assert bytes(s) == b'\x80foo'
110 def test_encoding(self):
111 # pound sign: '£' == '\u00a3' latin-1: b'\xa3', utf-8: b'\xc2\xa3'
112 with pytest.raises(UnicodeDecodeError):
113 base.BinString(b'\xa3', errors='strict')
114 s = base.BinString(b'\xa3', encoding='latin-1', errors='strict')
116 assert bytes(s) == b'\xa3'