Skip to content

Commit e9adaf8

Browse files
committed
#5 Add tests for fuzzy patching
Signed-off-by: Uilian Ries <uilianries@gmail.com>
1 parent 9634ba4 commit e9adaf8

File tree

8 files changed

+49
-3
lines changed

8 files changed

+49
-3
lines changed

patch_ng.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ def apply(self, strip=0, root=None, fuzz=False):
10431043
# todo \ No newline at end of file
10441044

10451045
# check hunks in source file
1046-
if lineno+1 < hunk.startsrc+len(hunkfind)-1:
1046+
if lineno+1 < hunk.startsrc+len(hunkfind):
10471047
if line.rstrip(b"\r\n") == hunkfind[hunklineno]:
10481048
hunklineno += 1
10491049
else:

tests/10fuzzyafter/10fuzzyafter.patch

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
diff --git a/Jamroot b/Jamroot
2+
index a6981dd..0c08f09 100644
3+
--- a/Jamroot
4+
+++ b/Jamroot
5+
@@ -1,3 +1,4 @@
6+
X
7+
Y
8+
+V
9+
W

tests/10fuzzyafter/Jamroot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
X
2+
Y
3+
Z

tests/10fuzzyafter/[result]/Jamroot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
X
2+
Y
3+
V
4+
Z
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
diff --git a/Jamroot b/Jamroot
2+
index a6981dd..0c08f09 100644
3+
--- a/Jamroot
4+
+++ b/Jamroot
5+
@@ -1,3 +1,4 @@
6+
T
7+
YYYY
8+
+V
9+
Z

tests/10fuzzybefore/Jamroot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
X
2+
Y
3+
Z

tests/10fuzzybefore/[result]/Jamroot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
X
2+
Y
3+
V
4+
Z

tests/run_tests.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def _run_test(self, testname):
151151
patch_tool = join(dirname(TESTS), "patch_ng.py")
152152
save_cwd = getcwdu()
153153
os.chdir(tmpdir)
154-
extra = "-f" if testname == "10fuzzy" else ""
154+
extra = "-f" if "10fuzzy" in testname else ""
155155
if verbose:
156156
cmd = '%s %s %s "%s"' % (sys.executable, patch_tool, extra, patch_file)
157157
print("\n"+cmd)
@@ -425,13 +425,27 @@ def test_delete_file(self):
425425
pto.apply(strip=0, root=treeroot)
426426
self.assertFalse(os.path.exists(os.path.join(treeroot, 'deleted')))
427427

428-
def test_fuzzy_patch(self):
428+
def test_fuzzy_patch_both(self):
429429
treeroot = join(self.tmpdir, 'rootparent')
430430
shutil.copytree(join(TESTS, '10fuzzy'), treeroot)
431431
pto = patch_ng.fromfile(join(TESTS, '10fuzzy/10fuzzy.patch'))
432432
self.assertTrue(pto.apply(root=treeroot, fuzz=True))
433433
self.assertFalse(pto.apply(root=treeroot, fuzz=False))
434434

435+
def test_fuzzy_patch_before(self):
436+
treeroot = join(self.tmpdir, 'rootparent')
437+
shutil.copytree(join(TESTS, '10fuzzybefore'), treeroot)
438+
pto = patch_ng.fromfile(join(TESTS, '10fuzzybefore/10fuzzybefore.patch'))
439+
self.assertTrue(pto.apply(root=treeroot, fuzz=True))
440+
self.assertFalse(pto.apply(root=treeroot, fuzz=False))
441+
442+
def test_fuzzy_patch_after(self):
443+
treeroot = join(self.tmpdir, 'rootparent')
444+
shutil.copytree(join(TESTS, '10fuzzyafter'), treeroot)
445+
pto = patch_ng.fromfile(join(TESTS, '10fuzzyafter/10fuzzyafter.patch'))
446+
self.assertTrue(pto.apply(root=treeroot, fuzz=True))
447+
self.assertFalse(pto.apply(root=treeroot, fuzz=False))
448+
435449

436450
class TestHelpers(unittest.TestCase):
437451
# unittest setting

0 commit comments

Comments
 (0)