[Python-checkins] python/dist/src/Lib/test test_itertools.py,1.8,1.9
rhettinger@users.sourceforge.net
rhettinger@users.sourceforge.net
Fri, 02 May 2003 15:38:09 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv26154
Modified Files:
test_itertools.py
Log Message:
Add StopIteration tests.
Simplify test_main().
Index: test_itertools.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_itertools.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** test_itertools.py 2 May 2003 19:44:20 -0000 1.8
--- test_itertools.py 2 May 2003 22:38:07 -0000 1.9
***************
*** 107,110 ****
--- 107,132 ----
self.assertEqual(list(dropwhile(underten, data)), [20, 2, 4, 6, 8])
+ def test_StopIteration(self):
+ class StopNow:
+ """Test support class . Emulates an empty iterable."""
+ def __iter__(self):
+ return self
+ def next(self):
+ raise StopIteration
+
+ for f in (chain, cycle, izip):
+ self.assertRaises(StopIteration, f([]).next)
+ self.assertRaises(StopIteration, f(StopNow()).next)
+
+ self.assertRaises(StopIteration, islice([], None).next)
+ self.assertRaises(StopIteration, islice(StopNow(), None).next)
+
+ self.assertRaises(StopIteration, repeat(None, 0).next)
+
+ for f in (ifilter, ifilterfalse, imap, takewhile, dropwhile, starmap):
+ self.assertRaises(StopIteration, f(lambda x:x, []).next)
+ self.assertRaises(StopIteration, f(lambda x:x, StopNow()).next)
+
+
libreftest = """ Doctest for examples in the library reference, libitertools.tex
***************
*** 227,241 ****
def test_main(verbose=None):
! suite = unittest.TestSuite()
! suite.addTest(unittest.makeSuite(TestBasicOps))
! test_support.run_suite(suite)
# verify reference counting
import sys
if verbose and hasattr(sys, "gettotalrefcount"):
! counts = []
! for i in xrange(5):
! test_support.run_suite(suite)
! counts.append(sys.gettotalrefcount()-i)
print counts
--- 249,261 ----
def test_main(verbose=None):
! test_support.run_unittest(TestBasicOps)
# verify reference counting
import sys
if verbose and hasattr(sys, "gettotalrefcount"):
! counts = [None] * 5
! for i in xrange(len(counts)):
! test_support.run_unittest(TestBasicOps)
! counts[i] = sys.gettotalrefcount()
print counts