diff options
author | Marc-André Lemburg <mal@egenix.com> | 2002-12-29 19:44:06 (GMT) |
---|---|---|
committer | Marc-André Lemburg <mal@egenix.com> | 2002-12-29 19:44:06 (GMT) |
commit | 79f57833f3df0d2f3dd08639f436113286ee6067 (patch) | |
tree | 7dca4ea91edb396d86a857d0a5d65030284e1bb2 /Lib/test | |
parent | bbfb91041634d11c73046775f62a1c44bc729bc3 (diff) | |
download | cpython-79f57833f3df0d2f3dd08639f436113286ee6067.zip cpython-79f57833f3df0d2f3dd08639f436113286ee6067.tar.gz cpython-79f57833f3df0d2f3dd08639f436113286ee6067.tar.bz2 |
Patch for bug #659709: bogus computation of float length
Python 2.2.x backport candidate. (This bug has been around since
Python 1.6.)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_string.py | 26 | ||||
-rw-r--r-- | Lib/test/test_unicode.py | 25 |
2 files changed, 51 insertions, 0 deletions
diff --git a/Lib/test/test_string.py b/Lib/test/test_string.py index a30cdbd..6361f78 100644 --- a/Lib/test/test_string.py +++ b/Lib/test/test_string.py @@ -57,3 +57,29 @@ string_tests.run_inplace_tests(str) string.whitespace string.lowercase string.uppercase + +# Float formatting +for prec in range(100): + formatstring = u'%%.%if' % prec + value = 0.01 + for x in range(60): + value = value * 3.141592655 / 3.0 * 10.0 + #print 'Overflow check for x=%i and prec=%i:' % \ + # (x, prec), + try: + result = formatstring % value + except OverflowError: + # The formatfloat() code in stringobject.c and + # unicodeobject.c uses a 120 byte buffer and switches from + # 'f' formatting to 'g' at precision 50, so we expect + # OverflowErrors for the ranges x < 50 and prec >= 67. + if x >= 50 or \ + prec < 67: + print '*** unexpected OverflowError for x=%i and prec=%i' % (x, prec) + else: + #print 'OverflowError' + pass + else: + #print result + pass + diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 66a7f91..2a94586 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -476,6 +476,31 @@ for ordinal in (-100, 0x200000): else: print '*** formatting u"%%c" %% %i should give a ValueError' % ordinal +# float formatting +for prec in range(100): + formatstring = u'%%.%if' % prec + value = 0.01 + for x in range(60): + value = value * 3.141592655 / 3.0 * 10.0 + #print 'Overflow check for x=%i and prec=%i:' % \ + # (x, prec), + try: + result = formatstring % value + except OverflowError: + # The formatfloat() code in stringobject.c and + # unicodeobject.c uses a 120 byte buffer and switches from + # 'f' formatting to 'g' at precision 50, so we expect + # OverflowErrors for the ranges x < 50 and prec >= 67. + if x >= 50 or \ + prec < 67: + print '*** unexpected OverflowError for x=%i and prec=%i' % (x, prec) + else: + #print 'OverflowError' + pass + else: + #print result + pass + # formatting jobs delegated from the string implementation: verify('...%(foo)s...' % {'foo':u"abc"} == u'...abc...') verify('...%(foo)s...' % {'foo':"abc"} == '...abc...') |