Skip to content

Commit

Permalink
Merge pull request #3 from boegel/fix_git_patch_permissions
Browse files Browse the repository at this point in the history
enhance test for apply_patch to also cover applying patches with git
  • Loading branch information
Flamefire authored Aug 18, 2020
2 parents 0f40683 + bbde96c commit 694999d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 13 deletions.
6 changes: 3 additions & 3 deletions test/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1856,7 +1856,7 @@ def run_checks():
# single SHA256 checksum per source/patch: OK
eb.cfg['checksums'] = [
'44332000aa33b99ad1e00cbd1a7da769220d74647060a10e807b916d73ea27bc', # toy-0.0.tar.gz
'45b5e3f9f495366830e1869bb2b8f4e7c28022739ce48d9f9ebb159b439823c5', # toy-*.patch
'81a3accc894592152f81814fbf133d39afad52885ab52c25018722c7bda92487', # toy-*.patch
'4196b56771140d8e2468fb77f0240bc48ddbf5dabafe0713d612df7fafb1e458', # toy-extra.txt]
]
# no checksum issues
Expand All @@ -1865,7 +1865,7 @@ def run_checks():
# SHA256 checksum with type specifier: OK
eb.cfg['checksums'] = [
('sha256', '44332000aa33b99ad1e00cbd1a7da769220d74647060a10e807b916d73ea27bc'), # toy-0.0.tar.gz
'45b5e3f9f495366830e1869bb2b8f4e7c28022739ce48d9f9ebb159b439823c5', # toy-*.patch
'81a3accc894592152f81814fbf133d39afad52885ab52c25018722c7bda92487', # toy-*.patch
('sha256', '4196b56771140d8e2468fb77f0240bc48ddbf5dabafe0713d612df7fafb1e458'), # toy-extra.txt]
]
# no checksum issues
Expand All @@ -1878,7 +1878,7 @@ def run_checks():
'a2848f34fcd5d6cf47def00461fcb528a0484d8edef8208d6d2e2909dc61d9cd',
'44332000aa33b99ad1e00cbd1a7da769220d74647060a10e807b916d73ea27bc',
),
'45b5e3f9f495366830e1869bb2b8f4e7c28022739ce48d9f9ebb159b439823c5', # toy-*.patch
'81a3accc894592152f81814fbf133d39afad52885ab52c25018722c7bda92487', # toy-*.patch
'4196b56771140d8e2468fb77f0240bc48ddbf5dabafe0713d612df7fafb1e458', # toy-extra.txt
]
# no checksum issues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sources = [SOURCE_TAR_GZ]
patches = ['toy-0.0_fix-silly-typo-in-printf-statement.patch']
checksums = [
('adler32', '0x998410035'),
'e6785e1a721fc8bf79892e3ef41557c0',
'a99f2a72cee1689a2f7e3ace0356efb1',
]

moduleclass = 'tools'
Expand Down
46 changes: 44 additions & 2 deletions test/framework/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,9 +1359,8 @@ def test_derive_alt_pypi_url(self):
def test_apply_patch(self):
""" Test apply_patch """
testdir = os.path.dirname(os.path.abspath(__file__))
tmpdir = self.test_prefix
toy_tar_gz = os.path.join(testdir, 'sandbox', 'sources', 'toy', 'toy-0.0.tar.gz')
path = ft.extract_file(toy_tar_gz, tmpdir, change_into_dir=False)
path = ft.extract_file(toy_tar_gz, self.test_prefix, change_into_dir=False)
toy_patch_fn = 'toy-0.0_fix-silly-typo-in-printf-statement.patch'
toy_patch = os.path.join(testdir, 'sandbox', 'sources', 'toy', toy_patch_fn)

Expand Down Expand Up @@ -1403,6 +1402,49 @@ def test_apply_patch(self):
ft.apply_patch(test_file, os.path.join(target_dir, 'subdir', 'target.txt'), copy=True)
self.assertEqual(ft.read_file(os.path.join(target_dir, 'subdir', 'target.txt')), '123')

# cleanup and re-extract toy source tarball
ft.remove_dir(self.test_prefix)
ft.mkdir(self.test_prefix)
ft.change_dir(self.test_prefix)
path = ft.extract_file(toy_tar_gz, self.test_prefix, change_into_dir=False)

# test applying of patch with git
toy_source_path = os.path.join(self.test_prefix, 'toy-0.0', 'toy.source')
self.assertFalse("I'm a toy, and very proud of it" in ft.read_file(toy_source_path))

ft.apply_patch(toy_patch, self.test_prefix, use_git=True)
self.assertTrue("I'm a toy, and very proud of it" in ft.read_file(toy_source_path))

# construct patch that only adds a new file,
# this shouldn't break applying a patch with git even when no level is specified
new_file_patch = os.path.join(self.test_prefix, 'toy_new_file.patch')
new_file_patch_txt = '\n'.join([
"new file mode 100755",
"--- /dev/null\t1970-01-01 01:00:00.000000000 +0100",
"+++ b/toy-0.0/new_file.txt\t2020-08-18 12:31:57.000000000 +0200",
"@@ -0,0 +1 @@",
"+This is a new file\n",
])
ft.write_file(new_file_patch, new_file_patch_txt)
ft.apply_patch(new_file_patch, self.test_prefix, use_git=True)
new_file_path = os.path.join(self.test_prefix, 'toy-0.0', 'new_file.txt')
self.assertEqual(ft.read_file(new_file_path), "This is a new file\n")

# cleanup & restore
ft.remove_dir(path)
path = ft.extract_file(toy_tar_gz, self.test_prefix, change_into_dir=False)

self.assertFalse("I'm a toy, and very proud of it" in ft.read_file(toy_source_path))

# mock stderr to catch deprecation warning caused by setting 'use_git_am'
self.allow_deprecated_behaviour()
self.mock_stderr(True)
ft.apply_patch(toy_patch, self.test_prefix, use_git_am=True)
stderr = self.get_stderr()
self.mock_stderr(False)
self.assertTrue("I'm a toy, and very proud of it" in ft.read_file(toy_source_path))
self.assertTrue("'use_git_am' named argument in apply_patch function has been renamed to 'use_git'" in stderr)

def test_copy_file(self):
"""Test copy_file function."""
testdir = os.path.dirname(os.path.abspath(__file__))
Expand Down
8 changes: 4 additions & 4 deletions test/framework/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -4717,7 +4717,7 @@ def test_check_contrib_non_style(self):
'checksums = [',
" None, # toy-0.0.tar.gz",
" # toy-0.0_fix-silly-typo-in-printf-statement.patch",
" '45b5e3f9f495366830e1869bb2b8f4e7c28022739ce48d9f9ebb159b439823c5',",
" '81a3accc894592152f81814fbf133d39afad52885ab52c25018722c7bda92487',",
" '4196b56771140d8e2468fb77f0240bc48ddbf5dabafe0713d612df7fafb1e458', # toy-extra.txt",
']\n',
])
Expand Down Expand Up @@ -4921,7 +4921,7 @@ def test_inject_checksums(self):
stdout, stderr = self._run_mock_eb(args, raise_error=True, strip=True)

toy_source_sha256 = '44332000aa33b99ad1e00cbd1a7da769220d74647060a10e807b916d73ea27bc'
toy_patch_sha256 = '45b5e3f9f495366830e1869bb2b8f4e7c28022739ce48d9f9ebb159b439823c5'
toy_patch_sha256 = '81a3accc894592152f81814fbf133d39afad52885ab52c25018722c7bda92487'
bar_tar_gz_sha256 = 'f3676716b610545a4e8035087f5be0a0248adee0abb3930d3edb76d498ae91e7'
bar_patch = 'bar-0.0_fix-silly-typo-in-printf-statement.patch'
bar_patch_sha256 = '84db53592e882b5af077976257f9c7537ed971cb2059003fd4faa05d02cae0ab'
Expand Down Expand Up @@ -5056,7 +5056,7 @@ def test_inject_checksums(self):
"^== backup of easyconfig file saved to .*/test\.eb\.bak_[0-9]+_[0-9]+\.\.\.$",
"^== injecting md5 checksums for sources & patches in test\.eb\.\.\.$",
"^== \* toy-0.0\.tar\.gz: be662daa971a640e40be5c804d9d7d10$",
"^== \* toy-0\.0_fix-silly-typo-in-printf-statement\.patch: e6785e1a721fc8bf79892e3ef41557c0$",
"^== \* toy-0\.0_fix-silly-typo-in-printf-statement\.patch: a99f2a72cee1689a2f7e3ace0356efb1$",
"^== \* toy-extra\.txt: 3b0787b3bf36603ae1398c4a49097893$",
]
for pattern in patterns:
Expand All @@ -5074,7 +5074,7 @@ def test_inject_checksums(self):
ec = EasyConfigParser(test_ec).get_config_dict()
checksums = [
'be662daa971a640e40be5c804d9d7d10',
'e6785e1a721fc8bf79892e3ef41557c0',
'a99f2a72cee1689a2f7e3ace0356efb1',
'3b0787b3bf36603ae1398c4a49097893',
]
self.assertEqual(ec['checksums'], checksums)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
--- a/toy-0.0/toy.source.orig 2013-11-30 14:43:48.000000000 +0100
+++ b/toy-0.0/toy.source 2013-11-30 14:43:58.000000000 +0100
--- a/toy-0.0.orig/toy.source 2014-03-06 18:48:16.000000000 +0100
+++ b/toy-0.0/toy.source 2020-08-18 12:19:35.000000000 +0200
@@ -2,6 +2,6 @@

int main(int argc, char* *argv[]){
int main(int argc, char* argv[]){

- printf("I'm a toy, and proud of it.\n");
+ printf("I'm a toy, and very proud of it.\n");
Expand Down

0 comments on commit 694999d

Please sign in to comment.