[pypy-svn] r66102 - in pypy/trunk/pypy/module/__builtin__: . test

antocuni at codespeak.net antocuni at codespeak.net
Fri Jul 3 16:06:46 CEST 2009


Author: antocuni
Date: Fri Jul  3 16:06:44 2009
New Revision: 66102

Modified:
   pypy/trunk/pypy/module/__builtin__/functional.py
   pypy/trunk/pypy/module/__builtin__/test/test_functional.py
   pypy/trunk/pypy/module/__builtin__/test/test_range.py
Log:
(brian brazil, based on a patch by jasonpjason)

- Fix using class with __int__ and xrange. Add a unittest
- Re-add unittest for range with floats, there doesn't appear to be a
reason to ignore it
- Add float unittest for xrange, this tests _toint



Modified: pypy/trunk/pypy/module/__builtin__/functional.py
==============================================================================
--- pypy/trunk/pypy/module/__builtin__/functional.py	(original)
+++ pypy/trunk/pypy/module/__builtin__/functional.py	Fri Jul  3 16:06:44 2009
@@ -205,7 +205,7 @@
 def _toint(space, w_obj):
     # trying to support float arguments, just because CPython still does
     try:
-        return space.int_w(w_obj)
+        return space.int_w(space.int(w_obj))
     except OperationError, e:
         if space.is_true(space.isinstance(w_obj, space.w_float)):
             return space.int_w(space.int(w_obj))

Modified: pypy/trunk/pypy/module/__builtin__/test/test_functional.py
==============================================================================
--- pypy/trunk/pypy/module/__builtin__/test/test_functional.py	(original)
+++ pypy/trunk/pypy/module/__builtin__/test/test_functional.py	Fri Jul  3 16:06:44 2009
@@ -117,6 +117,18 @@
       # test again, to make sure that xrange() is not its own iterator
       assert iter(x).next() == 2
 
+   def test_xrange_object_with___int__(self):
+       class A(object):
+          def __int__(self):
+             return 5
+
+       assert list(xrange(A())) == [0, 1, 2, 3, 4]
+       assert list(xrange(0, A())) == [0, 1, 2, 3, 4]
+       assert list(xrange(0, 10, A())) == [0, 5]
+ 
+   def test_xrange_float(self):
+      assert list(xrange(0.1, 2.0, 1.1)) == [0, 1]
+
 class AppTestReversed:
    def test_reversed(self):
       r = reversed("hello")

Modified: pypy/trunk/pypy/module/__builtin__/test/test_range.py
==============================================================================
--- pypy/trunk/pypy/module/__builtin__/test/test_range.py	(original)
+++ pypy/trunk/pypy/module/__builtin__/test/test_range.py	Fri Jul  3 16:06:44 2009
@@ -59,8 +59,8 @@
    def test_range_zerostep(self):
        raises(ValueError, range, 1, 5, 0)
 
-   def DONT_test_range_float(self):
-       "How CPython does it - UGLY, ignored for now."
+   def test_range_float(self):
+       "How CPython does it - UGLY."
        assert range(0.1, 2.0, 1.1) == [0, 1]
 
    def test_range_wrong_type(self):



More information about the Pypy-commit mailing list