[Python-checkins] CVS: python/dist/src/Lib/test test_format.py,1.3,1.4

A.M. Kuchling python-dev@python.org
Fri, 15 Dec 2000 05:09:09 -0800


Update of /cvsroot/python/python/dist/src/Lib/test
In directory slayer.i.sourceforge.net:/tmp/cvs-serv10608

Modified Files:
	test_format.py 
Log Message:
Add test case for error message raised by bad % format character
(Oh, look, it adds another little utility function for testing)


Index: test_format.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_format.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** test_format.py	2000/11/30 05:22:41	1.3
--- test_format.py	2000/12/15 13:09:06	1.4
***************
*** 175,176 ****
--- 175,201 ----
  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")
+