From a3bc186a204dfd09e3983cab6b572d4b205ca758 Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Mon, 4 Apr 2016 00:55:07 +0200 Subject: [PATCH] patchutils.py: Move external test resources to a separate directory. --- staging/patchutils.py | 32 +++++++------------------------- staging/tests/simple.patch | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 staging/tests/simple.patch diff --git a/staging/patchutils.py b/staging/patchutils.py index 9c268290..fd14680a 100644 --- a/staging/patchutils.py +++ b/staging/patchutils.py @@ -735,31 +735,13 @@ if __name__ == "__main__": # Basic tests for read_patch() class PatchReaderTests(unittest.TestCase): - def test_read(self): - source = ["From be07df750862699f2515c0ac0ceb7a6c25e9458a Mon Sep 17 00:00:00 2001", - "From: =?UTF-8?q?Author=20Name?= ", - "Subject: [PATCH v3] component: Replace arg1 with arg2.", - "", - "Signed-off-by: =?UTF-8?q?Author=20Name?= ", - "Signed-off-by: Other Developer ", - "---", - " test.txt | 2 +-", - " 1 file changed, 1 insertion(+), 1 deletion(-)", - "", - "diff --git a/test.txt b/test.txt", - "index d54375d..0078e66 100644", - "--- a/test.txt", "+++ b/test.txt", - "@@ -1,7 +1,7 @@", - " line1();", " line2();", " line3();", - "-function(arg1);", - "+function(arg2);", - " line5();", " line6();", " line7();", - "-- ", - "2.7.1"] + def test_simple(self): + with open("tests/simple.patch") as fp: + source = fp.read().split("\n") # Test formatted git patch with author and subject patchfile = tempfile.NamedTemporaryFile(mode='w+') - patchfile.write("\n".join(source + [""])) + patchfile.write("\n".join(source)) patchfile.flush() patches = list(read_patch(patchfile.name)) @@ -781,7 +763,7 @@ if __name__ == "__main__": del source[0:10] self.assertTrue(source[0].startswith("diff --git")) patchfile = tempfile.NamedTemporaryFile(mode='w+') - patchfile.write("\n".join(source + [""])) + patchfile.write("\n".join(source)) patchfile.flush() patches = list(read_patch(patchfile.name)) @@ -802,7 +784,7 @@ if __name__ == "__main__": del source[0:2] self.assertTrue(source[0].startswith("---")) patchfile = tempfile.NamedTemporaryFile(mode='w+') - patchfile.write("\n".join(source + [""])) + patchfile.write("\n".join(source)) patchfile.flush() patches = list(read_patch(patchfile.name)) @@ -820,7 +802,7 @@ if __name__ == "__main__": self.assertEqual(lines, source[:11]) # Test with StringIO buffer - fp = StringIO("\n".join(source + [""])) + fp = StringIO("\n".join(source)) patches = list(read_patch("unknown.patch", fp)) self.assertEqual(len(patches), 1) self.assertEqual(patches[0].patch_author, None) diff --git a/staging/tests/simple.patch b/staging/tests/simple.patch new file mode 100644 index 00000000..53fd0e2a --- /dev/null +++ b/staging/tests/simple.patch @@ -0,0 +1,25 @@ +From be07df750862699f2515c0ac0ceb7a6c25e9458a Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Author=20Name?= +Subject: [PATCH v3] component: Replace arg1 with arg2. + +Signed-off-by: =?UTF-8?q?Author=20Name?= +Signed-off-by: Other Developer +--- + test.txt | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/test.txt b/test.txt +index d54375d..0078e66 100644 +--- a/test.txt ++++ b/test.txt +@@ -1,7 +1,7 @@ + line1(); + line2(); + line3(); +-function(arg1); ++function(arg2); + line5(); + line6(); + line7(); +-- +2.7.1