@@ -296,7 +296,6 @@ def test_force(self):
296296
297297 def test_skip (self ):
298298 """Test skipping installation of module (--skip, -k)."""
299-
300299 # use toy-0.0.eb easyconfig file that comes with the tests
301300 topdir = os .path .abspath (os .path .dirname (__file__ ))
302301 toy_ec = os .path .join (topdir , 'easyconfigs' , 'test_ecs' , 't' , 'toy' , 'toy-0.0.eb' )
@@ -335,13 +334,11 @@ def test_skip(self):
335334 with self .mocked_stdout_stderr ():
336335 outtxt = self .eb_main (args , do_build = True , verbose = True )
337336
338- found_msg = "Module toy/1.2.3.4.5.6.7.8.9 found."
339- found = re .search (found_msg , outtxt )
340- self .assertTrue (not found , "Module found message not there with --skip for non-existing modules: %s" % outtxt )
337+ self .assertNotIn ("Module toy/1.2.3.4.5.6.7.8.9 found." , outtxt ,
338+ "Module found message should not be there with --skip for non-existing modules" )
341339
342- not_found_msg = "No module toy/1.2.3.4.5.6.7.8.9 found. Not skipping anything."
343- not_found = re .search (not_found_msg , outtxt )
344- self .assertTrue (not_found , "Module not found message there with --skip for non-existing modules: %s" % outtxt )
340+ self .assertIn ("No module toy/1.2.3.4.5.6.7.8.9 found. Not skipping anything." , outtxt ,
341+ "Module not found message should be there with --skip for non-existing modules" )
345342
346343 toy_mod_glob = os .path .join (self .test_installpath , 'modules' , 'all' , 'toy' , '*' )
347344 for toy_mod in glob .glob (toy_mod_glob ):
@@ -360,29 +357,26 @@ def test_skip(self):
360357 '--force' ,
361358 ]
362359 error_pattern = "Sanity check failed: no file found at 'bin/nosuchfile'"
363- with self .mocked_stdout_stderr ():
364- self .assertErrorRegex (EasyBuildError , error_pattern , self .eb_main , args , do_build = True , raise_error = True )
360+ self .assertErrorRegex (EasyBuildError , error_pattern , self .mocked_main , args , do_build = True , raise_error = True )
365361
366- # check use of skipsteps to skip sanity check
367- test_ec_txt += "\n skipsteps = ['sanitycheck']\n "
368- write_file (test_ec , test_ec_txt )
369- with self .mocked_stdout_stderr ():
370- self .eb_main (args , do_build = True , raise_error = True )
362+ def test_module_only_param (self ):
363+ """check use of module_only parameter"""
364+ topdir = os .path .abspath (os .path .dirname (__file__ ))
365+ toy_ec = os .path .join (topdir , 'easyconfigs' , 'test_ecs' , 't' , 'toy' , 'toy-0.0.eb' )
371366
372- self .assertEqual (len (glob .glob (toy_mod_glob )), 1 )
367+ test_ec = os .path .join (self .test_prefix , 'test.eb' )
368+ test_ec_txt = read_file (toy_ec )
369+ test_ec_txt += "\n module_only=True\n "
370+ test_ec_txt += "\n skipsteps = ['sanitycheck']\n " # Software does not exist, so sanity check would fail
371+ write_file (test_ec , test_ec_txt )
373372
374- # check use of module_only parameter
375- remove_dir (os .path .join (self .test_installpath , 'modules' , 'all' , 'toy' ))
376- remove_dir (os .path .join (self .test_installpath , 'software' , 'toy' , '0.0' ))
377373 args = [
378374 test_ec ,
379375 '--rebuild' ,
380376 ]
381- test_ec_txt += "\n module_only = True\n "
382- write_file (test_ec , test_ec_txt )
383- with self .mocked_stdout_stderr ():
384- self .eb_main (args , do_build = True , raise_error = True )
377+ self .mocked_main (args , do_build = True , raise_error = True )
385378
379+ toy_mod_glob = os .path .join (self .test_installpath , 'modules' , 'all' , 'toy' , '*' )
386380 self .assertEqual (len (glob .glob (toy_mod_glob )), 1 )
387381
388382 # check that no software was installed
@@ -391,6 +385,38 @@ def test_skip(self):
391385 easybuild_dir = os .path .join (installdir , 'easybuild' )
392386 self .assertEqual (installdir_glob , [easybuild_dir ])
393387
388+ def test_skipsteps (self ):
389+ """Test skipping of steps using skipsteps."""
390+ # use toy-0.0.eb easyconfig file that comes with the tests
391+ topdir = os .path .abspath (os .path .dirname (__file__ ))
392+ toy_ec = os .path .join (topdir , 'easyconfigs' , 'test_ecs' , 't' , 'toy' , 'toy-0.0.eb' )
393+
394+ # make sure that sanity check is *NOT* skipped
395+ test_ec = os .path .join (self .test_prefix , 'test.eb' )
396+ test_ec_txt = read_file (toy_ec )
397+ regex = re .compile (r"sanity_check_paths = \{(.|\n)*\}" , re .M )
398+ test_ec_txt = regex .sub ("sanity_check_paths = {'files': ['bin/nosuchfile'], 'dirs': []}" , test_ec_txt )
399+ write_file (test_ec , test_ec_txt )
400+ args = [
401+ test_ec ,
402+ '--rebuild' ,
403+ ]
404+ error_pattern = "Sanity check failed: no file found at 'bin/nosuchfile'"
405+ self .assertErrorRegex (EasyBuildError , error_pattern , self .mocked_main , args , do_build = True , raise_error = True )
406+
407+ # Verify a wrong step name is caught
408+ test_ec_txt += "\n skipsteps = ['wrong-step-name']\n "
409+ write_file (test_ec , test_ec_txt )
410+ self .assertErrorRegex (EasyBuildError , 'wrong-step-name' , self .eb_main , args , do_build = True , raise_error = True )
411+ test_ec_txt += "\n skipsteps = ['source']\n " # Especially the old name -> Replaced by extract
412+ write_file (test_ec , test_ec_txt )
413+ self .assertErrorRegex (EasyBuildError , 'source' , self .eb_main , args , do_build = True , raise_error = True )
414+
415+ # check use of skipsteps to skip sanity check
416+ test_ec_txt += "\n skipsteps = ['sanitycheck']\n "
417+ write_file (test_ec , test_ec_txt )
418+ self .mocked_main (args , do_build = True , raise_error = True )
419+
394420 def test_skip_test_step (self ):
395421 """Test skipping testing the build (--skip-test-step)."""
396422
@@ -717,8 +743,8 @@ def test_avail_hooks(self):
717743 " post_fetch_hook" ,
718744 " pre_ready_hook" ,
719745 " post_ready_hook" ,
720- " pre_source_hook " ,
721- " post_source_hook " ,
746+ " pre_extract_hook " ,
747+ " post_extract_hook " ,
722748 " pre_patch_hook" ,
723749 " post_patch_hook" ,
724750 " pre_prepare_hook" ,
@@ -1236,12 +1262,7 @@ def mocked_main(self, args, **kwargs):
12361262 if not kwargs :
12371263 kwargs = {'raise_error' : True }
12381264
1239- self .mock_stderr (True )
1240- self .mock_stdout (True )
1241- self .eb_main (args , ** kwargs )
1242- stderr , stdout = self .get_stderr (), self .get_stdout ()
1243- self .mock_stderr (False )
1244- self .mock_stdout (False )
1265+ stdout , stderr = self ._run_mock_eb (args , ** kwargs )
12451266 self .assertEqual (stderr , '' )
12461267 return stdout .strip ()
12471268
@@ -4422,14 +4443,14 @@ def _assert_regexs(self, regexs, txt, assert_true=True):
44224443 self .assertFalse (regex .search (txt ), "Pattern '%s' NOT found in: %s" % (regex .pattern , txt ))
44234444
44244445 def _run_mock_eb (self , args , strip = False , ** kwargs ):
4425- """Helper function to mock easybuild runs"""
4426- self . mock_stdout ( True )
4427- self . mock_stderr ( True )
4428- self . eb_main ( args , ** kwargs )
4429- stdout_txt = self .get_stdout ()
4430- stderr_txt = self .get_stderr ( )
4431- self . mock_stdout ( False )
4432- self . mock_stderr ( False )
4446+ """Helper function to mock easybuild runs
4447+
4448+ Return (stdout, stderr) optionally stripped of whitespace at start/end
4449+ """
4450+ with self .mocked_stdout_stderr () as ( stdout , stderr ):
4451+ self .eb_main ( args , ** kwargs )
4452+ stdout_txt = stdout . getvalue ( )
4453+ stderr_txt = stderr . getvalue ( )
44334454 if strip :
44344455 stdout_txt = stdout_txt .strip ()
44354456 stderr_txt = stderr_txt .strip ()
@@ -5437,6 +5458,10 @@ def test_stop(self):
54375458 regex = re .compile (r"COMPLETED: Installation STOPPED successfully \(took .* secs?\)" , re .M )
54385459 self .assertTrue (regex .search (txt ), "Pattern '%s' found in: %s" % (regex .pattern , txt ))
54395460
5461+ args = ['toy-0.0.eb' , '--force' , '--stop=source' ]
5462+ _ , stderr = self ._run_mock_eb (args , do_build = True , raise_error = True , testing = False , strip = True )
5463+ self .assertIn ("option --stop: invalid choice" , stderr )
5464+
54405465 def test_fetch (self ):
54415466 options = EasyBuildOptions (go_args = ['--fetch' ])
54425467
@@ -6446,7 +6471,7 @@ def test_enforce_checksums(self):
64466471
64476472 args = [
64486473 test_ec ,
6449- '--stop=source ' ,
6474+ '--stop=fetch ' ,
64506475 '--enforce-checksums' ,
64516476 ]
64526477
0 commit comments