(self, xs, ys, test_id, limit=None)
| 23 | |
| 24 | class 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]) |
no test coverage detected