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


Python ApplyPatchAction.apply方法代码示例

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


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

示例1: test_apply_rename

# 需要导入模块: from coalib.results.result_actions.ApplyPatchAction import ApplyPatchAction [as 别名]
# 或者: from coalib.results.result_actions.ApplyPatchAction.ApplyPatchAction import apply [as 别名]
    def test_apply_rename(self):
        uut = ApplyPatchAction()
        with make_temp() as f_a:
            file_dict = {f_a: ['1\n', '2\n', '3\n']}
            expected_file_dict = {f_a+'.renamed':
                                      ['1\n', '2_changed\n', '3_changed\n']}
            file_diff_dict = {}
            diff = Diff(file_dict[f_a], rename=f_a+'.renamed')
            diff.change_line(3, '3\n', '3_changed\n')
            uut.apply(Result('origin', 'msg', diffs={f_a: diff}),
                      file_dict,
                      file_diff_dict)
            self.assertTrue(isfile(f_a+'.orig'))
            self.assertTrue(isfile(f_a+'.renamed'))
            self.assertFalse(isfile(f_a))

            diff = Diff(file_dict[f_a])
            diff.change_line(2, '2\n', '2_changed\n')
            uut.apply(Result('origin', 'msg', diffs={f_a: diff}),
                      file_dict,
                      file_diff_dict)
            self.assertFalse(isfile(f_a+'.renamed.orig'))

            file_dict = {f_a+'.renamed': open(f_a+'.renamed').readlines()}

            self.assertEqual(file_dict, expected_file_dict)
            # Recreate file so that context manager make_temp() can delete it
            open(f_a, 'w').close()
开发者ID:arush0311,项目名称:coala,代码行数:30,代码来源:ApplyPatchActionTest.py

示例2: test_apply_orig_option

# 需要导入模块: from coalib.results.result_actions.ApplyPatchAction import ApplyPatchAction [as 别名]
# 或者: from coalib.results.result_actions.ApplyPatchAction.ApplyPatchAction import apply [as 别名]
 def test_apply_orig_option(self):
     uut = ApplyPatchAction()
     with make_temp() as f_a, make_temp() as f_b:
         file_dict = {
             f_a: ["1\n", "2\n", "3\n"],
             f_b: ["1\n", "2\n", "3\n"]
             }
         expected_file_dict = {
             f_a: ["1\n", "2\n", "3_changed\n"],
             f_b: ["1\n", "2\n", "3_changed\n"]
             }
         file_diff_dict = {}
         diff = Diff(file_dict[f_a])
         diff.change_line(3, "3\n", "3_changed\n")
         uut.apply(Result("origin", "msg", diffs={f_a: diff}),
                   file_dict,
                   file_diff_dict,
                   no_orig=True)
         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,
                   no_orig=False)
         self.assertFalse(isfile(f_a+".orig"))
         self.assertTrue(isfile(f_b+".orig"))
开发者ID:scriptnull,项目名称:coala,代码行数:28,代码来源:ApplyPatchActionTest.py

示例3: test_apply_orig_option

# 需要导入模块: from coalib.results.result_actions.ApplyPatchAction import ApplyPatchAction [as 别名]
# 或者: from coalib.results.result_actions.ApplyPatchAction.ApplyPatchAction import apply [as 别名]
    def test_apply_orig_option(self):
        uut = ApplyPatchAction()
        with make_temp() as f_a, make_temp() as f_b:
            file_dict = {
                f_a: ['1\n', '2\n', '3\n'],
                f_b: ['1\n', '2\n', '3\n']
                }
            expected_file_dict = {
                f_a: ['1\n', '2\n', '3_changed\n'],
                f_b: ['1\n', '2\n', '3_changed\n']
                }
            file_diff_dict = {}
            diff = Diff(file_dict[f_a])
            diff.change_line(3, '3\n', '3_changed\n')
            uut.apply(Result('origin', 'msg', diffs={f_a: diff}),
                      file_dict,
                      file_diff_dict,
                      no_orig=True)
            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,
                      no_orig=False)
            self.assertFalse(isfile(f_a+'.orig'))
            self.assertTrue(isfile(f_b+'.orig'))

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

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

示例4: test_apply

# 需要导入模块: from coalib.results.result_actions.ApplyPatchAction import ApplyPatchAction [as 别名]
# 或者: from coalib.results.result_actions.ApplyPatchAction.ApplyPatchAction import apply [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

示例5: test_apply_rename

# 需要导入模块: from coalib.results.result_actions.ApplyPatchAction import ApplyPatchAction [as 别名]
# 或者: from coalib.results.result_actions.ApplyPatchAction.ApplyPatchAction import apply [as 别名]
    def test_apply_rename(self):
        uut = ApplyPatchAction()
        with make_temp() as f_a:
            file_dict = {f_a: ["1\n", "2\n", "3\n"]}
            expected_file_dict = {f_a+".renamed":
                                      ["1\n", "2_changed\n", "3_changed\n"]}
            file_diff_dict = {}
            diff = Diff(file_dict[f_a], rename=f_a+".renamed")
            diff.change_line(3, "3\n", "3_changed\n")
            uut.apply(Result("origin", "msg", diffs={f_a: diff}),
                      file_dict,
                      file_diff_dict)
            self.assertTrue(isfile(f_a+".orig"))
            self.assertTrue(isfile(f_a+".renamed"))
            self.assertFalse(isfile(f_a))

            diff = Diff(file_dict[f_a])
            diff.change_line(2, "2\n", "2_changed\n")
            uut.apply(Result("origin", "msg", diffs={f_a: diff}),
                      file_dict,
                      file_diff_dict)
            self.assertTrue(isfile(f_a+".renamed.orig"))

            file_dict = {f_a+".renamed": open(f_a+".renamed").readlines()}

            self.assertEqual(file_dict, expected_file_dict)
            # Recreate file so that context manager make_temp() can delete it
            open(f_a, 'w').close()
开发者ID:Shreyas94,项目名称:coala,代码行数:30,代码来源:ApplyPatchActionTest.py

示例6: test_apply

# 需要导入模块: from coalib.results.result_actions.ApplyPatchAction import ApplyPatchAction [as 别名]
# 或者: from coalib.results.result_actions.ApplyPatchAction.ApplyPatchAction import apply [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

示例7: test_apply

# 需要导入模块: from coalib.results.result_actions.ApplyPatchAction import ApplyPatchAction [as 别名]
# 或者: from coalib.results.result_actions.ApplyPatchAction.ApplyPatchAction import apply [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

示例8: test_apply_delete

# 需要导入模块: from coalib.results.result_actions.ApplyPatchAction import ApplyPatchAction [as 别名]
# 或者: from coalib.results.result_actions.ApplyPatchAction.ApplyPatchAction import apply [as 别名]
    def test_apply_delete(self):
        uut = ApplyPatchAction()
        with make_temp() as f_a:
            file_dict = {f_a: ['1\n', '2\n', '3\n']}
            file_diff_dict = {}
            diff = Diff(file_dict[f_a], delete=True)
            uut.apply(Result('origin', 'msg', diffs={f_a: diff}),
                      file_dict,
                      file_diff_dict)
            self.assertFalse(isfile(f_a))
            self.assertTrue(isfile(f_a+'.orig'))
            os.remove(f_a+'.orig')

            diff = Diff(file_dict[f_a])
            diff.change_line(3, '3\n', '3_changed\n')
            uut.apply(Result('origin', 'msg', diffs={f_a: diff}),
                      file_dict,
                      file_diff_dict)
            self.assertFalse(isfile(f_a+'.orig'))
            # Recreate file so that context manager make_temp() can delete it
            open(f_a, 'w').close()
开发者ID:arush0311,项目名称:coala,代码行数:23,代码来源:ApplyPatchActionTest.py


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