def test_fillvalue_as_keyword_argument_only(self): """Test can be called with fillvalue (but only as keyword arg).""" inputs = [1, 2, 3] outputs = [(1, 2, 3, 0)] self.assertIterableEqual(window(inputs, 4, fillvalue=0), outputs) with self.assertRaises(TypeError): window(inputs, 4, 0)
def test_window_size_larger_than_iterable(self): self.assertIterableEqual(window([], 1), [(None, )]) self.assertIterableEqual(window([1, 2], 3), [( 1, 2, None, )]) self.assertIterableEqual(window([1, 2, 3], 4), [(1, 2, 3, None)])
def test_returns_lazy_iterable(self): inputs = (n**2 for n in [1, 2, 3, 4, 5]) iterable = window(inputs, 2) self.assertEqual(iter(iterable), iter(iterable)) self.assertEqual(next(iterable), (1, 4)) self.assertEqual(next(iterable), (4, 9)) self.assertEqual(list(iterable), [(9, 16), (16, 25)])
def test_window_size_0(self): self.assertIterableEqual(window([1, 2, 3], 0), []) self.assertIterableEqual(window([], 0), [])
def test_accepts_iterator(self): inputs = (n**2 for n in [1, 2, 3, 4]) outputs = [(1, 4), (4, 9), (9, 16)] self.assertIterableEqual(window(inputs, 2), outputs)
def test_window_size_3(self): inputs = [1, 2, 3, 4, 5, 6] outputs = [(1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 5, 6)] self.assertIterableEqual(window(inputs, 3), outputs)
def test_string(self): inputs = "hey" outputs = [('h', 'e'), ('e', 'y')] self.assertIterableEqual(window(inputs, 2), outputs)
def test_none(self): inputs = [None, None] outputs = [(None, None)] self.assertIterableEqual(window(inputs, 2), outputs)
def test_window_size_1(self): self.assertIterableEqual(window([1, 2, 3], 1), [(1, ), (2, ), (3, )]) self.assertIterableEqual(window([1], 1), [(1, )])
def test_window_size_2(self): inputs = [1, 2, 3] outputs = [(1, 2), (2, 3)] self.assertIterableEqual(window(inputs, 2), outputs)