@@ -2673,6 +2673,99 @@ def test_toy_build_enhanced_sanity_check(self):
26732673
26742674 del sys .modules ['easybuild.easyblocks.toy' ]
26752675
2676+ def test_toy_build_enhanced_sanity_check_templated_multi_dep (self ):
2677+ """Test enhancing of sanity check by easyblocks with templates and in the presence of multi_deps."""
2678+
2679+ # if toy easyblock was imported, get rid of corresponding entry in sys.modules,
2680+ # to avoid that it messes up the use of --include-easyblocks=toy.py below...
2681+ if 'easybuild.easyblocks.toy' in sys .modules :
2682+ del sys .modules ['easybuild.easyblocks.toy' ]
2683+
2684+ test_dir = os .path .join (os .path .abspath (os .path .dirname (__file__ )))
2685+ toy_ec = os .path .join (test_dir , 'easyconfigs' , 'test_ecs' , 't' , 'toy' , 'toy-0.0.eb' )
2686+ toy_ec_txt = read_file (toy_ec )
2687+
2688+ test_ec = os .path .join (self .test_prefix , 'test.eb' )
2689+
2690+ # get rid of custom sanity check paths in test easyconfig
2691+ regex = re .compile (r'^sanity_check_paths\s*=\s*{[^}]+}' , re .M )
2692+ test_ec_txt = regex .sub ('' , toy_ec_txt )
2693+ self .assertNotIn ('sanity_check_' , test_ec_txt )
2694+
2695+ test_ec_txt += "\n multi_deps = {'Python': ['3.7.2', '2.7.15']}"
2696+ write_file (test_ec , test_ec_txt )
2697+
2698+ # create custom easyblock for toy that has a custom sanity_check_step
2699+ toy_easyblock = os .path .join (test_dir , 'sandbox' , 'easybuild' , 'easyblocks' , 't' , 'toy.py' )
2700+
2701+ toy_easyblock_txt = read_file (toy_easyblock )
2702+
2703+ toy_custom_sanity_check_step = textwrap .dedent ("""
2704+ # Add to class to indent
2705+ def sanity_check_step(self):
2706+ paths = {
2707+ 'files': ['bin/python%(pyshortver)s'],
2708+ 'dirs': ['lib/py-%(pyshortver)s'],
2709+ }
2710+ cmds = ['python%(pyshortver)s']
2711+ return super(EB_toy, self).sanity_check_step(custom_paths=paths, custom_commands=cmds)
2712+ """ )
2713+ test_toy_easyblock = os .path .join (self .test_prefix , 'toy.py' )
2714+ write_file (test_toy_easyblock , toy_easyblock_txt + toy_custom_sanity_check_step )
2715+
2716+ eb_args = [
2717+ '--extended-dry-run' ,
2718+ '--include-easyblocks=%s' % test_toy_easyblock ,
2719+ ]
2720+
2721+ # by default, sanity check commands & paths specified by easyblock are used
2722+ with self .mocked_stdout_stderr ():
2723+ self ._test_toy_build (ec_file = test_ec , extra_args = eb_args , verify = False , testing = False , raise_error = True )
2724+ stdout = self .get_stdout ()
2725+ # Cut output to start of the toy-ec, after the Python installations
2726+ stdout = stdout [stdout .index (test_ec ):]
2727+
2728+ pattern_template = textwrap .dedent (r"""
2729+ Sanity check paths - file.*
2730+ \s*\* bin/python{pyshortver}
2731+ Sanity check paths - \(non-empty\) directory.*
2732+ \s*\* lib/py-{pyshortver}
2733+ Sanity check commands
2734+ \s*\* python{pyshortver}
2735+ """ )
2736+ for pyshortver in ('2.7' , '3.7' ):
2737+ regex = re .compile (pattern_template .format (pyshortver = pyshortver ), re .M )
2738+ self .assertTrue (regex .search (stdout ), "Pattern '%s' should be found in: %s" % (regex .pattern , stdout ))
2739+
2740+ # Enhance sanity check by extra paths to check for, the ones from the easyblock should be kept
2741+ test_ec_txt += textwrap .dedent ("""
2742+ enhance_sanity_check = True
2743+ sanity_check_paths = {
2744+ 'files': ['bin/pip%(pyshortver)s'],
2745+ 'dirs': ['bin'],
2746+ }
2747+ """ )
2748+ write_file (test_ec , test_ec_txt )
2749+ with self .mocked_stdout_stderr ():
2750+ self ._test_toy_build (ec_file = test_ec , extra_args = eb_args , verify = False , testing = False , raise_error = True )
2751+ stdout = self .get_stdout ()
2752+ # Cut output to start of the toy-ec, after the Python installations
2753+ stdout = stdout [stdout .index (test_ec ):]
2754+
2755+ pattern_template = textwrap .dedent (r"""
2756+ Sanity check paths - file.*
2757+ \s*\* bin/pip{pyshortver}
2758+ \s*\* bin/python{pyshortver}
2759+ Sanity check paths - \(non-empty\) directory.*
2760+ \s*\* bin
2761+ \s*\* lib/py-{pyshortver}
2762+ Sanity check commands
2763+ \s*\* python{pyshortver}
2764+ """ )
2765+ for pyshortver in ('2.7' , '3.7' ):
2766+ regex = re .compile (pattern_template .format (pyshortver = pyshortver ), re .M )
2767+ self .assertTrue (regex .search (stdout ), "Pattern '%s' should be found in: %s" % (regex .pattern , stdout ))
2768+
26762769 def test_toy_dumped_easyconfig (self ):
26772770 """ Test dumping of file in eb_filerepo in both .eb format """
26782771 filename = 'toy-0.0'
0 commit comments