[pypy-svn] r13775 - in pypy/dist/pypy/objspace/std: . test
arigo at codespeak.net
arigo at codespeak.net
Fri Jun 24 13:15:09 CEST 2005
Author: arigo
Date: Fri Jun 24 13:15:07 2005
New Revision: 13775
Modified:
pypy/dist/pypy/objspace/std/floattype.py
pypy/dist/pypy/objspace/std/test/test_floatobject.py
Log:
Use string_to_float() from floattype.py. Some tests.
Modified: pypy/dist/pypy/objspace/std/floattype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/floattype.py (original)
+++ pypy/dist/pypy/objspace/std/floattype.py Fri Jun 24 13:15:07 2005
@@ -1,21 +1,22 @@
from pypy.objspace.std.stdtypedef import *
from pypy.interpreter.error import OperationError
-from pypy.objspace.std.strutil import ParseStringError
+from pypy.objspace.std.strutil import string_to_float, ParseStringError
def descr__new__(space, w_floattype, w_x=0.0):
from pypy.objspace.std.floatobject import W_FloatObject
w_value = w_x # 'x' is the keyword argument name in CPython
if space.is_true(space.isinstance(w_value, space.w_str)):
+ strvalue = space.str_w(w_value)
try:
- value = float(space.str_w(w_value))
- except ValueError, e:
+ value = string_to_float(strvalue)
+ except ParseStringError, e:
raise OperationError(space.w_ValueError,
- space.wrap(str(e)))
+ space.wrap(e.msg))
elif space.is_true(space.isinstance(w_value, space.w_unicode)):
+ from unicodeobject import unicode_to_decimal_w
+ strvalue = unicode_to_decimal_w(space, w_value)
try:
- # XXX can produce unwrapped long
- from unicodeobject import unicode_to_decimal_w
- value = float(unicode_to_decimal_w(space, w_value))
+ value = string_to_float(strvalue)
except ParseStringError, e:
raise OperationError(space.w_ValueError,
space.wrap(e.msg))
Modified: pypy/dist/pypy/objspace/std/test/test_floatobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_floatobject.py (original)
+++ pypy/dist/pypy/objspace/std/test/test_floatobject.py Fri Jun 24 13:15:07 2005
@@ -56,9 +56,11 @@
def test_float_string(self):
assert 42 == float("42")
+ assert 42.25 == float("42.25")
def test_float_unicode(self):
- assert 42.3 == float(unicode("42.3"))
+ # u00A0 and u2000 are some kind of spaces
+ assert 42.75 == float(unichr(0x00A0)+unicode("42.75")+unichr(0x2000))
def test_float_long(self):
assert 42.0 == float(42L)
More information about the Pypy-commit
mailing list