Skip to content

Commit

Permalink
Mark itertools tests of tuple reuse as being specific to CPython.
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Jul 17, 2011
1 parent 3121547 commit e151d21
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions Lib/test/test_itertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ def combinations3(iterable, r):
self.assertEqual(result, list(combinations2(values, r))) # matches second pure python version
self.assertEqual(result, list(combinations3(values, r))) # matches second pure python version

# Test implementation detail: tuple re-use
@support.impl_detail("tuple reuse is specific to CPython")
def test_combinations_tuple_reuse(self):
self.assertEqual(len(set(map(id, combinations('abcde', 3)))), 1)
self.assertNotEqual(len(set(map(id, list(combinations('abcde', 3))))), 1)

Expand Down Expand Up @@ -238,7 +239,9 @@ def numcombs(n, r):
self.assertEqual(result, list(cwr1(values, r))) # matches first pure python version
self.assertEqual(result, list(cwr2(values, r))) # matches second pure python version

# Test implementation detail: tuple re-use
@support.impl_detail("tuple reuse is specific to CPython")
def test_combinations_with_replacement_tuple_reuse(self):
cwr = combinations_with_replacement
self.assertEqual(len(set(map(id, cwr('abcde', 3)))), 1)
self.assertNotEqual(len(set(map(id, list(cwr('abcde', 3))))), 1)

Expand Down Expand Up @@ -302,7 +305,8 @@ def permutations2(iterable, r=None):
self.assertEqual(result, list(permutations(values, None))) # test r as None
self.assertEqual(result, list(permutations(values))) # test default r

# Test implementation detail: tuple re-use
@support.impl_detail("tuple resuse is CPython specific")
def test_permutations_tuple_reuse(self):
self.assertEqual(len(set(map(id, permutations('abcde', 3)))), 1)
self.assertNotEqual(len(set(map(id, list(permutations('abcde', 3))))), 1)

Expand Down Expand Up @@ -566,11 +570,13 @@ def test_zip(self):
self.assertEqual(list(zip()), lzip())
self.assertRaises(TypeError, zip, 3)
self.assertRaises(TypeError, zip, range(3), 3)
# Check tuple re-use (implementation detail)
self.assertEqual([tuple(list(pair)) for pair in zip('abc', 'def')],
lzip('abc', 'def'))
self.assertEqual([pair for pair in zip('abc', 'def')],
lzip('abc', 'def'))

@support.impl_detail("tuple reuse is specific to CPython")
def test_zip_tuple_reuse(self):
ids = list(map(id, zip('abc', 'def')))
self.assertEqual(min(ids), max(ids))
ids = list(map(id, list(zip('abc', 'def'))))
Expand Down Expand Up @@ -613,11 +619,13 @@ def test_ziplongest(self):
else:
self.fail('Did not raise Type in: ' + stmt)

# Check tuple re-use (implementation detail)
self.assertEqual([tuple(list(pair)) for pair in zip_longest('abc', 'def')],
list(zip('abc', 'def')))
self.assertEqual([pair for pair in zip_longest('abc', 'def')],
list(zip('abc', 'def')))

@support.impl_detail("tuple reuse is specific to CPython")
def test_zip_longest_tuple_reuse(self):
ids = list(map(id, zip_longest('abc', 'def')))
self.assertEqual(min(ids), max(ids))
ids = list(map(id, list(zip_longest('abc', 'def'))))
Expand Down Expand Up @@ -721,7 +729,8 @@ def product2(*args, **kwds):
args = map(iter, args)
self.assertEqual(len(list(product(*args))), expected_len)

# Test implementation detail: tuple re-use
@support.impl_detail("tuple reuse is specific to CPython")
def test_product_tuple_reuse(self):
self.assertEqual(len(set(map(id, product('abc', 'def')))), 1)
self.assertNotEqual(len(set(map(id, list(product('abc', 'def'))))), 1)

Expand Down

0 comments on commit e151d21

Please sign in to comment.