MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_ziplongest

Method test_ziplongest

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

Source from the content-addressed store, hash-verified

796 self.assertEqual(len(dict.fromkeys(ids)), len(ids))
797
798 def test_ziplongest(self):
799 for args in [
800 ['abc', range(6)],
801 [range(6), 'abc'],
802 [range(1000), range(2000,2100), range(3000,3050)],
803 [range(1000), range(0), range(3000,3050), range(1200), range(1500)],
804 [range(1000), range(0), range(3000,3050), range(1200), range(1500), range(0)],
805 ]:
806 target = [tuple([arg[i] if i < len(arg) else None for arg in args])
807 for i in range(max(map(len, args)))]
808 self.assertEqual(list(zip_longest(*args)), target)
809 self.assertEqual(list(zip_longest(*args, **{})), target)
810 target = [tuple((e is None and 'X' or e) for e in t) for t in target] # Replace None fills with 'X'
811 self.assertEqual(list(zip_longest(*args, **dict(fillvalue='X'))), target)
812
813 self.assertEqual(take(3,zip_longest('abcdef', count())), list(zip('abcdef', range(3)))) # take 3 from infinite input
814
815 self.assertEqual(list(zip_longest()), list(zip()))
816 self.assertEqual(list(zip_longest([])), list(zip([])))
817 self.assertEqual(list(zip_longest('abcdef')), list(zip('abcdef')))
818
819 self.assertEqual(list(zip_longest('abc', 'defg', **{})),
820 list(zip(list('abc')+[None], 'defg'))) # empty keyword dict
821 self.assertRaises(TypeError, zip_longest, 3)
822 self.assertRaises(TypeError, zip_longest, range(3), 3)
823
824 for stmt in [
825 "zip_longest('abc', fv=1)",
826 "zip_longest('abc', fillvalue=1, bogus_keyword=None)",
827 ]:
828 try:
829 eval(stmt, globals(), locals())
830 except TypeError:
831 pass
832 else:
833 self.fail('Did not raise Type in: ' + stmt)
834
835 self.assertEqual([tuple(list(pair)) for pair in zip_longest('abc', 'def')],
836 list(zip('abc', 'def')))
837 self.assertEqual([pair for pair in zip_longest('abc', 'def')],
838 list(zip('abc', 'def')))
839
840 @support.impl_detail("tuple reuse is specific to CPython")
841 def test_zip_longest_tuple_reuse(self):

Callers

nothing calls this directly

Calls 11

lenFunction · 0.85
maxFunction · 0.85
listClass · 0.85
takeFunction · 0.85
countFunction · 0.85
globalsFunction · 0.85
localsFunction · 0.85
evalFunction · 0.50
assertEqualMethod · 0.45
assertRaisesMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected