def test_add(self): file_dict = { "f_a": ["1", "2", "3"], "f_b": ["1", "2", "3"], "f_c": ["1", "2", "3"] } expected_file_dict = { "f_a": ["1", "3_changed"], "f_b": ["1", "2", "3_changed"], "f_c": ["1", "2", "3"] } diff = Diff() diff.delete_line(2) uut1 = PatchResult("origin", "msg", {"f_a": diff}) diff = Diff() diff.change_line(3, "3", "3_changed") uut2 = PatchResult("origin", "msg", {"f_a": diff}) diff = Diff() diff.change_line(3, "3", "3_changed") uut3 = PatchResult("origin", "msg", {"f_b": diff}) uut1 += uut2 + uut3 uut1.apply(file_dict) self.assertEqual(file_dict, expected_file_dict)
def test_apply(self): file_dict = {"f_a": ["1", "2", "3"], "f_b": ["1", "2", "3"]} expected_file_dict = { "f_a": ["1", "3_changed"], "f_b": ["1", "2", "3"] } diff = Diff() diff.delete_line(2) diff.change_line(3, "3", "3_changed") uut = PatchResult("origin", "msg", {"f_a": diff}) uut.apply(file_dict) self.assertEqual(file_dict, expected_file_dict) uut = PatchResult("origin", "msg", {}) for action in uut.get_actions(): action.apply( uut, {}, {}) # All those actions should be able to apply this result self.assertEqual(len(uut.get_actions()), 1)
def test_apply(self): file_dict = { "f_a": ["1", "2", "3"], "f_b": ["1", "2", "3"] } expected_file_dict = { "f_a": ["1", "3_changed"], "f_b": ["1", "2", "3"] } diff = Diff() diff.delete_line(2) diff.change_line(3, "3", "3_changed") uut = PatchResult("origin", "msg", {"f_a": diff}) uut.apply(file_dict) self.assertEqual(file_dict, expected_file_dict) uut = PatchResult("origin", "msg", {}) for action in uut.get_actions(): action.apply(uut, {}, {}) # All those actions should be able to apply this result self.assertEqual(len(uut.get_actions()), 1)