summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_builtin.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2007-04-21 15:47:16 (GMT)
committerGeorg Brandl <georg@python.org>2007-04-21 15:47:16 (GMT)
commita18af4e7a2091d11478754eb66ae387a85535763 (patch)
treefea8015d656cfee937bb6f3d106e6ca0e9f19d78 /Lib/test/test_builtin.py
parent4d2adcca52ced412d4bdf131b872729c43520d58 (diff)
downloadcpython-a18af4e7a2091d11478754eb66ae387a85535763.zip
cpython-a18af4e7a2091d11478754eb66ae387a85535763.tar.gz
cpython-a18af4e7a2091d11478754eb66ae387a85535763.tar.bz2
PEP 3114: rename .next() to .__next__() and add next() builtin.
Diffstat (limited to 'Lib/test/test_builtin.py')
-rw-r--r--Lib/test/test_builtin.py33
1 files changed, 30 insertions, 3 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 05e80e4..500516c 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -907,9 +907,9 @@ class BuiltinTest(unittest.TestCase):
lists.append(unicode("12"))
for l in lists:
i = iter(l)
- self.assertEqual(i.next(), '1')
- self.assertEqual(i.next(), '2')
- self.assertRaises(StopIteration, i.next)
+ self.assertEqual(next(i), '1')
+ self.assertEqual(next(i), '2')
+ self.assertRaises(StopIteration, next, i)
def test_isinstance(self):
class C:
@@ -1305,6 +1305,33 @@ class BuiltinTest(unittest.TestCase):
self.assertEqual(min(data, key=f),
sorted(data, key=f)[0])
+ def test_next(self):
+ it = iter(range(2))
+ self.assertEqual(next(it), 0)
+ self.assertEqual(next(it), 1)
+ self.assertRaises(StopIteration, next, it)
+ self.assertRaises(StopIteration, next, it)
+ self.assertEquals(next(it, 42), 42)
+
+ class Iter(object):
+ def __iter__(self):
+ return self
+ def __next__(self):
+ raise StopIteration
+
+ it = iter(Iter())
+ self.assertEquals(next(it, 42), 42)
+ self.assertRaises(StopIteration, next, it)
+
+ def gen():
+ yield 1
+ return
+
+ it = gen()
+ self.assertEquals(next(it), 1)
+ self.assertRaises(StopIteration, next, it)
+ self.assertEquals(next(it, 42), 42)
+
def test_oct(self):
self.assertEqual(oct(100), '0144')
self.assertEqual(oct(100), '0144')