diff options
author | Guido van Rossum <guido@python.org> | 2007-05-07 22:24:25 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-05-07 22:24:25 (GMT) |
commit | 805365ee39298f93e433e19ae0dd87c6f782145b (patch) | |
tree | ae8f8a3c315b49cfb2e7926d4b7e56f64c68b21c /Lib/test/test_iter.py | |
parent | 598d98a7e8981e650e803e41e884ffc905b2311e (diff) | |
download | cpython-805365ee39298f93e433e19ae0dd87c6f782145b.zip cpython-805365ee39298f93e433e19ae0dd87c6f782145b.tar.gz cpython-805365ee39298f93e433e19ae0dd87c6f782145b.tar.bz2 |
Merged revisions 55007-55179 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk
........
r55077 | guido.van.rossum | 2007-05-02 11:54:37 -0700 (Wed, 02 May 2007) | 2 lines
Use the new print syntax, at least.
........
r55142 | fred.drake | 2007-05-04 21:27:30 -0700 (Fri, 04 May 2007) | 1 line
remove old cruftiness
........
r55143 | fred.drake | 2007-05-04 21:52:16 -0700 (Fri, 04 May 2007) | 1 line
make this work with the new Python
........
r55162 | neal.norwitz | 2007-05-06 22:29:18 -0700 (Sun, 06 May 2007) | 1 line
Get asdl code gen working with Python 2.3. Should continue to work with 3.0
........
r55164 | neal.norwitz | 2007-05-07 00:00:38 -0700 (Mon, 07 May 2007) | 1 line
Verify checkins to p3yk (sic) branch go to 3000 list.
........
r55166 | neal.norwitz | 2007-05-07 00:12:35 -0700 (Mon, 07 May 2007) | 1 line
Fix this test so it runs again by importing warnings_test properly.
........
r55167 | neal.norwitz | 2007-05-07 01:03:22 -0700 (Mon, 07 May 2007) | 8 lines
So long xrange. range() now supports values that are outside
-sys.maxint to sys.maxint. floats raise a TypeError.
This has been sitting for a long time. It probably has some problems and
needs cleanup. Objects/rangeobject.c now uses 4-space indents since
it is almost completely new.
........
r55171 | guido.van.rossum | 2007-05-07 10:21:26 -0700 (Mon, 07 May 2007) | 4 lines
Fix two tests that were previously depending on significant spaces
at the end of a line (and before that on Python 2.x print behavior
that has no exact equivalent in 3.0).
........
Diffstat (limited to 'Lib/test/test_iter.py')
-rw-r--r-- | Lib/test/test_iter.py | 65 |
1 files changed, 32 insertions, 33 deletions
diff --git a/Lib/test/test_iter.py b/Lib/test/test_iter.py index 5a75c50..22595fc 100644 --- a/Lib/test/test_iter.py +++ b/Lib/test/test_iter.py @@ -68,18 +68,18 @@ class TestCase(unittest.TestCase): # Test basic use of iter() function def test_iter_basic(self): - self.check_iterator(iter(range(10)), range(10)) + self.check_iterator(iter(range(10)), list(range(10))) # Test that iter(iter(x)) is the same as iter(x) def test_iter_idempotency(self): - seq = range(10) + seq = list(range(10)) it = iter(seq) it2 = iter(it) self.assert_(it is it2) # Test that for loops over iterators work def test_iter_for_loop(self): - self.check_for_loop(iter(range(10)), range(10)) + self.check_for_loop(iter(range(10)), list(range(10))) # Test several independent iterators over the same list def test_iter_independence(self): @@ -106,19 +106,19 @@ class TestCase(unittest.TestCase): # Test a class with __iter__ in a for loop def test_iter_class_for(self): - self.check_for_loop(IteratingSequenceClass(10), range(10)) + self.check_for_loop(IteratingSequenceClass(10), list(range(10))) # Test a class with __iter__ with explicit iter() def test_iter_class_iter(self): - self.check_iterator(iter(IteratingSequenceClass(10)), range(10)) + self.check_iterator(iter(IteratingSequenceClass(10)), list(range(10))) # Test for loop on a sequence class without __iter__ def test_seq_class_for(self): - self.check_for_loop(SequenceClass(10), range(10)) + self.check_for_loop(SequenceClass(10), list(range(10))) # Test iter() on a sequence class without __iter__ def test_seq_class_iter(self): - self.check_iterator(iter(SequenceClass(10)), range(10)) + self.check_iterator(iter(SequenceClass(10)), list(range(10))) # Test two-argument iter() with callable instance def test_iter_callable(self): @@ -131,7 +131,7 @@ class TestCase(unittest.TestCase): if i > 100: raise IndexError # Emergency stop return i - self.check_iterator(iter(C(), 10), range(10)) + self.check_iterator(iter(C(), 10), list(range(10))) # Test two-argument iter() with function def test_iter_function(self): @@ -139,7 +139,7 @@ class TestCase(unittest.TestCase): i = state[0] state[0] = i+1 return i - self.check_iterator(iter(spam, 10), range(10)) + self.check_iterator(iter(spam, 10), list(range(10))) # Test two-argument iter() with function that raises StopIteration def test_iter_function_stop(self): @@ -149,7 +149,7 @@ class TestCase(unittest.TestCase): raise StopIteration state[0] = i+1 return i - self.check_iterator(iter(spam, 20), range(10)) + self.check_iterator(iter(spam, 20), list(range(10))) # Test exception propagation through function iterator def test_exception_function(self): @@ -164,7 +164,7 @@ class TestCase(unittest.TestCase): for x in iter(spam, 20): res.append(x) except RuntimeError: - self.assertEqual(res, range(10)) + self.assertEqual(res, list(range(10))) else: self.fail("should have raised RuntimeError") @@ -180,7 +180,7 @@ class TestCase(unittest.TestCase): for x in MySequenceClass(20): res.append(x) except RuntimeError: - self.assertEqual(res, range(10)) + self.assertEqual(res, list(range(10))) else: self.fail("should have raised RuntimeError") @@ -191,11 +191,11 @@ class TestCase(unittest.TestCase): if i == 10: raise StopIteration return SequenceClass.__getitem__(self, i) - self.check_for_loop(MySequenceClass(20), range(10)) + self.check_for_loop(MySequenceClass(20), list(range(10))) # Test a big range def test_iter_big_range(self): - self.check_for_loop(iter(range(10000)), range(10000)) + self.check_for_loop(iter(range(10000)), list(range(10000))) # Test an empty list def test_iter_empty(self): @@ -203,11 +203,11 @@ class TestCase(unittest.TestCase): # Test a tuple def test_iter_tuple(self): - self.check_for_loop(iter((0,1,2,3,4,5,6,7,8,9)), range(10)) + self.check_for_loop(iter((0,1,2,3,4,5,6,7,8,9)), list(range(10))) - # Test an xrange - def test_iter_xrange(self): - self.check_for_loop(iter(xrange(10)), range(10)) + # Test a range + def test_iter_range(self): + self.check_for_loop(iter(range(10)), list(range(10))) # Test a string def test_iter_string(self): @@ -248,10 +248,9 @@ class TestCase(unittest.TestCase): # Test list()'s use of iterators. def test_builtin_list(self): - self.assertEqual(list(SequenceClass(5)), range(5)) + self.assertEqual(list(SequenceClass(5)), list(range(5))) self.assertEqual(list(SequenceClass(0)), []) self.assertEqual(list(()), []) - self.assertEqual(list(range(10, -1, -1)), range(10, -1, -1)) d = {"one": 1, "two": 2, "three": 3} self.assertEqual(list(d), list(d.keys())) @@ -313,7 +312,7 @@ class TestCase(unittest.TestCase): # Test filter()'s use of iterators. def test_builtin_filter(self): - self.assertEqual(filter(None, SequenceClass(5)), range(1, 5)) + self.assertEqual(filter(None, SequenceClass(5)), list(range(1, 5))) self.assertEqual(filter(None, SequenceClass(0)), []) self.assertEqual(filter(None, ()), ()) self.assertEqual(filter(None, "abc"), "abc") @@ -389,8 +388,8 @@ class TestCase(unittest.TestCase): # Test map()'s use of iterators. def test_builtin_map(self): - self.assertEqual(map(None, SequenceClass(5)), range(5)) - self.assertEqual(map(lambda x: x+1, SequenceClass(5)), range(1, 6)) + self.assertEqual(map(None, SequenceClass(5)), list(range(5))) + self.assertEqual(map(lambda x: x+1, SequenceClass(5)), list(range(1, 6))) d = {"one": 1, "two": 2, "three": 3} self.assertEqual(map(None, d), list(d.keys())) @@ -413,7 +412,7 @@ class TestCase(unittest.TestCase): f.close() f = open(TESTFN, "r") try: - self.assertEqual(map(len, f), range(1, 21, 2)) + self.assertEqual(map(len, f), list(range(1, 21, 2))) finally: f.close() try: @@ -470,7 +469,7 @@ class TestCase(unittest.TestCase): except OSError: pass - self.assertEqual(list(zip(xrange(5))), [(i,) for i in range(5)]) + self.assertEqual(list(zip(range(5))), [(i,) for i in range(5)]) # Classes that lie about their lengths. class NoGuessLen5: @@ -799,16 +798,16 @@ class TestCase(unittest.TestCase): def test_sinkstate_list(self): # This used to fail - a = range(5) + a = list(range(5)) b = iter(a) - self.assertEqual(list(b), range(5)) + self.assertEqual(list(b), list(range(5))) a.extend(range(5, 10)) self.assertEqual(list(b), []) def test_sinkstate_tuple(self): a = (0, 1, 2, 3, 4) b = iter(a) - self.assertEqual(list(b), range(5)) + self.assertEqual(list(b), list(range(5))) self.assertEqual(list(b), []) def test_sinkstate_string(self): @@ -821,7 +820,7 @@ class TestCase(unittest.TestCase): # This used to fail a = SequenceClass(5) b = iter(a) - self.assertEqual(list(b), range(5)) + self.assertEqual(list(b), list(range(5))) a.n = 10 self.assertEqual(list(b), []) @@ -834,7 +833,7 @@ class TestCase(unittest.TestCase): raise AssertionError, "shouldn't have gotten this far" return i b = iter(spam, 5) - self.assertEqual(list(b), range(5)) + self.assertEqual(list(b), list(range(5))) self.assertEqual(list(b), []) def test_sinkstate_dict(self): @@ -851,13 +850,13 @@ class TestCase(unittest.TestCase): for i in range(5): yield i b = gen() - self.assertEqual(list(b), range(5)) + self.assertEqual(list(b), list(range(5))) self.assertEqual(list(b), []) def test_sinkstate_range(self): - a = xrange(5) + a = range(5) b = iter(a) - self.assertEqual(list(b), range(5)) + self.assertEqual(list(b), list(range(5))) self.assertEqual(list(b), []) def test_sinkstate_enumerate(self): |