Exemplo n.º 1
0
    def test_change_success(self):
        files = self.files
        with open(files[0], "w") as f:
            f.write("this line is removed\n")
        with open(files[1], "w") as f:
            f.write("this line is not removed\n")

        change = self.change
        change.add_validated_files(files)
        change.append_expected_add(files[0], "this is a new line")
        change.append_expected_remove(files[0], "this line is removed")
        change.append_expected_add(files[1], "this is a new line again")

        diff_validator.make_temp_file_copies(change.get_target_files())
        with open(files[0], "w") as f:
            f.write("this is a new line")
        with open(files[1], "w") as f:
            f.write("this line is not removed\nthis is a new line again\n")

        changes = diff_validator.extract_changes(change.get_target_files())
        change_success = diff_validator.assert_change(changes,
                                                      change.files_dict)
        change_dict = diff_validator.assert_change_dict(
            changes, change.files_dict)
        self.assertTrue(
            change_success, "The change must be valid:\n%s" %
            diff_validator.create_diff_report(change_dict))
Exemplo n.º 2
0
    def test_change_wrong_no_change(self):
        files = self.files
        with open(files[0], "w", encoding='utf-8') as f:
            f.write("this line is removed\n")

        change = self.change
        change.add_validated_files(files)
        change.append_expected_add(files[0], "this is a new line")
        change.append_expected_remove(files[0], "this line is removed")

        diff_validator.make_temp_file_copies(change.get_target_files())

        changes = diff_validator.extract_changes(change.get_target_files())
        change_success = diff_validator.assert_change(changes, change.files_dict)
        change_dict = diff_validator.assert_change_dict(changes, change.files_dict)
        self.assertFalse(change_success, "The change must not be valid:\n%s" % diff_validator.create_diff_report(change_dict))