]> granicus.if.org Git - python/commitdiff
Add test case for error message raised by bad % format character
authorAndrew M. Kuchling <amk@amk.ca>
Fri, 15 Dec 2000 13:09:06 +0000 (13:09 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Fri, 15 Dec 2000 13:09:06 +0000 (13:09 +0000)
(Oh, look, it adds another little utility function for testing)

Lib/test/test_format.py

index c2c7244582fe515bd269a5a6ac6969f7e7175595..4778a8bc0b671af830073925bde053ff91eae0d6 100644 (file)
@@ -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")
+