Skip to content

Commit

Permalink
Merge pull request #4247 from branfosj/patch
Browse files Browse the repository at this point in the history
enforce correct extentions for patch files
  • Loading branch information
boegel committed Apr 15, 2023
2 parents b963350 + 01d0cea commit 03155f2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
5 changes: 2 additions & 3 deletions easybuild/tools/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1528,9 +1528,8 @@ def create_patch_info(patch_spec):
def validate_patch_spec(patch_spec):
allowed_patch_exts = ['.patch' + x for x in ('',) + ZIPPED_PATCH_EXTS]
if not any(patch_spec.endswith(x) for x in allowed_patch_exts):
msg = "Use of patch file with filename that doesn't end with correct extension: %s " % patch_spec
msg += "(should be any of: %s)" % (', '.join(allowed_patch_exts))
_log.deprecated(msg, '5.0')
raise EasyBuildError("Wrong patch spec (%s), extension type should be any of %s." %
(patch_spec, ', '.join(allowed_patch_exts)))


def apply_patch(patch_file, dest, fn=None, copy=False, level=None, use_git=False):
Expand Down
16 changes: 3 additions & 13 deletions test/framework/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1646,25 +1646,15 @@ def test_create_patch_info(self):
self.assertEqual(ft.create_patch_info({'name': 'foo.txt', 'copy': 'subdir', 'alt_location': 'alt'}),
{'name': 'foo.txt', 'copy': 'subdir', 'alt_location': 'alt'})

self.allow_deprecated_behaviour()
self.mock_stderr(True)
self.assertEqual(ft.create_patch_info('foo.txt'), {'name': 'foo.txt'})
stderr = self.get_stderr()
self.mock_stderr(False)
self.disallow_deprecated_behaviour()
expected_warning = "Use of patch file with filename that doesn't end with correct extension: foo.txt "
expected_warning += "(should be any of: .patch, .patch.bz2, .patch.gz, .patch.xz)"
fail_msg = "Warning '%s' should appear in stderr output: %s" % (expected_warning, stderr)
self.assertIn(expected_warning, stderr, fail_msg)

# deprecation warning is treated as an error in context of unit test suite
expected_error = expected_warning.replace('(', '\\(').replace(')', '\\)')
expected_error = r"Wrong patch spec \(foo.txt\), extension type should be any of .patch, .patch.bz2, "
expected_error += ".patch.gz, .patch.xz."
self.assertErrorRegex(EasyBuildError, expected_error, ft.create_patch_info, 'foo.txt')

# faulty input
error_msg = "Wrong patch spec"
self.assertErrorRegex(EasyBuildError, error_msg, ft.create_patch_info, None)
self.assertErrorRegex(EasyBuildError, error_msg, ft.create_patch_info, {'copy': 'subdir'})
self.assertErrorRegex(EasyBuildError, error_msg, ft.create_patch_info, {'name': 'foo.txt'})
self.assertErrorRegex(EasyBuildError, error_msg, ft.create_patch_info, {'name': 'foo.txt', 'random': 'key'})
self.assertErrorRegex(EasyBuildError, error_msg, ft.create_patch_info,
{'name': 'foo.txt', 'copy': 'subdir', 'sourcepath': 'subdir'})
Expand Down

0 comments on commit 03155f2

Please sign in to comment.