Skip to content

Commit

Permalink
trivial code style changes in EasyConfig.validate + tweaks in tests f…
Browse files Browse the repository at this point in the history
…or skipsteps and --stop
  • Loading branch information
boegel committed Dec 4, 2024
1 parent 4c3a483 commit f41ef28
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
11 changes: 6 additions & 5 deletions easybuild/framework/easyconfig/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
from easybuild.tools.filetools import convert_name, copy_file, create_index, decode_class_name, encode_class_name
from easybuild.tools.filetools import find_backup_name_candidate, find_easyconfigs, load_index
from easybuild.tools.filetools import read_file, write_file
from easybuild.tools.hooks import STEP_NAMES, PARSE, load_hooks, run_hook
from easybuild.tools.hooks import PARSE, STEP_NAMES, load_hooks, run_hook
from easybuild.tools.module_naming_scheme.mns import DEVEL_MODULE_SUFFIX
from easybuild.tools.module_naming_scheme.utilities import avail_module_naming_schemes, det_full_ec_version
from easybuild.tools.module_naming_scheme.utilities import det_hidden_modname, is_valid_module_name
Expand Down Expand Up @@ -866,13 +866,14 @@ def validate(self, check_osdeps=True):
type(skipsteps), skipsteps)
unknown_step_names = [step for step in skipsteps if step not in STEP_NAMES]
if unknown_step_names:
error_lines = ["Found one or more unknown step names in skipsteps:"]
error_lines = ["Found one or more unknown step names in 'skipsteps' easyconfig parameter:"]
for step in unknown_step_names:
error_lines.append("* %s" % step)
# try to find close match, may be just a typo in the hook name
error_line = "* %s" % step
# try to find close match, may be just a typo in the step name
close_matches = difflib.get_close_matches(step, STEP_NAMES, 2, 0.8)
if close_matches:
error_lines[-1] += " (did you mean %s?)" % ', or '.join("'%s'" % s for s in close_matches)
error_line += " (did you mean %s?)" % ', or '.join("'%s'" % s for s in close_matches)
error_lines.append(error_line)
raise EasyBuildError('\n'.join(error_lines))

self.log.info("Checking build option lists")
Expand Down
18 changes: 14 additions & 4 deletions test/framework/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,16 +404,24 @@ def test_skipsteps(self):
# Verify a wrong step name is caught
test_ec_txt += "\nskipsteps = ['wrong-step-name']\n"
write_file(test_ec, test_ec_txt)
self.assertErrorRegex(EasyBuildError, 'wrong-step-name', self.eb_main, args, do_build=True, raise_error=True)
test_ec_txt += "\nskipsteps = ['source']\n" # Especially the old name -> Replaced by extract
error_pattern = "Found one or more unknown step names in 'skipsteps' easyconfig parameter:\n"
error_pattern += r"\* wrong-step-name"
self.assertErrorRegex(EasyBuildError, error_pattern, self.eb_main, args, do_build=True, raise_error=True)
# 'source' step was renamed to 'extract' in EasyBuild 5.0,
# see https://github.com/easybuilders/easybuild-framework/pull/4629
test_ec_txt += "\nskipsteps = ['source']\n"
write_file(test_ec, test_ec_txt)
self.assertErrorRegex(EasyBuildError, 'source', self.eb_main, args, do_build=True, raise_error=True)
error_pattern = error_pattern.replace('wrong-step-name', 'source')
self.assertErrorRegex(EasyBuildError, error_pattern, self.eb_main, args, do_build=True, raise_error=True)

# check use of skipsteps to skip sanity check
test_ec_txt += "\nskipsteps = ['sanitycheck']\n"
write_file(test_ec, test_ec_txt)
self.mocked_main(args, do_build=True, raise_error=True)

toy_mod_glob = os.path.join(self.test_installpath, 'modules', 'all', 'toy', '*')
self.assertEqual(len(glob.glob(toy_mod_glob)), 1)

def test_skip_test_step(self):
"""Test skipping testing the build (--skip-test-step)."""

Expand Down Expand Up @@ -5509,9 +5517,11 @@ def test_stop(self):
regex = re.compile(r"COMPLETED: Installation STOPPED successfully \(took .* secs?\)", re.M)
self.assertTrue(regex.search(txt), "Pattern '%s' found in: %s" % (regex.pattern, txt))

# 'source' step was renamed to 'extract' in EasyBuild 5.0,
# see https://github.com/easybuilders/easybuild-framework/pull/4629
args = ['toy-0.0.eb', '--force', '--stop=source']
_, stderr = self._run_mock_eb(args, do_build=True, raise_error=True, testing=False, strip=True)
self.assertIn("option --stop: invalid choice", stderr)
self.assertIn("option --stop: invalid choice: 'source' (choose from", stderr)

def test_fetch(self):
options = EasyBuildOptions(go_args=['--fetch'])
Expand Down

0 comments on commit f41ef28

Please sign in to comment.