From 9e2b49bb5b3e98914b1fbd9e0eff812303676556 Mon Sep 17 00:00:00 2001 From: Stefan Krah Date: Tue, 19 Mar 2019 17:31:44 +0100 Subject: [PATCH] Add PEP-3118 complex tests. --- python/test_xnd.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/python/test_xnd.py b/python/test_xnd.py index 9c0c8cb..784dfd6 100644 --- a/python/test_xnd.py +++ b/python/test_xnd.py @@ -3096,10 +3096,11 @@ def test_endian(self): 'h', 'i', 'l', 'q', 'H', 'I', 'L', 'Q', 'f', 'd', + 'F', 'D', ] if HAVE_PYTHON_36: - standard += 'e' + standard += ['e'] modifiers = ['', '<', '>'] @@ -3132,6 +3133,24 @@ def test_readonly(self): self.assertEqual(x.tolist(), [1000, 2000, 3000]) check_copy_contiguous(self, y) + @unittest.skipIf(np is None, "numpy not found") + def test_complex(self): + x = xnd([1, 2, 3], dtype="complex64") + y = np.array(x) + self.assertEqual(memoryview(y).format, "Zf") + + x = xnd([1, 2, 3], dtype="complex128") + y = np.array(x) + self.assertEqual(memoryview(y).format, "Zd") + + x = np.array([1, 2, 3], dtype="complex64") + y = xnd.from_buffer(x) + self.assertEqual(memoryview(y).format, "=Zf") + + x = np.array([1, 2, 3], dtype="complex128") + y = xnd.from_buffer(x) + self.assertEqual(memoryview(y).format, "=Zd") + class TestReshape(XndTestCase):