[pypy-svn] r71992 - in pypy/trunk/pypy/objspace/std: . test
arigo at codespeak.net
arigo at codespeak.net
Tue Mar 9 19:36:14 CET 2010
Author: arigo
Date: Tue Mar 9 19:36:08 2010
New Revision: 71992
Modified:
pypy/trunk/pypy/objspace/std/formatting.py
pypy/trunk/pypy/objspace/std/test/test_stringformat.py
Log:
Tests and corresponding fix. Argh, this logic is a bit insane.
Modified: pypy/trunk/pypy/objspace/std/formatting.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/formatting.py (original)
+++ pypy/trunk/pypy/objspace/std/formatting.py Tue Mar 9 19:36:08 2010
@@ -38,7 +38,7 @@
space.wrap('not all arguments converted '
'during string formatting'))
- def std_wp_int(self, r, prefix=''):
+ def std_wp_int(self, r, prefix='', keep_zero=False):
# use self.prec to add some '0' on the left of the number
if self.prec >= 0:
sign = r[0] == '-'
@@ -48,7 +48,7 @@
r = '-' + '0'*padding + r[1:]
else:
r = '0'*padding + r
- elif self.prec == 0 and r == '0':
+ elif self.prec == 0 and r == '0' and not keep_zero:
r = ''
self.std_wp_number(r, prefix)
@@ -78,11 +78,15 @@
def fmt_o(self, w_value):
"oct formatting"
r = oct_num_helper(self.space, w_value)
- if self.f_alt and (r != '0' or self.prec == 0):
- prefix = '0'
- else:
- prefix = ''
- self.std_wp_int(r, prefix)
+ keep_zero = False
+ if self.f_alt:
+ if r == '0':
+ keep_zero = True
+ elif r.startswith('-'):
+ r = '-0' + r[1:]
+ else:
+ r = '0' + r
+ self.std_wp_int(r, keep_zero=keep_zero)
fmt_i = fmt_d
fmt_u = fmt_d
Modified: pypy/trunk/pypy/objspace/std/test/test_stringformat.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/test/test_stringformat.py (original)
+++ pypy/trunk/pypy/objspace/std/test/test_stringformat.py Tue Mar 9 19:36:08 2010
@@ -113,7 +113,16 @@
n = 23
f = 5
assert '-0x017' == '%#06x' % -n
+ assert '' == '%.0o' % z
assert '0' == '%#.0o' % z
+ assert '5' == '%.0o' % f
+ assert '05' == '%#.0o' % f
+ assert '000' == '%.3o' % z
+ assert '000' == '%#.3o' % z
+ assert '005' == '%.3o' % f
+ assert '005' == '%#.3o' % f
+ assert '27' == '%.2o' % n
+ assert '027' == '%#.2o' % n
def test_format_list(self):
l = [1,2]
More information about the Pypy-commit
mailing list