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

Tim Peters tim_one@users.sourceforge.net
Wed, 11 Apr 2001 17:35:53 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv16212/python/dist/src/Lib/test

Modified Files:
	test_format.py 
Log Message:
Fix for SF bug #415514: "%#x" % 0 caused assertion failure/abort.
http://sourceforge.net/tracker/index.php?func=detail&aid=415514&group_id=5470&atid=105470
For short ints, Python defers to the platform C library to figure out what
%#x should do.  The code asserted that the platform C returned a string
beginning with "0x".  However, that's not true when-- and only when --the
*value* being formatted is 0.  Changed the code to live with C's inconsistency
here.  In the meantime, the problem does not arise if you format a long 0 (0L)
instead.  However, that's because the code *we* wrote to do %#x conversions on
longs produces a leading "0x" regardless of value.  That's probably wrong too:
we should drop leading "0x", for consistency with C, when (& only when) formatting
0L.  So I changed the long formatting code to do that too.


Index: test_format.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_format.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** test_format.py	2001/02/09 11:46:37	1.9
--- test_format.py	2001/04/12 00:35:50	1.10
***************
*** 165,168 ****
--- 165,184 ----
  testboth("%d", 42L, "42")
  testboth("%d", -42L, "-42")
+ testboth("%#x", 1, "0x1")
+ testboth("%#x", 1L, "0x1")
+ testboth("%#X", 1, "0X1")
+ testboth("%#X", 1L, "0X1")
+ testboth("%#o", 1, "01")
+ testboth("%#o", 1L, "01")
+ testboth("%#o", 0, "0")
+ testboth("%#o", 0L, "0")
+ testboth("%o", 0, "0")
+ testboth("%o", 0L, "0")
+ testboth("%d", 0, "0")
+ testboth("%d", 0L, "0")
+ testboth("%#x", 0, "0")
+ testboth("%#x", 0L, "0")
+ testboth("%#X", 0, "0")
+ testboth("%#X", 0L, "0")
  
  testboth("%x", 0x42, "42")