diff options
author | Guido van Rossum <guido@python.org> | 1997-01-03 00:09:46 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-01-03 00:09:46 (GMT) |
commit | 420c11c6aa123497a073c0bd8c61a4d80792b7c6 (patch) | |
tree | 6cc3135e84208f25b03531db0a6a852d12c61616 /Lib/test/test_struct.py | |
parent | 4ccc531f34bf6e40040b14dda9f3dde33b3b7fa9 (diff) | |
download | cpython-420c11c6aa123497a073c0bd8c61a4d80792b7c6.zip cpython-420c11c6aa123497a073c0bd8c61a4d80792b7c6.tar.gz cpython-420c11c6aa123497a073c0bd8c61a4d80792b7c6.tar.bz2 |
Added f/d tests for specific byte orders.
Diffstat (limited to 'Lib/test/test_struct.py')
-rw-r--r-- | Lib/test/test_struct.py | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py index 3d54314..954a3f2 100644 --- a/Lib/test/test_struct.py +++ b/Lib/test/test_struct.py @@ -38,16 +38,20 @@ l = 65536 f = 3.1415 d = 3.1415 -for format in ('xcbhilfd', 'xcBHILfd', '@xsbhilfd'): - s = struct.pack(format, c, b, h, i, l, f, d) - cp, bp, hp, ip, lp, fp, dp = struct.unpack(format, s) - if (cp <> c or bp <> b or hp <> h or ip <> i or lp <> l or - int(100 * fp) <> int(100 * f) or int(100 * dp) <> int(100 * d)): - # ^^^ calculate only to two decimal places - raise TestFailed, "unpack/pack not transitive (%s, %s)" % ( - str(format), str((cp, bp, hp, ip, lp, fp, dp))) +for prefix in ('', '@', '<', '>', '=', '!'): + for format in ('xcbhilfd', 'xcBHILfd'): + format = prefix + format + if verbose: + print "trying:", format + s = struct.pack(format, c, b, h, i, l, f, d) + cp, bp, hp, ip, lp, fp, dp = struct.unpack(format, s) + if (cp <> c or bp <> b or hp <> h or ip <> i or lp <> l or + int(100 * fp) <> int(100 * f) or int(100 * dp) <> int(100 * d)): + # ^^^ calculate only to two decimal places + raise TestFailed, "unpack/pack not transitive (%s, %s)" % ( + str(format), str((cp, bp, hp, ip, lp, fp, dp))) -# Test some of the new features +# Test some of the new features in detail # (format, argument, big-endian result, little-endian result, asymmetric) tests = [ @@ -77,6 +81,12 @@ tests = [ ('l', -70000000, '\373\323\342\200', '\200\342\323\373', 0), ('L', 70000000L, '\004,\035\200', '\200\035,\004', 0), ('L', 0x100000000L-70000000, '\373\323\342\200', '\200\342\323\373', 0), + ('f', 2.0, '@\000\000\000', '\000\000\000@', 0), + ('d', 2.0, '@\000\000\000\000\000\000\000', + '\000\000\000\000\000\000\000@', 0), + ('f', -2.0, '\300\000\000\000', '\000\000\000\300', 0), + ('d', -2.0, '\300\000\000\000\000\000\000\000', + '\000\000\000\000\000\000\000\300', 0), ] def badpack(fmt, arg, got, exp): |