Skip to content

Commit 283d7fa

Browse files
authored
Add test to validate empty patch (#47)
* Add test to validate issue #35 Signed-off-by: Uilian Ries <uilianr@jfrog.com> * Add empty patch for testing Signed-off-by: Uilian Ries <uilianr@jfrog.com> --------- Signed-off-by: Uilian Ries <uilianr@jfrog.com>
1 parent 843bef7 commit 283d7fa

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

tests/emptypatches/create755.patch

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
From 39fdfb57a112a3b00cc352b45d17aba4f0f58005 Mon Sep 17 00:00:00 2001
2+
From: John Doe <john.doe@mail.com>
3+
Date: Wed, 1 Oct 2025 12:39:25 +0200
4+
Subject: [PATCH] Add quotes.txt
5+
6+
Signed-off-by: John Doe <john.doe@mail.com>
7+
---
8+
quote.txt | 1 +
9+
1 file changed, 1 insertion(+)
10+
create mode 100755 quote.txt
11+
12+
diff --git a/quote.txt b/quote.txt
13+
new file mode 100755
14+
index 0000000000000000000000000000000000000000..cbfafe956ec35385f5b728daa390603ff71f1933
15+
--- /dev/null
16+
+++ b/quote.txt
17+
@@ -0,0 +1 @@
18+
+post malam segetem, serendum est.
19+
--
20+
2.51.0
21+

tests/emptypatches/update644.patch

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
From 9a6f61c8cabffc01811605577d6d276a07c8bb95 Mon Sep 17 00:00:00 2001
2+
From: John Doe <john.doe@mail.com>
3+
Date: Fri, 3 Oct 2025 08:57:43 +0200
4+
Subject: [PATCH] Change file permission
5+
6+
Signed-off-by: John Doe <john.doe@mail.com>
7+
---
8+
quote.txt | 0
9+
1 file changed, 0 insertions(+), 0 deletions(-)
10+
mode change 100755 => 100644 quote.txt
11+
12+
diff --git a/quote.txt b/quote.txt
13+
old mode 100755
14+
new mode 100644
15+
--
16+
2.51.0

tests/run_tests.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,42 @@ def test_handle_full_index_patch_format(self):
521521
self.assertTrue(pto.apply())
522522
self.assertEqual(os.stat(join(self.tmpdir, 'quote.txt')).st_mode, 0o644 | stat.S_IFREG)
523523

524+
525+
class TestPatchEmptyFile(unittest.TestCase):
526+
527+
def setUp(self):
528+
self.save_cwd = os.getcwd()
529+
self.tmpdir = mkdtemp(prefix=self.__class__.__name__)
530+
shutil.copytree(join(TESTS, 'emptypatches'), join(self.tmpdir, 'emptypatches'))
531+
532+
def tearDown(self):
533+
os.chdir(self.save_cwd)
534+
remove_tree_force(self.tmpdir)
535+
536+
@unittest.skipIf(platform.system() == "Windows", "File permission modes are not supported on Windows")
537+
@unittest.expectedFailure # FIXME: https://github.com/conan-io/python-patch-ng/issues/35
538+
def test_apply_patch_only_file_mode(self):
539+
"""Test when a patch file is empty in terms of content, but has file
540+
permission mode listed in the patch, the same should be applied to
541+
the target file after patching.
542+
"""
543+
544+
os.chdir(self.tmpdir)
545+
pto = patch_ng.fromfile(join(self.tmpdir, 'emptypatches', 'create755.patch'))
546+
self.assertEqual(len(pto), 1)
547+
self.assertEqual(pto.items[0].type, patch_ng.GIT)
548+
self.assertEqual(pto.items[0].filemode, 0o100755)
549+
self.assertTrue(pto.apply())
550+
self.assertTrue(os.path.exists(join(self.tmpdir, 'quote.txt')))
551+
self.assertEqual(os.stat(join(self.tmpdir, 'quote.txt')).st_mode, 0o755 | stat.S_IFREG)
552+
553+
pto = patch_ng.fromfile(join(self.tmpdir, 'emptypatches', 'update644.patch'))
554+
self.assertEqual(len(pto), 1)
555+
self.assertEqual(pto.items[0].type, patch_ng.GIT)
556+
self.assertEqual(pto.items[0].filemode, 0o100644)
557+
self.assertTrue(pto.apply())
558+
self.assertEqual(os.stat(join(self.tmpdir, 'quote.txt')).st_mode, 0o644 | stat.S_IFREG)
559+
524560
class TestHelpers(unittest.TestCase):
525561
# unittest setting
526562
longMessage = True

0 commit comments

Comments
 (0)