本文整理汇总了Python中coalib.results.result_actions.ApplyPatchAction.ApplyPatchAction类的典型用法代码示例。如果您正苦于以下问题:Python ApplyPatchAction类的具体用法?Python ApplyPatchAction怎么用?Python ApplyPatchAction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ApplyPatchAction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_apply_rename
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()
示例2: test_apply_rename
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()
示例3: test_apply_orig_option
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)
示例4: test_apply_orig_option
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"))
示例5: test_is_applicable_conflict
def test_is_applicable_conflict(self):
diff = Diff(["1\n", "2\n", "3\n"])
diff.add_lines(2, ['a line'])
conflict_result = Result("", "", diffs={'f': diff})
# Applying the same diff twice will result in a conflict
self.assertFalse(
ApplyPatchAction.is_applicable(conflict_result, {}, {'f': diff}))
示例6: test_apply
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)
示例7: test_is_applicable_empty_patch
def test_is_applicable_empty_patch(self):
diff = Diff([], rename='new_name')
result = Result('', '', diffs={'f': diff})
# Two renames donot result in any change
self.assertEqual(
ApplyPatchAction.is_applicable(result, {}, {'f': diff}),
'The given patches do not change anything anymore.'
)
示例8: test_is_applicable_conflict
def test_is_applicable_conflict(self):
diff = Diff(['1\n', '2\n', '3\n'])
diff.add_lines(2, ['a line'])
conflict_result = Result('', '', diffs={'f': diff})
# Applying the same diff twice will result in a conflict
self.assertIn(
'Two or more patches conflict with each other: ',
ApplyPatchAction.is_applicable(conflict_result, {}, {'f': diff})
)
示例9: test_apply
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)
示例10: test_apply_delete
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()
示例11: test_apply
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())
示例12: test_is_applicable_without_patch
def test_is_applicable_without_patch(self):
result = Result('', '')
self.assertEqual(
ApplyPatchAction.is_applicable(result, {}, {}),
'This result has no patch attached.'
)
示例13: test_is_applicable
def test_is_applicable(self):
diff = Diff(['1\n', '2\n', '3\n'])
diff.delete_line(2)
patch_result = Result('', '', diffs={'f': diff})
self.assertTrue(
ApplyPatchAction.is_applicable(patch_result, {}, {}))
示例14: test_is_applicable
def test_is_applicable(self):
patch_result = PatchResult("", "", {})
result = Result("", "")
self.assertTrue(ApplyPatchAction.is_applicable(patch_result))
self.assertFalse(ApplyPatchAction.is_applicable(result))
示例15: test_is_applicable
def test_is_applicable(self):
diff = Diff(["1\n", "2\n", "3\n"])
diff.delete_line(2)
patch_result = Result("", "", diffs={'f': diff})
self.assertTrue(
ApplyPatchAction.is_applicable(patch_result, {}, {}))