summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-04-30 19:47:09 (GMT)
committerGeorg Brandl <georg@python.org>2008-04-30 19:47:09 (GMT)
commit28e0873f1f89d0d80ab64fabeb805de813ec08e4 (patch)
tree71a2fbd6c280bdbf02c17acdb45a8c815f8dd8f4 /Lib
parent46d6b689b224ecd8cc46beb3d069361cc68a9f38 (diff)
downloadcpython-28e0873f1f89d0d80ab64fabeb805de813ec08e4.zip
cpython-28e0873f1f89d0d80ab64fabeb805de813ec08e4.tar.gz
cpython-28e0873f1f89d0d80ab64fabeb805de813ec08e4.tar.bz2
#2719: backport next() from 3k.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_builtin.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 9fa973e..dbc86e2 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -1539,6 +1539,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(100L), '0144L')