From a0d2dab5944dc8bbfdf00e0f0250e013c174f4a4 Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Sun, 24 Apr 2016 14:27:24 +0200 Subject: [PATCH] test/pyon: arrays and complex types --- artiq/test/test_serialization.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/artiq/test/test_serialization.py b/artiq/test/test_serialization.py index 841010df8..369c36fd2 100644 --- a/artiq/test/test_serialization.py +++ b/artiq/test/test_serialization.py @@ -14,14 +14,27 @@ _pyon_test_object = { "a": np.int8(9), "b": np.int16(-98), "c": np.int32(42), "d": np.int64(-5), "e": np.uint8(8), "f": np.uint16(5), "g": np.uint32(4), "h": np.uint64(9), "x": np.float16(9.0), "y": np.float32(9.0), "z": np.float64(9.0), + 1j: 1-9j, + "q": np.complex128(1j), } class PYON(unittest.TestCase): def test_encdec(self): for enc in pyon.encode, lambda x: pyon.encode(x, True): - self.assertEqual(pyon.decode(enc(_pyon_test_object)), - _pyon_test_object) + with self.subTest(enc=enc): + self.assertEqual(pyon.decode(enc(_pyon_test_object)), + _pyon_test_object) + + def test_encdec_array(self): + orig = {k: (np.array(v), np.array([v])) + for k, v in _pyon_test_object.items() + if np.isscalar(v)} + for enc in pyon.encode, lambda x: pyon.encode(x, True): + result = pyon.decode(enc(orig)) + for k in orig: + with self.subTest(enc=enc, k=k, v=orig[k]): + np.testing.assert_equal(result[k], orig[k]) _json_test_object = {