def test_array_import_export_using_buffer(self): s = FloatArray([1, 2, 3]) buf = buffer(s.buffer()) s.free() self.assertEqual(len(buf), 12) copy = FloatArray(buf, 12) self.assertListEqual(copy.values(), [1, 2, 3]) copy.free() s = FloatArray() self.assertEqual(s.buffer(), None) s.free()
def test_array_import_export(self): s = FloatArray([1, 2, 3]) buf = str(s.buffer()) s.free() self.assertEqual(len(buf), 12) copy = FloatArray(buf, 12) self.assertEqual(copy.values(), [1, 2, 3]) copy.free() s = FloatArray() self.assertIsNone(s.buffer()) s.free()
def test_array_buffer_offset(self): s = FloatArray([1, 2, 3]) buf = s.buffer(byte_offset=4) s.free() self.assertEqual(len(buf), 8) copy = FloatArray(buf, 8) self.assertListEqual(copy.values(), [2, 3]) copy.free()
def test_use_array_after_free_error(self): s = FloatArray() s.free() with self.assertRaises(GaugedUseAfterFreeError): len(s) with self.assertRaises(GaugedUseAfterFreeError): s.values() with self.assertRaises(GaugedUseAfterFreeError): s.values() with self.assertRaises(GaugedUseAfterFreeError): s.append(1) with self.assertRaises(GaugedUseAfterFreeError): s.byte_length() with self.assertRaises(GaugedUseAfterFreeError): s.buffer() with self.assertRaises(GaugedUseAfterFreeError): s.clear()