summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-06-17 05:05:49 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-06-17 05:05:49 (GMT)
commitd05abdec7b2620449369bb44a617684463ba50ac (patch)
treecb20408dd9bf2d158586d3187e22438b4427288e /Lib/test
parentc8106e1f1dbd00e64aff6ecc5ecb53010168dd27 (diff)
downloadcpython-d05abdec7b2620449369bb44a617684463ba50ac.zip
cpython-d05abdec7b2620449369bb44a617684463ba50ac.tar.gz
cpython-d05abdec7b2620449369bb44a617684463ba50ac.tar.bz2
SF #754014: list.index() should accept optional start, end arguments
Also, modified UserList.index() to match and expanded the related tests.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_types.py16
-rw-r--r--Lib/test/test_userlist.py9
2 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py
index 1cb1484..9599456 100644
--- a/Lib/test/test_types.py
+++ b/Lib/test/test_types.py
@@ -366,7 +366,23 @@ b.insert(200, "right")
if b != ["left",-2,-1,0,0,"foo",1,2,"right"]: raise TestFailed, 'list insert2'
if a.count(0) != 2: raise TestFailed, ' list count'
if a.index(0) != 2: raise TestFailed, 'list index'
+if a.index(0,2) != 2: raise TestFailed, 'list index, start argument'
+if a.index(-2,-10) != 0: raise TestFailed, 'list index, negative start argument'
+if a.index(0,3) != 3: raise TestFailed, 'list index, start argument'
+if a.index(0,3,4) != 3: raise TestFailed, 'list index, stop argument'
+try:
+ a.index(2,0,-10)
+except ValueError:
+ pass
+else:
+ raise TestFailed, 'list index, negative stop argument'
a.remove(0)
+try:
+ a.index(2,0,4)
+except ValueError:
+ pass
+else:
+ raise TestFailed, 'list index, stop argument.'
if a != [-2,-1,0,1,2]: raise TestFailed, 'list remove'
a.reverse()
if a != [2,1,0,-1,-2]: raise TestFailed, 'list reverse'
diff --git a/Lib/test/test_userlist.py b/Lib/test/test_userlist.py
index 467a47c..2d11a24 100644
--- a/Lib/test/test_userlist.py
+++ b/Lib/test/test_userlist.py
@@ -206,6 +206,15 @@ class UserListTest(unittest.TestCase):
self.assertEqual(u.index(1), 1)
self.assertRaises(ValueError, u.index, 2)
+ u = UserList([-2,-1,0,0,1,2])
+ self.assertEqual(u.count(0), 2)
+ self.assertEqual(u.index(0), 2)
+ self.assertEqual(u.index(0,2), 2)
+ self.assertEqual(u.index(-2,-10), 0)
+ self.assertEqual(u.index(0,3), 3)
+ self.assertEqual(u.index(0,3,4), 3)
+ self.assertRaises(ValueError, u.index, 2,0,-10)
+
def test_reverse(self):
u = UserList((0, 1))
u2 = u[:]