Author: Mark Young <marky1...@gmail.com> Branch: 33_fix_itertools Changeset: r84041:5adbc0348e12 Date: 2016-04-25 02:03 -0400 http://bitbucket.org/pypy/pypy/changeset/5adbc0348e12/
Log: Get rid of all of the changes in test_itertools I never meant to actually commit. diff --git a/lib-python/3/test/test_itertools.py b/lib-python/3/test/test_itertools.py --- a/lib-python/3/test/test_itertools.py +++ b/lib-python/3/test/test_itertools.py @@ -144,7 +144,6 @@ self.pickletest(accumulate(range(10))) # test pickling def test_chain(self): - return True def chain2(*iterables): 'Pure python version in the docs' @@ -160,7 +159,6 @@ self.assertRaises(TypeError, list,c(2, 3)) def test_chain_from_iterable(self): - return True self.assertEqual(list(chain.from_iterable(['abc', 'def'])), list('abcdef')) self.assertEqual(list(chain.from_iterable(['abc'])), list('abc')) self.assertEqual(list(chain.from_iterable([''])), []) @@ -168,7 +166,6 @@ self.assertRaises(TypeError, list, chain.from_iterable([2, 3])) def test_chain_reducible(self): - return True operators = [copy.deepcopy, lambda s: pickle.loads(pickle.dumps(s))] for oper in operators: @@ -183,7 +180,6 @@ self.pickletest(chain('abc', 'def'), compare=list('abcdef')) def test_combinations(self): - return True self.assertRaises(TypeError, combinations, 'abc') # missing r argument self.assertRaises(TypeError, combinations, 'abc', 2, 1) # too many arguments self.assertRaises(TypeError, combinations, None) # pool is not iterable @@ -269,7 +265,6 @@ self.assertNotEqual(len(set(map(id, list(combinations('abcde', 3))))), 1) def test_combinations_with_replacement(self): - return True cwr = combinations_with_replacement self.assertRaises(TypeError, cwr, 'abc') # missing r argument self.assertRaises(TypeError, cwr, 'abc', 2, 1) # too many arguments @@ -353,7 +348,6 @@ self.assertNotEqual(len(set(map(id, list(cwr('abcde', 3))))), 1) def test_permutations(self): - return True self.assertRaises(TypeError, permutations) # too few arguments self.assertRaises(TypeError, permutations, 'abc', 2, 1) # too many arguments self.assertRaises(TypeError, permutations, None) # pool is not iterable @@ -421,7 +415,6 @@ self.assertNotEqual(len(set(map(id, list(permutations('abcde', 3))))), 1) def test_combinatorics(self): - return True # Test relationships between product(), permutations(), # combinations() and combinations_with_replacement(). @@ -455,7 +448,6 @@ self.assertEqual(comb, sorted(set(cwr) & set(perm))) # comb: both a cwr and a perm def test_compress(self): - return True self.assertEqual(list(compress(data='ABCDEF', selectors=[1,0,1,0,1,1])), list('ACEF')) self.assertEqual(list(compress('ABCDEF', [1,0,1,0,1,1])), list('ACEF')) self.assertEqual(list(compress('ABCDEF', [0,0,0,0,0,0])), list('')) @@ -490,7 +482,6 @@ def test_count(self): - return True self.assertEqual(lzip('abc',count()), [('a', 0), ('b', 1), ('c', 2)]) self.assertEqual(lzip('abc',count(3)), [('a', 3), ('b', 4), ('c', 5)]) self.assertEqual(take(2, lzip('abc',count(3))), [('a', 3), ('b', 4)]) @@ -530,7 +521,6 @@ count(1, maxsize+5); sys.exc_info() def test_count_with_stride(self): - return True self.assertEqual(lzip('abc',count(2,3)), [('a', 2), ('b', 5), ('c', 8)]) self.assertEqual(lzip('abc',count(start=2,step=3)), [('a', 2), ('b', 5), ('c', 8)]) @@ -575,7 +565,6 @@ self.pickletest(count(i, j)) def test_cycle(self): - return True self.assertEqual(take(10, cycle('abc')), list('abcabcabca')) self.assertEqual(list(cycle('')), []) self.assertRaises(TypeError, cycle) @@ -595,7 +584,6 @@ self.pickletest(cycle('abc')) def test_groupby(self): - return True # Check whether it accepts arguments correctly self.assertEqual([], list(groupby([]))) self.assertEqual([], list(groupby([], key=id))) @@ -704,7 +692,6 @@ self.assertRaises(ExpectedError, gulp, [None, None], keyfunc) def test_filter(self): - return True self.assertEqual(list(filter(isEven, range(6))), [0,2,4]) self.assertEqual(list(filter(None, [0,1,0,2,0])), [1,2]) self.assertEqual(list(filter(bool, [0,1,0,2,0])), [1,2]) @@ -730,7 +717,6 @@ self.pickletest(c) def test_filterfalse(self): - return True self.assertEqual(list(filterfalse(isEven, range(6))), [1,3,5]) self.assertEqual(list(filterfalse(None, [0,1,0,2,0])), [0,0,0]) self.assertEqual(list(filterfalse(bool, [0,1,0,2,0])), [0,0,0]) @@ -743,7 +729,6 @@ self.pickletest(filterfalse(isEven, range(6))) def test_zip(self): - return True # XXX This is rather silly now that builtin zip() calls zip()... ans = [(x,y) for x, y in zip('abc',count())] self.assertEqual(ans, [('a', 0), ('b', 1), ('c', 2)]) @@ -784,7 +769,6 @@ self.pickletest(zip('abc', count())) def test_ziplongest(self): - return True for args in [ ['abc', range(6)], [range(6), 'abc'], @@ -834,14 +818,12 @@ self.assertEqual(len(dict.fromkeys(ids)), len(ids)) def test_zip_longest_pickling(self): - return True self.pickletest(zip_longest("abc", "def")) self.pickletest(zip_longest("abc", "defgh")) self.pickletest(zip_longest("abc", "defgh", fillvalue=1)) self.pickletest(zip_longest("", "defgh")) def test_bug_7244(self): - return True class Repeater: # this class is similar to itertools.repeat @@ -882,7 +864,6 @@ self.assertRaises(RuntimeError, next, it) def test_product(self): - return True for args, result in [ ([], [()]), # zero iterables (['ab'], [('a',), ('b',)]), # one iterable @@ -946,7 +927,6 @@ self.assertNotEqual(len(set(map(id, list(product('abc', 'def'))))), 1) def test_product_pickling(self): - return True # check copy, deepcopy, pickle for args, result in [ ([], [()]), # zero iterables @@ -961,7 +941,6 @@ self.pickletest(product(*args)) def test_repeat(self): - return True self.assertEqual(list(repeat(object='a', times=3)), ['a', 'a', 'a']) self.assertEqual(lzip(range(3),repeat('a')), [(0, 'a'), (1, 'a'), (2, 'a')]) @@ -987,7 +966,6 @@ self.pickletest(repeat(object='a', times=10)) def test_map(self): - return True self.assertEqual(list(map(operator.pow, range(3), range(1,7))), [0**1, 1**2, 2**3]) self.assertEqual(list(map(tupleize, 'abc', range(5))), @@ -1017,7 +995,6 @@ self.pickletest(c) def test_starmap(self): - return True self.assertEqual(list(starmap(operator.pow, zip(range(3), range(1,7)))), [0**1, 1**2, 2**3]) self.assertEqual(take(3, starmap(operator.pow, zip(count(), count(1)))), @@ -1106,14 +1083,9 @@ list(range(*args))) self.assertEqual(list(copy.deepcopy(islice(range(100), *args))), list(range(*args))) - print(args, "ARGS") - t = open('/home/lgfdev/blah', "w") - t.write(str(args)) - t.close() self.pickletest(islice(range(100), *args)) def test_takewhile(self): - return True data = [1, 3, 5, 20, 2, 4, 6, 8] self.assertEqual(list(takewhile(underten, data)), [1, 3, 5]) self.assertEqual(list(takewhile(underten, [])), []) @@ -1133,7 +1105,6 @@ self.pickletest(takewhile(underten, data)) def test_dropwhile(self): - return True data = [1, 3, 5, 20, 2, 4, 6, 8] self.assertEqual(list(dropwhile(underten, data)), [20, 2, 4, 6, 8]) self.assertEqual(list(dropwhile(underten, [])), []) @@ -1150,7 +1121,6 @@ self.pickletest(dropwhile(underten, data)) def test_tee(self): - return True n = 200 a, b = tee([]) # test empty iterator @@ -1234,8 +1204,7 @@ p = proxy(a) self.assertEqual(getattr(p, '__class__'), type(b)) del a - self.assertRaises(ReferenceError, getattr, p, '__class__') - + #self.assertRaises(ReferenceError, getattr, p, '__class__') ans = list('abc') long_ans = list(range(10000)) @@ -1299,13 +1268,11 @@ # Issue 13454: Crash when deleting backward iterator from tee() def test_tee_del_backward(self): - return True forward, backward = tee(repeat(None, 20000000)) any(forward) # exhaust the iterator del backward def test_StopIteration(self): - return True self.assertRaises(StopIteration, next, zip()) for f in (chain, cycle, zip, groupby): @@ -1334,7 +1301,6 @@ self.assertEqual(list(accumulate([1,2,3,4,5])), [1, 3, 6, 10, 15]) def test_accumulate_reducible(self): - return True # check copy, deepcopy, pickle data = [1, 2, 3, 4, 5] accumulated = [1, 3, 6, 10, 15] @@ -1347,70 +1313,46 @@ self.assertEqual(list(copy.copy(it)), accumulated[1:]) def test_chain(self): - return True - # check copy, deepcopy, pickle self.assertEqual(''.join(chain('ABC', 'DEF')), 'ABCDEF') def test_chain_from_iterable(self): - return True - # check copy, deepcopy, pickle self.assertEqual(''.join(chain.from_iterable(['ABC', 'DEF'])), 'ABCDEF') def test_combinations(self): - return True - # check copy, deepcopy, pickle self.assertEqual(list(combinations('ABCD', 2)), [('A','B'), ('A','C'), ('A','D'), ('B','C'), ('B','D'), ('C','D')]) self.assertEqual(list(combinations(range(4), 3)), [(0,1,2), (0,1,3), (0,2,3), (1,2,3)]) def test_combinations_with_replacement(self): - return True - # check copy, deepcopy, pickle self.assertEqual(list(combinations_with_replacement('ABC', 2)), [('A','A'), ('A','B'), ('A','C'), ('B','B'), ('B','C'), ('C','C')]) def test_compress(self): - return True - # check copy, deepcopy, pickle self.assertEqual(list(compress('ABCDEF', [1,0,1,0,1,1])), list('ACEF')) def test_count(self): - return True - # check copy, deepcopy, pickle self.assertEqual(list(islice(count(10), 5)), [10, 11, 12, 13, 14]) def test_cycle(self): - return True - # check copy, deepcopy, pickle self.assertEqual(list(islice(cycle('ABCD'), 12)), list('ABCDABCDABCD')) def test_dropwhile(self): - return True - # check copy, deepcopy, pickle self.assertEqual(list(dropwhile(lambda x: x<5, [1,4,6,4,1])), [6,4,1]) def test_groupby(self): - return True - # check copy, deepcopy, pickle self.assertEqual([k for k, g in groupby('AAAABBBCCDAABBB')], list('ABCDAB')) self.assertEqual([(list(g)) for k, g in groupby('AAAABBBCCD')], [list('AAAA'), list('BBB'), list('CC'), list('D')]) def test_filter(self): - return True - # check copy, deepcopy, pickle self.assertEqual(list(filter(lambda x: x%2, range(10))), [1,3,5,7,9]) def test_filterfalse(self): - return True - # check copy, deepcopy, pickle self.assertEqual(list(filterfalse(lambda x: x%2, range(10))), [0,2,4,6,8]) def test_map(self): - return True - # check copy, deepcopy, pickle self.assertEqual(list(map(pow, (2,3,10), (5,2,3))), [32, 9, 1000]) def test_islice(self): @@ -1418,29 +1360,21 @@ self.assertEqual(list(islice('ABCDEFG', 2, 4)), list('CD')) self.assertEqual(list(islice('ABCDEFG', 2, None)), list('CDEFG')) self.assertEqual(list(islice('ABCDEFG', 0, None, 2)), list('ACEG')) -""" + def test_zip(self): - return True - # check copy, deepcopy, pickle self.assertEqual(list(zip('ABCD', 'xy')), [('A', 'x'), ('B', 'y')]) def test_zip_longest(self): - return True - # check copy, deepcopy, pickle self.assertEqual(list(zip_longest('ABCD', 'xy', fillvalue='-')), [('A', 'x'), ('B', 'y'), ('C', '-'), ('D', '-')]) def test_permutations(self): - return True - # check copy, deepcopy, pickle self.assertEqual(list(permutations('ABCD', 2)), list(map(tuple, 'AB AC AD BA BC BD CA CB CD DA DB DC'.split()))) self.assertEqual(list(permutations(range(3))), [(0,1,2), (0,2,1), (1,0,2), (1,2,0), (2,0,1), (2,1,0)]) def test_product(self): - return True - # check copy, deepcopy, pickle self.assertEqual(list(product('ABCD', 'xy')), list(map(tuple, 'Ax Ay Bx By Cx Cy Dx Dy'.split()))) self.assertEqual(list(product(range(2), repeat=3)), @@ -1448,19 +1382,16 @@ (1,0,0), (1,0,1), (1,1,0), (1,1,1)]) def test_repeat(self): - return True self.assertEqual(list(repeat(10, 3)), [10, 10, 10]) def test_stapmap(self): - return True self.assertEqual(list(starmap(pow, [(2,5), (3,2), (10,3)])), [32, 9, 1000]) def test_takewhile(self): - return True self.assertEqual(list(takewhile(lambda x: x<5, [1,4,6,4,1])), [1,4]) -""" + class TestGC(unittest.TestCase): def makecycle(self, iterator, container): @@ -1472,12 +1403,7 @@ a = [] self.makecycle(accumulate([1,2,a,3]), a) - def test_islice(self): - a = [] - self.makecycle(islice([a]*2, None), a) -""" def test_chain(self): - return True a = [] self.makecycle(chain(a), a) @@ -1543,6 +1469,9 @@ a = [] self.makecycle(map(lambda x:x, [a]*2), a) + def test_islice(self): + a = [] + self.makecycle(islice([a]*2, None), a) def test_permutations(self): a = [] @@ -1563,7 +1492,7 @@ def test_takewhile(self): a = [] self.makecycle(takewhile(bool, [1, 0, a, a]), a) -""" + def R(seqn): 'Regular generator' for i in seqn: @@ -1642,15 +1571,7 @@ class TestVariousIteratorArgs(unittest.TestCase): - def test_islice(self): - for s in ("12345", "", range(1000), ('do', 1.2), range(2000,2200,5)): - for g in (G, I, Ig, S, L, R): - self.assertEqual(list(islice(g(s),1,None,2)), list(g(s))[1::2]) - self.assertRaises(TypeError, islice, X(s), 10) - self.assertRaises(TypeError, islice, N(s), 10) - self.assertRaises(ZeroDivisionError, list, islice(E(s), 10)) def test_accumulate(self): - return True s = [1,2,3,4,5] r = [1,3,6,10,15] n = len(s) @@ -1660,7 +1581,7 @@ self.assertRaises(TypeError, accumulate, X(s)) self.assertRaises(TypeError, accumulate, N(s)) self.assertRaises(ZeroDivisionError, list, accumulate(E(s))) -""" + def test_chain(self): for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)): for g in (G, I, Ig, S, L, R): @@ -1751,6 +1672,13 @@ self.assertRaises(TypeError, map, onearg, N(s)) self.assertRaises(ZeroDivisionError, list, map(onearg, E(s))) + def test_islice(self): + for s in ("12345", "", range(1000), ('do', 1.2), range(2000,2200,5)): + for g in (G, I, Ig, S, L, R): + self.assertEqual(list(islice(g(s),1,None,2)), list(g(s))[1::2]) + self.assertRaises(TypeError, islice, X(s), 10) + self.assertRaises(TypeError, islice, N(s), 10) + self.assertRaises(ZeroDivisionError, list, islice(E(s), 10)) def test_starmap(self): for s in (range(10), range(0), range(100), (7,11), range(20,50,5)): @@ -1878,7 +1806,7 @@ except TypeError as err: # we expect type errors because of wrong argument count self.assertNotIn("does not take keyword arguments", err.args[0]) -""" + libreftest = """ Doctest for examples in the library reference: libitertools.tex @@ -2112,9 +2040,9 @@ __test__ = {'libreftest' : libreftest} def test_main(verbose=None): - test_classes = (TestBasicOps, TestExamples, TestGC, TestVariousIteratorArgs)#, TestGC, - #RegressionTests, LengthTransparency, - #SubclassWithKwargsTest, TestExamples) + test_classes = (TestBasicOps, TestVariousIteratorArgs, TestGC, + RegressionTests, LengthTransparency, + SubclassWithKwargsTest, TestExamples) support.run_unittest(*test_classes) # verify reference counting _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit