Skip to content

Commit 05e29cd

Browse files
committed
Fix unit tests
Signed-off-by: Uilian Ries <uilianries@gmail.com>
1 parent 1a49328 commit 05e29cd

File tree

8 files changed

+101
-101
lines changed

8 files changed

+101
-101
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ script:
1717
- coverage run tests/run_tests.py
1818
- coverage report -m
1919
# test distribution packaging
20-
- python -m pypack patch.py
20+
- python -m pypack patch_ng.py

patch_ng.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def tostr(b):
7979

8080
#------------------------------------------------
8181
# Logging is controlled by logger named after the
82-
# module name (e.g. 'patch' for patch.py module)
82+
# module name (e.g. 'patch' for patch_ng.py module)
8383

8484
logger = logging.getLogger(__name__)
8585

@@ -1247,7 +1247,7 @@ def main():
12471247
else:
12481248
patch.apply(options.strip, root=options.directory) or sys.exit(-1)
12491249

1250-
# todo: document and test line ends handling logic - patch.py detects proper line-endings
1250+
# todo: document and test line ends handling logic - patch_ng.py detects proper line-endings
12511251
# for inserted hunks and issues a warning if patched file has incosistent line ends
12521252

12531253

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def load_version():
120120
# pip to create the appropriate form of executable for the target platform.
121121
#entry_points={
122122
# 'console_scripts': [
123-
# 'patch.py=patch',
123+
# 'patch_ng.py=patch',
124124
# ],
125125
#},
126126
)

tests/05hg_change.from

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ if "-v" in sys.argv or "--verbose" in sys.argv:
4141
tests_dir = dirname(abspath(__file__))
4242

4343

44-
# import patch.py from parent directory
44+
# import patch_ng.py from parent directory
4545
save_path = sys.path
4646
sys.path.insert(0, dirname(tests_dir))
47-
import patch
47+
import patch_ng
4848
sys.path = save_path
4949

5050

@@ -68,7 +68,7 @@ class TestPatchFiles(unittest.TestCase):
6868
f2.close()
6969
if f1:
7070
f1.close()
71-
71+
7272
def _assert_dirs_equal(self, dir1, dir2, ignore=[]):
7373
""" compare dir1 with reference dir2
7474
.svn dirs are ignored
@@ -94,23 +94,23 @@ class TestPatchFiles(unittest.TestCase):
9494
continue
9595
self.fail("extra file or directory: %s" % e2)
9696

97-
97+
9898
def _run_test(self, testname):
9999
"""
100100
boilerplate for running *.patch file tests
101101
"""
102102

103103
# 1. create temp test directory
104104
# 2. copy files
105-
# 3. execute file-based patch
105+
# 3. execute file-based patch
106106
# 4. compare results
107107
# 5. cleanup on success
108108

109109
tmpdir = mkdtemp(prefix="%s."%testname)
110110

111111
patch_file = join(tmpdir, "%s.patch" % testname)
112112
shutil.copy(join(tests_dir, "%s.patch" % testname), patch_file)
113-
113+
114114
from_src = join(tests_dir, "%s.from" % testname)
115115
from_tgt = join(tmpdir, "%s.from" % testname)
116116

@@ -129,7 +129,7 @@ class TestPatchFiles(unittest.TestCase):
129129

130130
# 3.
131131
# test utility as a whole
132-
patch_tool = join(dirname(tests_dir), "patch.py")
132+
patch_tool = join(dirname(tests_dir), "patch_ng.py")
133133
save_cwd = os.getcwdu()
134134
os.chdir(tmpdir)
135135
if verbose:
@@ -150,7 +150,7 @@ class TestPatchFiles(unittest.TestCase):
150150
# need recursive compare
151151
self._assert_dirs_equal(join(tests_dir, "%s.to" % testname), tmpdir, "%s.patch" % testname)
152152

153-
153+
154154

155155
shutil.rmtree(tmpdir)
156156
return 0
@@ -200,7 +200,7 @@ class TestCheckPatched(unittest.TestCase):
200200
pto3 = patch.fromfile("03trail_fname.patch")
201201
self.assertEqual(None, pto3.can_patch("03trail_fname.to"))
202202
self.assertEqual(None, pto3.can_patch("not_in_source.also"))
203-
203+
204204
def test_multiline_false_on_other_file(self):
205205
pto = patch.fromfile("01uni_multi.patch")
206206
os.chdir(join(tests_dir, "01uni_multi.from"))

tests/05hg_change.to

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ if "-v" in sys.argv or "--verbose" in sys.argv:
4141
tests_dir = dirname(abspath(__file__))
4242

4343

44-
# import patch.py from parent directory
44+
# import patch_ng.py from parent directory
4545
save_path = sys.path
4646
sys.path.insert(0, dirname(tests_dir))
47-
import patch
47+
import patch_ng
4848
sys.path = save_path
4949

5050

@@ -68,7 +68,7 @@ class TestPatchFiles(unittest.TestCase):
6868
f2.close()
6969
if f1:
7070
f1.close()
71-
71+
7272
def _assert_dirs_equal(self, dir1, dir2, ignore=[]):
7373
""" compare dir1 with reference dir2
7474
.svn dirs are ignored
@@ -94,23 +94,23 @@ class TestPatchFiles(unittest.TestCase):
9494
continue
9595
self.fail("extra file or directory: %s" % e2)
9696

97-
97+
9898
def _run_test(self, testname):
9999
"""
100100
boilerplate for running *.patch file tests
101101
"""
102102

103103
# 1. create temp test directory
104104
# 2. copy files
105-
# 3. execute file-based patch
105+
# 3. execute file-based patch
106106
# 4. compare results
107107
# 5. cleanup on success
108108

109109
tmpdir = mkdtemp(prefix="%s."%testname)
110110

111111
patch_file = join(tmpdir, "%s.patch" % testname)
112112
shutil.copy(join(tests_dir, "%s.patch" % testname), patch_file)
113-
113+
114114
from_src = join(tests_dir, "%s.from" % testname)
115115
from_tgt = join(tmpdir, "%s.from" % testname)
116116

@@ -129,7 +129,7 @@ class TestPatchFiles(unittest.TestCase):
129129

130130
# 3.
131131
# test utility as a whole
132-
patch_tool = join(dirname(tests_dir), "patch.py")
132+
patch_tool = join(dirname(tests_dir), "patch_ng.py")
133133
save_cwd = os.getcwdu()
134134
os.chdir(tmpdir)
135135
if verbose:
@@ -150,7 +150,7 @@ class TestPatchFiles(unittest.TestCase):
150150
# need recursive compare
151151
self._assert_dirs_equal(join(tests_dir, "%s.to" % testname), tmpdir, "%s.patch" % testname)
152152

153-
153+
154154

155155
shutil.rmtree(tmpdir)
156156
return 0
@@ -200,7 +200,7 @@ class TestCheckPatched(unittest.TestCase):
200200
pto3 = patch.fromfile("03trail_fname.patch")
201201
self.assertEqual(None, pto3.can_patch("03trail_fname.to"))
202202
self.assertEqual(None, pto3.can_patch("not_in_source.also"))
203-
203+
204204
def test_multiline_false_on_other_file(self):
205205
pto = patch.fromfile("01uni_multi.patch")
206206
os.chdir(join(tests_dir, "01uni_multi.from"))

tests/data/autofix/absolute-path.diff

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
Index: c:/winnt/tests/run_tests.py
2-
===================================================================
3-
--- c:/winnt/tests/run_tests.py (revision 132)
4-
+++ c:/winnt/tests/run_tests.py (working copy)
5-
@@ -240,6 +240,12 @@
1+
Index: c:/winnt/tests/run_tests.py
2+
===================================================================
3+
--- c:/winnt/tests/run_tests.py (revision 132)
4+
+++ c:/winnt/tests/run_tests.py (working copy)
5+
@@ -240,6 +240,12 @@
66
self.assertNotEqual(pto.parse(fp), True)
77
fp.close()
8-
8+
99
+ def test_fail_absolute_path(self):
1010
+ fp = open(join(tests_dir, "data/failing/absolute-path.diff"))
1111
+ res = patch.PatchSet().parse(fp)
@@ -15,36 +15,36 @@ Index: c:/winnt/tests/run_tests.py
1515
class TestPatchApply(unittest.TestCase):
1616
def setUp(self):
1717
self.save_cwd = os.getcwdu()
18-
Index: c:/winnt/patch.py
19-
===================================================================
20-
--- c:/winnt/patch.py (revision 132)
21-
+++ c:/winnt/patch.py (working copy)
22-
@@ -22,7 +22,7 @@
18+
Index: c:/winnt/patch_ng.py
19+
===================================================================
20+
--- c:/winnt/patch_ng.py (revision 132)
21+
+++ c:/winnt/patch_ng.py (working copy)
22+
@@ -22,7 +22,7 @@
2323
from StringIO import StringIO
2424
import urllib2
25-
25+
2626
-from os.path import exists, isfile, abspath
2727
+from os.path import exists, isabs, isfile, abspath
2828
from os import unlink
29-
30-
31-
@@ -439,7 +439,21 @@
32-
29+
30+
31+
@@ -439,7 +439,21 @@
32+
3333
return (errors == 0)
34-
34+
3535
+ def process_filenames():
3636
+ """ sanitize filenames
3737
+ return True on success
3838
+ """
3939
+ errors = 0
40-
40+
4141
+ for i,p in enumerate(self.items):
42-
+ #
42+
+ #
4343
+
4444
+ # absolute paths are not allowed
4545
+ if isabs(p.source) or isabs(p.target):
4646
+ warning("error: absolute paths are not allowed for patch no.%d" % i)
47-
+
47+
+
4848
+ return (errors == 0)
4949
+
5050
def apply(self):

tests/data/autofix/parent-path.diff

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
Index: patch.py
1+
Index: patch_ng.py
22
===================================================================
3-
--- ../patch.py (revision 151)
4-
+++ ../patch.py (working copy)
3+
--- ../patch_ng.py (revision 151)
4+
+++ ../patch_ng.py (working copy)
55
@@ -13,7 +13,7 @@
66
"""
7-
7+
88
__author__ = "techtonik.rainforce.org"
99
-__version__ = "1.11.10-dev"
1010
+__version__ = "1.11.11-dev"
11-
11+
1212
import copy
1313
import logging

0 commit comments

Comments
 (0)