[Python-3000-checkins] r60384 - python/branches/py3k-ctypes-pep3118/Lib/ctypes/test/test_pep3118.py
thomas.heller
python-3000-checkins at python.org
Mon Jan 28 08:45:05 CET 2008
Author: thomas.heller
Date: Mon Jan 28 08:45:04 2008
New Revision: 60384
Modified:
python/branches/py3k-ctypes-pep3118/Lib/ctypes/test/test_pep3118.py
Log:
Restructure the test so that it contains little endian format strings.
On big endian machines, the format strings are converted by replacing
'<' with '>'.
Modified: python/branches/py3k-ctypes-pep3118/Lib/ctypes/test/test_pep3118.py
==============================================================================
--- python/branches/py3k-ctypes-pep3118/Lib/ctypes/test/test_pep3118.py (original)
+++ python/branches/py3k-ctypes-pep3118/Lib/ctypes/test/test_pep3118.py Mon Jan 28 08:45:04 2008
@@ -3,21 +3,22 @@
import re, struct, sys
if sys.byteorder == "little":
- ENDIAN = "<"
+ THIS_ENDIAN = "<"
+ OTHER_ENDIAN = ">"
else:
- ENDIAN = ">"
+ THIS_ENDIAN = ">"
+ OTHER_ENDIAN = "<"
def normalize(format):
# Remove current endian specifier and white space from a format
# string
- format = format.replace(ENDIAN, "")
- format = format.replace("=", "")
+ format = format.replace(OTHER_ENDIAN, THIS_ENDIAN)
return re.sub(r"\s", "", format)
class Test(unittest.TestCase):
- def test_types(self):
- for tp, fmt, shape, itemtp in types:
+ def test_native_types(self):
+ for tp, fmt, shape, itemtp in native_types:
ob = tp()
v = memoryview(ob)
try:
@@ -59,62 +60,62 @@
class aUnion(Union):
_fields_ = [("a", c_int)]
-types = [
- # type format shape calc itemsize
+native_types = [
+ # type format shape calc itemsize
## simple types
- (c_char, "c", None, c_char),
- (c_byte, "b", None, c_byte),
- (c_ubyte, "B", None, c_ubyte),
- (c_short, "h", None, c_short),
- (c_ushort, "H", None, c_ushort),
+ (c_char, "<c", None, c_char),
+ (c_byte, "<b", None, c_byte),
+ (c_ubyte, "<B", None, c_ubyte),
+ (c_short, "<h", None, c_short),
+ (c_ushort, "<H", None, c_ushort),
# c_int and c_uint may be aliases to c_long
- #(c_int, "i", None, c_int),
- #(c_uint, "I", None, c_uint),
+ #(c_int, "<i", None, c_int),
+ #(c_uint, "<I", None, c_uint),
- (c_long, "l", None, c_long),
- (c_ulong, "L", None, c_ulong),
+ (c_long, "<l", None, c_long),
+ (c_ulong, "<L", None, c_ulong),
# c_longlong and c_ulonglong are aliases on 64-bit platforms
- #(c_longlong, "q", None, c_longlong),
- #(c_ulonglong, "Q", None, c_ulonglong),
+ #(c_longlong, "<q", None, c_longlong),
+ #(c_ulonglong, "<Q", None, c_ulonglong),
- (c_float, "f", None, c_float),
- (c_double, "d", None, c_double),
+ (c_float, "<f", None, c_float),
+ (c_double, "<d", None, c_double),
# c_longdouble may be an alias to c_double
- (c_bool, "t", None, c_bool),
- (py_object, "O", None, py_object),
+ (c_bool, "<t", None, c_bool),
+ (py_object, "<O", None, py_object),
## pointers
- (POINTER(c_byte), "&b", None, POINTER(c_byte)),
- (POINTER(POINTER(c_long)), "&&l", None, POINTER(POINTER(c_long))),
+ (POINTER(c_byte), "&<b", None, POINTER(c_byte)),
+ (POINTER(POINTER(c_long)), "&&<l", None, POINTER(POINTER(c_long))),
## arrays and pointers
- (c_double * 4, "(4)d", (4,), c_double),
- (c_float * 4 * 3 * 2, "(2,3,4)f", (2,3,4), c_float),
- (POINTER(c_short) * 2, "(2)&h", (2,), POINTER(c_short)),
- (POINTER(c_short) * 2 * 3, "(3,2)&h", (3,2,), POINTER(c_short)),
- (POINTER(c_short * 2), "&(2)h", None, POINTER(c_short)),
+ (c_double * 4, "(4)<d", (4,), c_double),
+ (c_float * 4 * 3 * 2, "(2,3,4)<f", (2,3,4), c_float),
+ (POINTER(c_short) * 2, "(2)&<h", (2,), POINTER(c_short)),
+ (POINTER(c_short) * 2 * 3, "(3,2)&<h", (3,2,), POINTER(c_short)),
+ (POINTER(c_short * 2), "&(2)<h", None, POINTER(c_short)),
## structures and unions
- (Point, "T{l:x:l:y:}", None, Point),
+ (Point, "T{<l:x:<l:y:}", None, Point),
# packed structures do not implement the pep
- (PackedPoint, "B", None, PackedPoint),
- (Point2, "T{l:x:l:y:}", None, Point2),
- (EmptyStruct, "T{}", None, EmptyStruct),
+ (PackedPoint, "B", None, PackedPoint),
+ (Point2, "T{<l:x:<l:y:}", None, Point2),
+ (EmptyStruct, "T{}", None, EmptyStruct),
# the pep does't support unions
- (aUnion, "B", None, aUnion),
+ (aUnion, "B", None, aUnion),
## other
# function signatures are not implemented
- (CFUNCTYPE(None), "X{}", None, CFUNCTYPE(None)),
+ (CFUNCTYPE(None), "X{}", None, CFUNCTYPE(None)),
]
More information about the Python-3000-checkins
mailing list