diff options
author | Marc-André Lemburg <mal@egenix.com> | 2000-06-30 10:26:29 (GMT) |
---|---|---|
committer | Marc-André Lemburg <mal@egenix.com> | 2000-06-30 10:26:29 (GMT) |
commit | d70141a2d9844ffaf7fbee9ca741ba62a51673ee (patch) | |
tree | d7a400bd6661e1b56dac0149ceefa36612546f0f | |
parent | e3f257e6819327e40544315cae2ad838de8ff2e1 (diff) | |
download | cpython-d70141a2d9844ffaf7fbee9ca741ba62a51673ee.zip cpython-d70141a2d9844ffaf7fbee9ca741ba62a51673ee.tar.gz cpython-d70141a2d9844ffaf7fbee9ca741ba62a51673ee.tar.bz2 |
Marc-Andre Lemburg <mal@lemburg.com>:
New test for huge formatting strings (these could cause core
dumps in previous versions).
By Trent Mick.
-rw-r--r-- | Lib/test/test_format.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Lib/test/test_format.py b/Lib/test/test_format.py new file mode 100644 index 0000000..9be9c76 --- /dev/null +++ b/Lib/test/test_format.py @@ -0,0 +1,52 @@ +from test_support import verbose +import string, sys + +# test string formatting operator (I am not sure if this is being tested +# elsewhere but, surely, some of the given cases are *not* tested because +# they crash python) +# test on unicode strings as well + +def testformat(formatstr, args, output=None): + if verbose: + if output: + print "%s %% %s =? %s ..." %\ + (repr(formatstr), repr(args), repr(output)), + else: + print "%s %% %s works? ..." % (repr(formatstr), repr(args)), + try: + result = formatstr % args + except OverflowError: + if verbose: + print 'overflow (this is fine)' + else: + if output and result != output: + if verbose: + print 'no' + print "%s %% %s == %s != %s" %\ + (repr(formatstr), repr(args), repr(result), repr(output)) + else: + if verbose: + print 'yes' + +def testboth(formatstr, *args): + testformat(formatstr, *args) + testformat(unicode(formatstr), *args) + + +testboth("%.1d", (1,), "1") +testboth("%.*d", (sys.maxint,1)) # expect overflow +testboth("%.100d", (1,), '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001') +testboth("%#.117x", (1,), '0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001') +testboth("%#.118x", (1,), '0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001') + +testboth("%f", (1.0,), "1.000000") +# these are trying to test the limits of the internal magic-number-length +# formatting buffer, if that number changes then these tests are less +# effective +testboth("%#.*g", (109, -1.e+49/3.)) +testboth("%#.*g", (110, -1.e+49/3.)) +testboth("%#.*g", (110, -1.e+100/3.)) + +# test some ridiculously large precision, expect overflow +testboth('%12.*f', (123456, 1.0)) + |