当前位置: 首页>>代码示例>>Python>>正文


Python ApplyPatchAction.apply_from_section方法代码示例

本文整理汇总了Python中coalib.results.result_actions.ApplyPatchAction.ApplyPatchAction.apply_from_section方法的典型用法代码示例。如果您正苦于以下问题:Python ApplyPatchAction.apply_from_section方法的具体用法?Python ApplyPatchAction.apply_from_section怎么用?Python ApplyPatchAction.apply_from_section使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在coalib.results.result_actions.ApplyPatchAction.ApplyPatchAction的用法示例。


在下文中一共展示了ApplyPatchAction.apply_from_section方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_apply

# 需要导入模块: from coalib.results.result_actions.ApplyPatchAction import ApplyPatchAction [as 别名]
# 或者: from coalib.results.result_actions.ApplyPatchAction.ApplyPatchAction import apply_from_section [as 别名]
    def test_apply(self):
        uut = ApplyPatchAction()
        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"]
        }

        file_diff_dict = {}

        diff = Diff()
        diff.delete_line(2)
        uut.apply_from_section(PatchResult("origin", "msg", {"f_a": diff}), file_dict, file_diff_dict, Section("t"))

        diff = Diff()
        diff.change_line(3, "3", "3_changed")
        uut.apply_from_section(PatchResult("origin", "msg", {"f_a": diff}), file_dict, file_diff_dict, Section("t"))

        diff = Diff()
        diff.change_line(3, "3", "3_changed")
        uut.apply(PatchResult("origin", "msg", {"f_b": diff}), file_dict, file_diff_dict)

        for filename in file_diff_dict:
            file_dict[filename] = file_diff_dict[filename].apply(file_dict[filename])

        self.assertEqual(file_dict, expected_file_dict)
开发者ID:AhmedKamal1432,项目名称:coala,代码行数:33,代码来源:ApplyPatchActionTest.py

示例2: test_apply

# 需要导入模块: from coalib.results.result_actions.ApplyPatchAction import ApplyPatchAction [as 别名]
# 或者: from coalib.results.result_actions.ApplyPatchAction.ApplyPatchAction import apply_from_section [as 别名]
    def test_apply(self):
        uut = ApplyPatchAction()
        fh_a, f_a = mkstemp()
        fh_b, f_b = mkstemp()
        fh_c, f_c = mkstemp()
        os.close(fh_a)
        os.close(fh_b)
        os.close(fh_c)

        file_dict = {
            f_a: ["1\n", "2\n", "3\n"],
            f_b: ["1\n", "2\n", "3\n"],
            f_c: ["1\n", "2\n", "3\n"]
        }
        expected_file_dict = {
            f_a: ["1\n", "3_changed\n"],
            f_b: ["1\n", "2\n", "3_changed\n"],
            f_c: ["1\n", "2\n", "3\n"]
        }

        file_diff_dict = {}

        diff = Diff(file_dict[f_a])
        diff.delete_line(2)
        uut.apply_from_section(Result("origin", "msg", diffs={f_a: diff}),
                               file_dict,
                               file_diff_dict,
                               Section("t"))

        diff = Diff(file_dict[f_a])
        diff.change_line(3, "3\n", "3_changed\n")
        uut.apply_from_section(Result("origin", "msg", diffs={f_a: diff}),
                               file_dict,
                               file_diff_dict,
                               Section("t"))

        diff = Diff(file_dict[f_b])
        diff.change_line(3, "3\n", "3_changed\n")
        uut.apply(Result("origin", "msg", diffs={f_b: diff}),
                  file_dict,
                  file_diff_dict)

        for filename in file_diff_dict:
            file_dict[filename] = file_diff_dict[filename].modified

        self.assertEqual(file_dict, expected_file_dict)
        with open(f_a) as fa:
            self.assertEqual(file_dict[f_a], fa.readlines())
        with open(f_b) as fb:
            self.assertEqual(file_dict[f_b], fb.readlines())
        with open(f_c) as fc:
            # File c is unchanged and should be untouched
            self.assertEqual([], fc.readlines())

        os.remove(f_a)
        os.remove(f_b)
        os.remove(f_c)
开发者ID:Tanmay28,项目名称:coala,代码行数:59,代码来源:ApplyPatchActionTest.py

示例3: test_apply

# 需要导入模块: from coalib.results.result_actions.ApplyPatchAction import ApplyPatchAction [as 别名]
# 或者: from coalib.results.result_actions.ApplyPatchAction.ApplyPatchAction import apply_from_section [as 别名]
    def test_apply(self):
        uut = ApplyPatchAction()
        with make_temp() as f_a, make_temp() as f_b, make_temp() as f_c:

            file_dict = {
                f_a: ['1\n', '2\n', '3\n'],
                f_b: ['1\n', '2\n', '3\n'],
                f_c: ['1\n', '2\n', '3\n']
            }
            expected_file_dict = {
                f_a: ['1\n', '3_changed\n'],
                f_b: ['1\n', '2\n', '3_changed\n'],
                f_c: ['1\n', '2\n', '3\n']
            }

            file_diff_dict = {}

            diff = Diff(file_dict[f_a])
            diff.delete_line(2)
            uut.apply_from_section(Result('origin', 'msg', diffs={f_a: diff}),
                                   file_dict,
                                   file_diff_dict,
                                   Section('t'))

            diff = Diff(file_dict[f_a])
            diff.change_line(3, '3\n', '3_changed\n')
            uut.apply_from_section(Result('origin', 'msg', diffs={f_a: diff}),
                                   file_dict,
                                   file_diff_dict,
                                   Section('t'))

            diff = Diff(file_dict[f_b])
            diff.change_line(3, '3\n', '3_changed\n')
            uut.apply(Result('origin', 'msg', diffs={f_b: diff}),
                      file_dict,
                      file_diff_dict)

            for filename in file_diff_dict:
                file_dict[filename] = file_diff_dict[filename].modified

            self.assertEqual(file_dict, expected_file_dict)
            with open(f_a) as fa:
                self.assertEqual(file_dict[f_a], fa.readlines())
            with open(f_b) as fb:
                self.assertEqual(file_dict[f_b], fb.readlines())
            with open(f_c) as fc:
                # File c is unchanged and should be untouched
                self.assertEqual([], fc.readlines())
开发者ID:arush0311,项目名称:coala,代码行数:50,代码来源:ApplyPatchActionTest.py


注:本文中的coalib.results.result_actions.ApplyPatchAction.ApplyPatchAction.apply_from_section方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。