[pypy-svn] r79081 - in pypy/branch/fast-forward/pypy/objspace/std: . test
afa at codespeak.net
afa at codespeak.net
Mon Nov 15 00:24:31 CET 2010
Author: afa
Date: Mon Nov 15 00:24:30 2010
New Revision: 79081
Modified:
pypy/branch/fast-forward/pypy/objspace/std/newformat.py
pypy/branch/fast-forward/pypy/objspace/std/test/test_newformat.py
Log:
format(s, '.3') should truncate the string. Test and fix.
Modified: pypy/branch/fast-forward/pypy/objspace/std/newformat.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/newformat.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/newformat.py Mon Nov 15 00:24:30 2010
@@ -443,8 +443,11 @@
msg = "'=' alignment not allowed in string format specifier"
raise OperationError(space.w_ValueError, space.wrap(msg))
length = len(string)
- if self._precision != -1 and length >= self._precision:
- length = self._precision
+ precision = self._precision
+ if precision != -1 and length >= precision:
+ assert precision >= 0
+ length = precision
+ string = string[:precision]
if self._fill_char == "\0":
self._fill_char = self._lit(" ")[0]
self._calc_padding(string, length)
Modified: pypy/branch/fast-forward/pypy/objspace/std/test/test_newformat.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/test/test_newformat.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/test/test_newformat.py Mon Nov 15 00:24:30 2010
@@ -95,6 +95,9 @@
assert format(self.s("h"), "c<3") == self.s("hcc")
raises(ValueError, format, self.s("blah"), "=12")
+ def test_precision(self):
+ assert format(self.s("abcdef"), ".3") == self.s("abc")
+
def test_non_ascii_presentation(self):
raises(ValueError, format, self.s(""), "\x234")
More information about the Pypy-commit
mailing list