summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_format.py
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2000-12-15 13:09:06 (GMT)
committerAndrew M. Kuchling <amk@amk.ca>2000-12-15 13:09:06 (GMT)
commit4d192b37ecaee5948d92eee0519de391c0b7b446 (patch)
treef1721b2344dc41f1ccf222ca0f2c17760b675e08 /Lib/test/test_format.py
parent6ca8917758c90bb8de4d3698f9c6ba84167035f5 (diff)
downloadcpython-4d192b37ecaee5948d92eee0519de391c0b7b446.zip
cpython-4d192b37ecaee5948d92eee0519de391c0b7b446.tar.gz
cpython-4d192b37ecaee5948d92eee0519de391c0b7b446.tar.bz2
Add test case for error message raised by bad % format character
(Oh, look, it adds another little utility function for testing)
Diffstat (limited to 'Lib/test/test_format.py')
-rw-r--r--Lib/test/test_format.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_format.py b/Lib/test/test_format.py
index c2c7244..4778a8b 100644
--- a/Lib/test/test_format.py
+++ b/Lib/test/test_format.py
@@ -174,3 +174,28 @@ testboth("%o", 042, "42")
# 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")
+