diff options
author | Ronan Lamy <ronan.lamy@gmail.com> | 2020-05-22 19:47:12 +0100 |
---|---|---|
committer | Ronan Lamy <ronan.lamy@gmail.com> | 2020-05-22 19:47:12 +0100 |
commit | c3e218be9079546db73c51319aca18c4a7b0ac72 (patch) | |
tree | 035b393dfdb80e0ffe0b556f768df62a066b8e78 /extra_tests | |
parent | memoryviews on pointers contain the pointer itself, not what it points to. Ad... (diff) | |
download | pypy-c3e218be9079546db73c51319aca18c4a7b0ac72.tar.gz pypy-c3e218be9079546db73c51319aca18c4a7b0ac72.tar.bz2 pypy-c3e218be9079546db73c51319aca18c4a7b0ac72.zip |
Replace get_format_str() with tp._getformat() and fix pointer formats
Diffstat (limited to 'extra_tests')
-rw-r--r-- | extra_tests/ctypes_tests/test_buffers.py | 34 | ||||
-rw-r--r-- | extra_tests/ctypes_tests/test_structures.py | 6 |
2 files changed, 34 insertions, 6 deletions
diff --git a/extra_tests/ctypes_tests/test_buffers.py b/extra_tests/ctypes_tests/test_buffers.py index a27a9281ac..1e360a62b3 100644 --- a/extra_tests/ctypes_tests/test_buffers.py +++ b/extra_tests/ctypes_tests/test_buffers.py @@ -1,3 +1,5 @@ +import pytest +import sys from ctypes import * def test_buffer(): @@ -36,3 +38,35 @@ def test_from_buffer_keepalive(): # this is also what we get on CPython. I don't think it makes # sense because the array contains just a copy of the number. assert array._objects == {'6': b1} + +def normalize(fmt): + if sys.byteorder == "big": + return fmt.replace('<', '>') + else: + return fmt + +@pytest.mark.parametrize("tp, fmt", [ + ## simple types + (c_char, "<c"), + (c_byte, "<b"), + (c_ubyte, "<B"), + (c_short, "<h"), + (c_ushort, "<H"), + (c_long, "<l"), + (c_ulong, "<L"), + (c_float, "<f"), + (c_double, "<d"), + (c_bool, "<?"), + (py_object, "<O"), + ## pointers + (POINTER(c_byte), "&<b"), + (POINTER(POINTER(c_long)), "&&<l"), + ## arrays and pointers + (c_double * 4, "<d"), + (c_float * 4 * 3 * 2, "<f"), + (POINTER(c_short) * 2, "&<h"), + (POINTER(c_short) * 2 * 3, "&<h"), + (POINTER(c_short * 2), "&(2)<h"), +]) +def test_memoryview_format(tp, fmt): + assert memoryview(tp()).format == normalize(fmt) diff --git a/extra_tests/ctypes_tests/test_structures.py b/extra_tests/ctypes_tests/test_structures.py index a0027e4b15..fa6ed900ae 100644 --- a/extra_tests/ctypes_tests/test_structures.py +++ b/extra_tests/ctypes_tests/test_structures.py @@ -214,9 +214,3 @@ def test_memoryview(): assert mv.format == 'T{>h:a:>h:b:}' assert mv.shape == (2, 3) assert mv.itemsize == 4 - -def test_memoryview_primitive(): - tp = c_char - fmt = '<c' - ob = tp() - assert memoryview(tp()).format == fmt |