Skip to content

Commit

Permalink
improve error message for unknown file extensions, add comment to cla…
Browse files Browse the repository at this point in the history
…rify behaviour of find_extension in extract_cmd, extend test_extract_cmd to check case of unknown extension
  • Loading branch information
boegel committed Dec 4, 2021
1 parent d008310 commit 1d4e454
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion easybuild/tools/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ def find_extension(filename):
if res:
ext = res.group('ext')
else:
raise EasyBuildError('Unknown file type for file %s', filename)
raise EasyBuildError("%s has unknown file extension", filename)

return ext

Expand All @@ -1382,7 +1382,9 @@ def extract_cmd(filepath, overwrite=False):
ext = find_extension(filename)
target = filename[:-len(ext)]

# find_extension will either return an extension listed in EXTRACT_CMDS, or raise an error
cmd_tmpl = EXTRACT_CMDS[ext.lower()]

if overwrite:
if 'unzip -qq' in cmd_tmpl:
cmd_tmpl = cmd_tmpl.replace('unzip -qq', 'unzip -qq -o')
Expand Down
3 changes: 3 additions & 0 deletions test/framework/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ def test_extract_cmd(self):

self.assertEqual("unzip -qq -o test.zip", ft.extract_cmd('test.zip', True))

error_pattern = "test.foo has unknown file extension"
self.assertErrorRegex(EasyBuildError, error_pattern, ft.extract_cmd, 'test.foo')

def test_find_extension(self):
"""Test find_extension function."""
tests = [
Expand Down
3 changes: 0 additions & 3 deletions test/framework/toy_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1368,9 +1368,6 @@ def test_toy_extension_extract_cmd(self):
toy_ec = os.path.join(test_ecs, 't', 'toy', 'toy-0.0.eb')
toy_ec_txt = read_file(toy_ec)

# create file that we'll copy via 'patches'
write_file(os.path.join(self.test_prefix, 'test.txt'), 'test123')

test_ec = os.path.join(self.test_prefix, 'test.eb')
test_ec_txt = '\n'.join([
toy_ec_txt,
Expand Down

0 comments on commit 1d4e454

Please sign in to comment.