def test_copy(self): tests = [([[0], [1]], 4)] for test in tests: res = fill(*test, copy=False) self.assertIs(res[-1], test[0][-1]) res = fill(*test, copy=True) self.assertIsNot(res[-1], test[0][-1]) self.assertEqual(res[-1], test[0][-1])
def test_empty(self): tests = [(None, -1), ([], 0), (0, 0)] for test in tests: self.assertEqual(fill(*test), []) with self.assertRaises(ValueError): fill([], 1)
def test_multiple(self): tests = [((range(10), 2), [0, 1]), ((range(3), 5), [0, 1, 2, 2, 2])] for test, res in tests: self.assertEqual(fill(*test), res)
def test_no_copy(self): tests = [([], 0), (list(range(3)), 3)] for lst, sz in tests: self.assertIs(fill(lst, sz), lst)
def test_single(self): tests = [((1, 1), [1]), ((1, 5), [1] * 5)] for test, res in tests: self.assertEqual(fill(*test), res)
def test_fill_copy(lst, size): res = fill(lst, size, copy=False) assert res[-1] is lst[-1] res = fill(lst, size, copy=True) assert res[-1] is not lst[-1] assert res[-1] == lst[-1]
def test_fill_no_copy(lst, size): assert fill(lst, size) is lst
def test_fill(test, res): assert fill(*test) == res
def test_fill_error(): with pytest.raises(ValueError): fill([], 1)