summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_builtin.py
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-05-05 22:39:58 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2010-05-05 22:39:58 (GMT)
commit85b53533e499f5d1968896f846fd43b9ec8f1e0e (patch)
tree337972bda44a34edfae916b06938c5d93b342d4b /Lib/test/test_builtin.py
parentb2153e9d08b95c12c82b3d75cfaba837734c561b (diff)
downloadcpython-85b53533e499f5d1968896f846fd43b9ec8f1e0e.zip
cpython-85b53533e499f5d1968896f846fd43b9ec8f1e0e.tar.gz
cpython-85b53533e499f5d1968896f846fd43b9ec8f1e0e.tar.bz2
Issue #1533: Merge added trunk range tests to py3k. (The fix itself
doesn't need to be merged.) Patch by Alexander Belopolsky.
Diffstat (limited to 'Lib/test/test_builtin.py')
-rw-r--r--Lib/test/test_builtin.py44
1 files changed, 42 insertions, 2 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 5df7efb..94c6878 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -942,8 +942,8 @@ class BuiltinTest(unittest.TestCase):
self.assertRaises(RuntimeError, range, a, a + 1, badzero(1))
"""
- # Reject floats when it would require PyLongs to represent.
- # (smaller floats still accepted, but deprecated)
+ # Reject floats.
+ self.assertRaises(TypeError, range, 1., 1., 1.)
self.assertRaises(TypeError, range, 1e100, 1e101, 1e101)
self.assertRaises(TypeError, range, 0, "spam")
@@ -954,6 +954,46 @@ class BuiltinTest(unittest.TestCase):
self.assertRaises(OverflowError, len, range(0, sys.maxsize**10))
+ bignum = 2*sys.maxsize
+ smallnum = 42
+
+ # User-defined class with an __index__ method
+ class I:
+ def __init__(self, n):
+ self.n = int(n)
+ def __index__(self):
+ return self.n
+ self.assertEqual(list(range(I(bignum), I(bignum + 1))), [bignum])
+ self.assertEqual(list(range(I(smallnum), I(smallnum + 1))), [smallnum])
+
+ # User-defined class with a failing __index__ method
+ class IX:
+ def __index__(self):
+ raise RuntimeError
+ self.assertRaises(RuntimeError, range, IX())
+
+ # User-defined class with an invalid __index__ method
+ class IN:
+ def __index__(self):
+ return "not a number"
+
+ self.assertRaises(TypeError, range, IN())
+ # Exercise various combinations of bad arguments, to check
+ # refcounting logic
+ self.assertRaises(TypeError, range, 0.0)
+
+ self.assertRaises(TypeError, range, 0, 0.0)
+ self.assertRaises(TypeError, range, 0.0, 0)
+ self.assertRaises(TypeError, range, 0.0, 0.0)
+
+ self.assertRaises(TypeError, range, 0, 0, 1.0)
+ self.assertRaises(TypeError, range, 0, 0.0, 1)
+ self.assertRaises(TypeError, range, 0, 0.0, 1.0)
+ self.assertRaises(TypeError, range, 0.0, 0, 1)
+ self.assertRaises(TypeError, range, 0.0, 0, 1.0)
+ self.assertRaises(TypeError, range, 0.0, 0.0, 1)
+ self.assertRaises(TypeError, range, 0.0, 0.0, 1.0)
+
def test_input(self):
self.write_testfile()
fp = open(TESTFN, 'r')