[pypy-svn] r80017 - in pypy/branch/fast-forward/pypy/module/_bisect: . test

agaynor at codespeak.net agaynor at codespeak.net
Mon Dec 13 06:45:24 CET 2010


Author: agaynor
Date: Mon Dec 13 06:45:22 2010
New Revision: 80017

Modified:
   pypy/branch/fast-forward/pypy/module/_bisect/interp_bisect.py
   pypy/branch/fast-forward/pypy/module/_bisect/test/test_bisect.py
Log:
Fixed an error in the bisect tests, verify that lo is non-negative.

Modified: pypy/branch/fast-forward/pypy/module/_bisect/interp_bisect.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_bisect/interp_bisect.py	(original)
+++ pypy/branch/fast-forward/pypy/module/_bisect/interp_bisect.py	Mon Dec 13 06:45:22 2010
@@ -1,3 +1,4 @@
+from pypy.interpreter.error import OperationError
 from pypy.interpreter.gateway import ObjSpace, W_Root
 
 
@@ -10,6 +11,10 @@
 
 Optional args lo (default 0) and hi (default len(a)) bound the
 slice of a to be searched."""
+    if lo < 0:
+        raise OperationError(space.w_ValueError,
+            space.wrap("lo must be non-negative")
+        )
     if hi == -1:
         hi = space.int_w(space.len(w_a))
     while lo < hi:

Modified: pypy/branch/fast-forward/pypy/module/_bisect/test/test_bisect.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_bisect/test/test_bisect.py	(original)
+++ pypy/branch/fast-forward/pypy/module/_bisect/test/test_bisect.py	Mon Dec 13 06:45:22 2010
@@ -42,6 +42,8 @@
         assert bisect_left(a, 6, 0, 3) == 1
         assert bisect_left(a, 6, 0, 4) == 1
 
+        raises(ValueError, bisect_left, [1, 2, 3], 5, -1, 3)
+
     def test_bisect_right(self):
         from _bisect import bisect_right
         a = [0, 5, 6, 6, 6, 7]



More information about the Pypy-commit mailing list