summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_format.py
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2008-02-24 13:08:18 (GMT)
committerChristian Heimes <christian@cheimes.de>2008-02-24 13:08:18 (GMT)
commita612dc02ced728f553dcc91ca557a2a8b7fa0ca6 (patch)
tree62b717da0813ba63b61537d380ea923a1e657b3d /Lib/test/test_format.py
parent8e21a3cf059aa8195716f6e7d3bfd0602daca6f1 (diff)
downloadcpython-a612dc02ced728f553dcc91ca557a2a8b7fa0ca6.zip
cpython-a612dc02ced728f553dcc91ca557a2a8b7fa0ca6.tar.gz
cpython-a612dc02ced728f553dcc91ca557a2a8b7fa0ca6.tar.bz2
Merged revisions 61034-61036,61038-61048 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r61034 | georg.brandl | 2008-02-24 01:03:22 +0100 (Sun, 24 Feb 2008) | 4 lines #900744: If an invalid chunked-encoding header is sent by a server, httplib will now raise IncompleteRead and close the connection instead of raising ValueError. ........ r61035 | georg.brandl | 2008-02-24 01:14:24 +0100 (Sun, 24 Feb 2008) | 2 lines #1627: httplib now ignores negative Content-Length headers. ........ r61039 | andrew.kuchling | 2008-02-24 03:39:15 +0100 (Sun, 24 Feb 2008) | 1 line Remove stray word ........ r61040 | neal.norwitz | 2008-02-24 03:40:58 +0100 (Sun, 24 Feb 2008) | 3 lines Add a little info to the 3k deprecation warnings about what to use instead. Suggested by Raymond Hettinger. ........ r61041 | facundo.batista | 2008-02-24 04:17:21 +0100 (Sun, 24 Feb 2008) | 4 lines Issue 1742669. Now %d accepts very big float numbers. Thanks Gabriel Genellina. ........ r61046 | neal.norwitz | 2008-02-24 08:21:56 +0100 (Sun, 24 Feb 2008) | 5 lines Get ctypes working on the Alpha (Tru64). The problem was that there were two module_methods and the one used depended on the order the modules were loaded. By making the test module_methods static, it is not exported and the correct version is picked up. ........ r61048 | neal.norwitz | 2008-02-24 09:27:49 +0100 (Sun, 24 Feb 2008) | 1 line Fix typo of hexidecimal ........
Diffstat (limited to 'Lib/test/test_format.py')
-rw-r--r--Lib/test/test_format.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/Lib/test/test_format.py b/Lib/test/test_format.py
index 9f4528c..7070286 100644
--- a/Lib/test/test_format.py
+++ b/Lib/test/test_format.py
@@ -11,7 +11,7 @@ maxsize = MAX_Py_ssize_t
overflowok = 1
overflowrequired = 0
-def testformat(formatstr, args, output=None):
+def testformat(formatstr, args, output=None, limit=None):
if verbose:
if output:
print("%r %% %r =? %r ..." %\
@@ -30,11 +30,22 @@ def testformat(formatstr, args, output=None):
if verbose:
print('no')
print("overflow expected on %r %% %r" % (formatstr, args))
- elif output and result != output:
+ elif output and limit is None and result != output:
if verbose:
print('no')
print("%r %% %r == %r != %r" %\
(formatstr, args, result, output))
+ # when 'limit' is specified, it determines how many characters
+ # must match exactly; lengths must always match.
+ # ex: limit=5, '12345678' matches '12345___'
+ # (mainly for floating point format tests for which an exact match
+ # can't be guaranteed due to rounding and representation errors)
+ elif output and limit is not None and (
+ len(result)!=len(output) or result[:limit]!=output[:limit]):
+ if verbose:
+ print('no')
+ print("%s %% %s == %s != %s" % \
+ (repr(formatstr), repr(args), repr(result), repr(output)))
else:
if verbose:
print('yes')
@@ -91,6 +102,7 @@ testformat("%.2d", big, "123456789012345678901234567890")
testformat("%.30d", big, "123456789012345678901234567890")
testformat("%.31d", big, "0123456789012345678901234567890")
testformat("%32.31d", big, " 0123456789012345678901234567890")
+testformat("%d", float(big), "123456________________________", 6)
big = 0x1234567890abcdef12345 # 21 hex digits
testformat("%x", big, "1234567890abcdef12345")
@@ -128,6 +140,7 @@ testformat("%#+27.23X", big, " +0X001234567890ABCDEF12345")
testformat("%#+027.23X", big, "+0X0001234567890ABCDEF12345")
# same, except no 0 flag
testformat("%#+27.23X", big, " +0X001234567890ABCDEF12345")
+testformat("%x", float(big), "123456_______________", 6)
big = 0o12345670123456701234567012345670 # 32 octal digits
testformat("%o", big, "12345670123456701234567012345670")
@@ -169,6 +182,7 @@ testformat("%034.33o", big, "0012345670123456701234567012345670")
testformat("%0#38.33o", big, "0o000012345670123456701234567012345670")
# padding spaces come before marker
testformat("%#36.33o", big, " 0o012345670123456701234567012345670")
+testformat("%o", float(big), "123456__________________________", 6)
# Some small ints, in both Python int and long flavors).
testformat("%d", 42, "42")
@@ -186,11 +200,13 @@ testformat("%#X", 0, "0X0")
testformat("%x", 0x42, "42")
testformat("%x", -0x42, "-42")
+testformat("%x", float(0x42), "42")
testformat("%o", 0o42, "42")
testformat("%o", -0o42, "-42")
testformat("%o", 0o42, "42")
testformat("%o", -0o42, "-42")
+testformat("%o", float(0o42), "42")
# Test exception for unknown format characters
if verbose: