def test_init_buffer_mutable_from_immutable(self): a = memoryview(b'01234567' b'456789ab' b'89abcdef').cast('b', shape=[3, 8]) with self.assertRaisesRegex(BufferError, "underlying buffer is not writable"): b = containers.MutableStridedArrayView2D(a)
def test_init_buffer_mutable(self): a = bytearray(b'01234567' b'456789ab' b'89abcdef') b = containers.MutableStridedArrayView2D( memoryview(a).cast('b', shape=[3, 8])) b[0, 7] = '!' b[1, 7] = '!' b[2, 7] = '!' self.assertEqual(b[0][7], '!') self.assertEqual(bytes(b), b'0123456!' b'456789a!' b'89abcde!')
def test_init(self): a = containers.StridedArrayView2D() b = containers.MutableStridedArrayView2D() 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'') self.assertEqual(a.size, (0, 0)) self.assertEqual(b.size, (0, 0)) self.assertEqual(a.stride, (0, 0)) self.assertEqual(b.stride, (0, 0)) self.assertEqual(a.dimensions, 2) self.assertEqual(b.dimensions, 2)