MCPcopy Index your code
hub / github.com/python/cpython / test_ziplongest

Method test_ziplongest

Lib/test/test_itertools.py:850–890  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

848 self.assertEqual(len(dict.fromkeys(ids)), len(ids))
849
850 def test_ziplongest(self):
851 for args in [
852 ['abc', range(6)],
853 [range(6), 'abc'],
854 [range(1000), range(2000,2100), range(3000,3050)],
855 [range(1000), range(0), range(3000,3050), range(1200), range(1500)],
856 [range(1000), range(0), range(3000,3050), range(1200), range(1500), range(0)],
857 ]:
858 target = [tuple([arg[i] if i < len(arg) else None for arg in args])
859 for i in range(max(map(len, args)))]
860 self.assertEqual(list(zip_longest(*args)), target)
861 self.assertEqual(list(zip_longest(*args, **{})), target)
862 target = [tuple((e is None and 'X' or e) for e in t) for t in target] # Replace None fills with 'X'
863 self.assertEqual(list(zip_longest(*args, **dict(fillvalue='X'))), target)
864
865 self.assertEqual(take(3,zip_longest('abcdef', count())), list(zip('abcdef', range(3)))) # take 3 from infinite input
866
867 self.assertEqual(list(zip_longest()), list(zip()))
868 self.assertEqual(list(zip_longest([])), list(zip([])))
869 self.assertEqual(list(zip_longest('abcdef')), list(zip('abcdef')))
870
871 self.assertEqual(list(zip_longest('abc', 'defg', **{})),
872 list(zip(list('abc')+[None], 'defg'))) # empty keyword dict
873 self.assertRaises(TypeError, zip_longest, 3)
874 self.assertRaises(TypeError, zip_longest, range(3), 3)
875
876 for stmt in [
877 "zip_longest('abc', fv=1)",
878 "zip_longest('abc', fillvalue=1, bogus_keyword=None)",
879 ]:
880 try:
881 eval(stmt, globals(), locals())
882 except TypeError:
883 pass
884 else:
885 self.fail('Did not raise Type in: ' + stmt)
886
887 self.assertEqual([tuple(list(pair)) for pair in zip_longest('abc', 'def')],
888 list(zip('abc', 'def')))
889 self.assertEqual([pair for pair in zip_longest('abc', 'def')],
890 list(zip('abc', 'def')))
891
892 @support.impl_detail("tuple reuse is specific to CPython")
893 def test_zip_longest_tuple_reuse(self):

Callers

nothing calls this directly

Calls 6

listClass · 0.85
takeFunction · 0.85
countFunction · 0.85
assertEqualMethod · 0.45
assertRaisesMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected