Changed test so it no longer runs as a side effect of importing.

This commit is contained in:
Jerry Seutter 2008-03-26 05:32:51 +00:00
parent 22b3e3aff8
commit 9f7af8d4da

View file

@ -1,7 +1,9 @@
from test.test_support import verbose, have_unicode, TestFailed
import sys
from test.test_support import MAX_Py_ssize_t
maxsize = MAX_Py_ssize_t
from test.test_support import verbose, have_unicode, TestFailed
import test.test_support as test_support
import unittest
maxsize = test_support.MAX_Py_ssize_t
# 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
@ -11,6 +13,7 @@ maxsize = MAX_Py_ssize_t
overflowok = 1
overflowrequired = 0
def testformat(formatstr, args, output=None, limit=None):
if verbose:
if output:
@ -51,12 +54,15 @@ def testformat(formatstr, args, output=None, limit=None):
if verbose:
print 'yes'
def testboth(formatstr, *args):
testformat(formatstr, *args)
if have_unicode:
testformat(unicode(formatstr), *args)
class FormatTest(unittest.TestCase):
def test_format(self):
testboth("%.1d", (1,), "1")
testboth("%.*d", (sys.maxint,1)) # expect overflow
testboth("%.100d", (1,), '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001')
@ -280,3 +286,10 @@ if maxsize == 2**31-1:
pass
else:
raise TestFailed, '"%*d"%(maxsize, -127) should fail'
def test_main():
test_support.run_unittest(FormatTest)
if __name__ == "__main__":
unittest.main()