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

Method assert_iterators_equal

Lib/test/test_range.py:25–44  ·  view source on GitHub ↗
(self, xs, ys, test_id, limit=None)

Source from the content-addressed store, hash-verified

23
24class RangeTest(unittest.TestCase):
25 def assert_iterators_equal(self, xs, ys, test_id, limit=None):
26 # check that an iterator xs matches the expected results ys,
27 # up to a given limit.
28 if limit is not None:
29 xs = itertools.islice(xs, limit)
30 ys = itertools.islice(ys, limit)
31 sentinel = object()
32 pairs = itertools.zip_longest(xs, ys, fillvalue=sentinel)
33 for i, (x, y) in enumerate(pairs):
34 if x == y:
35 continue
36 elif x == sentinel:
37 self.fail('{}: iterator ended unexpectedly '
38 'at position {}; expected {}'.format(test_id, i, y))
39 elif y == sentinel:
40 self.fail('{}: unexpected excess element {} at '
41 'position {}'.format(test_id, x, i))
42 else:
43 self.fail('{}: wrong element at position {}; '
44 'expected {}, got {}'.format(test_id, i, y, x))
45
46 def test_range(self):
47 self.assertEqual(list(range(3)), [0, 1, 2])

Callers 1

test_range_iteratorsMethod · 0.95

Calls 4

enumerateFunction · 0.85
isliceMethod · 0.80
failMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected