def test_init(self): a = containers.ArrayView() b = containers.MutableArrayView() self.assertIs(a.owner, None) self.assertIs(b.owner, None) self.assertEqual(len(a), 0) self.assertEqual(len(b), 0) self.assertEqual(bytes(a), b'') self.assertEqual(bytes(b), b'')
def test_init_buffer_mutable(self): a = bytearray(b'hello') b = containers.MutableArrayView(a) b[4] = '!' self.assertEqual(b[4], '!') self.assertEqual(bytes(b), b'hell!')
def test_convert_mutable_memoryview(self): a = bytearray(b'World is hell!') b = memoryview(containers.MutableArrayView(a)) b[-1] = ord('?') self.assertEqual(a, b'World is hell?')
def test_init_buffer_mutable_from_immutable(self): a = b'hello' with self.assertRaisesRegex(BufferError, "Object is not writable."): b = containers.MutableArrayView(a)