mirror of
https://github.com/python/cpython.git
synced 2026-02-13 19:04:37 +00:00
Add test case for error message raised by bad % format character
(Oh, look, it adds another little utility function for testing)
This commit is contained in:
parent
6ca8917758
commit
4d192b37ec
1 changed files with 25 additions and 0 deletions
|
|
@ -174,3 +174,28 @@ def testboth(formatstr, *args):
|
|||
# testboth("%o", -042, "37777777736") # Alas, that's specific to 32-bit machines
|
||||
testboth("%o", 042L, "42")
|
||||
testboth("%o", -042L, "-42")
|
||||
|
||||
# Test exception for unknown format characters
|
||||
if verbose:
|
||||
print 'Testing exceptions'
|
||||
|
||||
def test_exc(formatstr, args, exception, excmsg):
|
||||
try:
|
||||
testformat(formatstr, args)
|
||||
except exception, exc:
|
||||
if str(exc) == excmsg:
|
||||
if verbose:
|
||||
print "yes"
|
||||
else:
|
||||
if verbose: print 'no'
|
||||
print 'Unexpected ', exception, ':', repr(str(exc))
|
||||
except:
|
||||
if verbose: print 'no'
|
||||
print 'Unexpected exception'
|
||||
raise
|
||||
|
||||
test_exc('abc %a', 1, ValueError,
|
||||
"unsupported format character 'a' (0x61) at index 5")
|
||||
test_exc(u'abc %\u3000', 1, ValueError,
|
||||
"unsupported format character '\000' (0x3000) at index 5")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue