diff options
| author | Mircea Akos Bruma <bruma.mircea.a@gmail.com> | 2018-11-09 10:30:21 +0100 |
|---|---|---|
| committer | Mircea Akos Bruma <bruma.mircea.a@gmail.com> | 2018-11-09 10:30:21 +0100 |
| commit | dc560bd3f3669ad7c6ef3a280a209ca177b2f624 (patch) | |
| tree | d7eed6ec01c609efdc5c96d5efd238af2e4d22cd /numpy/core/tests | |
| parent | 3ce73b79d6dc151f64f3254f9eeafd681c5efa5c (diff) | |
| download | numpy-dc560bd3f3669ad7c6ef3a280a209ca177b2f624.tar.gz | |
BUG: Fix for np.dtype(ctypes.Structure) does not respect _pack_ field
See #10532
Cosmetic changes + added an additional test with a more complex
structure.
Diffstat (limited to 'numpy/core/tests')
| -rw-r--r-- | numpy/core/tests/test_dtype.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/numpy/core/tests/test_dtype.py b/numpy/core/tests/test_dtype.py index f4b118bab..39493d52d 100644 --- a/numpy/core/tests/test_dtype.py +++ b/numpy/core/tests/test_dtype.py @@ -837,6 +837,26 @@ class TestFromCTypes(object): ]) self.check(PackedStructure, expected) + def test_large_packed_structure(self): + class PackedStructure(ctypes.Structure): + _pack_ = 2 + _fields_ = [ + ('a', ctypes.c_uint8), + ('b', ctypes.c_uint16), + ('c', ctypes.c_uint8), + ('d', ctypes.c_uint16), + ('e', ctypes.c_uint32), + ('f', ctypes.c_uint32), + ('g', ctypes.c_uint8) + ] + expected = np.dtype(dict( + formats=[np.uint8, np.uint16, np.uint8, np.uint16, np.uint32, np.uint32, np.uint8 ], + offsets=[0, 2, 4, 6, 8, 12, 16], + names=['a', 'b', 'c', 'd', 'e', 'f', 'g'], + itemsize=18 + )) + self.check(PackedStructure, expected) + @pytest.mark.xfail(sys.byteorder != 'little', reason="non-native endianness does not work - see gh-10533") def test_little_endian_structure(self): |
