def test_invalid_sample_count(self): with self.assertRaises(ValueError): array_storage.pack({}, sample_count=-1) array_storage.pack({}, sample_count=0) array_storage.pack({}, sample_count=2 ** 24 - 1) with self.assertRaises(ValueError): array_storage.pack({}, sample_count=2**24)
def test_single_float32(self): x = np.arange(0, 10, 0.25, dtype=np.float32) b = array_storage.pack({3: x}, sample_count=43) y, c = array_storage.unpack(b) self.assertEqual(c, 43) self.assertIn(3, y) np.testing.assert_equal(y[3], x)
def test_single_u8(self): x = np.arange(256, dtype=np.uint8) b = array_storage.pack({2: x}, sample_count=42) y, c = array_storage.unpack(b) self.assertEqual(c, 42) self.assertIn(2, y) np.testing.assert_equal(y[2], x)
def test_multiple(self): x_u8 = np.arange(256, dtype=np.uint8) x_f32 = np.arange(0, 10, 0.25, dtype=np.float32) x = {9: x_u8, 5: x_f32} b = array_storage.pack(x, sample_count=44) y, c = array_storage.unpack(b) self.assertEqual(c, 44) self.assertEqual(len(y), 2) np.testing.assert_equal(y[9], x_u8) np.testing.assert_equal(y[5], x_f32)
def test_truncated(self): x = np.arange(0, 10, 0.25, dtype=np.float32) b = array_storage.pack({3: x}, sample_count=43) with self.assertRaises(ValueError): array_storage.unpack(b[:-16])
def test_invalid_array_id(self): x = np.arange(256, dtype=np.uint8) with self.assertRaises(ValueError): array_storage.pack({-1: x}, sample_count=42)
def test_empty(self): b = array_storage.pack({}, sample_count=0) y, c = array_storage.unpack(b) self.assertEqual(c, 0) self.assertEqual(len(y), 0)