2929@author: Kenneth Hoste (Ghent University)
3030@author: Damian Alvarez (Forschungszentrum Juelich GmbH)
3131"""
32- import copy
3332import glob
3433import grp
3534import os
5453from easybuild .main import main_with_hooks
5554from easybuild .tools .build_log import EasyBuildError
5655from easybuild .tools .config import get_module_syntax , get_repositorypath
57- from easybuild .tools .environment import modify_env , setvar
56+ from easybuild .tools .environment import setvar
5857from easybuild .tools .filetools import adjust_permissions , change_dir , copy_file , mkdir , move_file
5958from easybuild .tools .filetools import read_file , remove_dir , remove_file , which , write_file
6059from easybuild .tools .module_generator import ModuleGeneratorTcl
@@ -1759,18 +1758,14 @@ def test_external_dependencies(self):
17591758 installed_test_modules = os .path .join (self .test_installpath , 'modules' , 'all' )
17601759 self .reset_modulepath ([modulepath , installed_test_modules ])
17611760
1762- start_env = copy .deepcopy (os .environ )
1763-
17641761 with self .mocked_stdout_stderr ():
17651762 self ._test_toy_build (ec_file = toy_ec , versionsuffix = '-external-deps' , verbose = True , raise_error = True )
17661763
1767- self .modtool .load (['toy/0.0-external-deps' ])
1768- # note build dependency is not loaded
1769- mods = ['intel/2018a' , 'GCC/6.4.0-2.28' , 'foobar/1.2.3' , 'toy/0.0-external-deps' ]
1770- self .assertEqual ([x ['mod_name' ] for x in self .modtool .list ()], mods )
1771-
1772- # restore original environment (to undo 'module load' done above)
1773- modify_env (os .environ , start_env , verbose = False )
1764+ with self .saved_env ():
1765+ self .modtool .load (['toy/0.0-external-deps' ])
1766+ # note build dependency is not loaded
1767+ mods = ['intel/2018a' , 'GCC/6.4.0-2.28' , 'foobar/1.2.3' , 'toy/0.0-external-deps' ]
1768+ self .assertEqual ([x ['mod_name' ] for x in self .modtool .list ()], mods )
17741769
17751770 # check behaviour when a non-existing external (build) dependency is included
17761771 extraectxt = "\n builddependencies = [('nosuchbuilddep/0.0.0', EXTERNAL_MODULE)]"
@@ -3147,10 +3142,6 @@ def test_toy_filter_rpath_sanity_libs(self):
31473142
31483143 def test_toy_cuda_sanity_check (self ):
31493144 """Test the CUDA sanity check"""
3150- # We need to mock a cuobjdump executable and prepend in on the PATH
3151- # First, make sure we can restore environment at the end of this test
3152- start_env = copy .deepcopy (os .environ )
3153-
31543145 # Define the toy_ec file we want to use
31553146 topdir = os .path .dirname (os .path .abspath (__file__ ))
31563147 toy_ec = os .path .join (topdir , 'easyconfigs' , 'test_ecs' , 't' , 'toy' , 'toy-0.0.eb' )
@@ -3540,9 +3531,6 @@ def assert_cuda_report(missing_cc, additional_cc, missing_ptx, log, stdout=None,
35403531 self .assertTrue (expected_result .search (outtxt ), msg )
35413532 assert_cuda_report (missing_cc = 0 , additional_cc = 0 , missing_ptx = 0 , log = outtxt , stdout = stdout , num_checked = 0 )
35423533
3543- # Restore original environment
3544- modify_env (os .environ , start_env , verbose = False )
3545-
35463534 def test_toy_modaltsoftname (self ):
35473535 """Build two dependent toys as in test_toy_toy but using modaltsoftname"""
35483536 topdir = os .path .dirname (os .path .abspath (__file__ ))
@@ -3953,7 +3941,8 @@ def check_toy_load(depends_on=False):
39533941 # just undo
39543942 self .modtool .unload (['toy/0.0' , 'GCC/4.6.3' ])
39553943
3956- check_toy_load ()
3944+ with self .saved_env ():
3945+ check_toy_load ()
39573946
39583947 # this behaviour can be disabled via "multi_dep_load_defaults = False"
39593948 write_file (test_ec , test_ec_txt + "\n multi_deps_load_default = False" )
@@ -3965,8 +3954,9 @@ def check_toy_load(depends_on=False):
39653954
39663955 self .assertNotIn (expected , toy_mod_txt )
39673956
3968- self .modtool .load (['toy/0.0' ])
3969- loaded_mod_names = [x ['mod_name' ] for x in self .modtool .list ()]
3957+ with self .saved_env ():
3958+ self .modtool .load (['toy/0.0' ])
3959+ loaded_mod_names = [x ['mod_name' ] for x in self .modtool .list ()]
39703960 self .assertIn ('toy/0.0' , loaded_mod_names )
39713961 self .assertNotIn ('GCC/4.6.3' , loaded_mod_names )
39723962 self .assertNotIn ('GCC/7.3.0-2.30' , loaded_mod_names )
@@ -3989,10 +3979,6 @@ def check_toy_load(depends_on=False):
39893979 error_msg_whatis = "Pattern '%s' should be found in: %s" % (expected_whatis_no_default , toy_mod_txt )
39903980 self .assertIn (expected_whatis_no_default , toy_mod_txt , error_msg_whatis )
39913981
3992- # restore original environment to continue testing with a clean slate
3993- modify_env (os .environ , self .orig_environ , verbose = False )
3994- self .modtool .use (test_mod_path )
3995-
39963982 # disable showing of progress bars (again), doesn't make sense when running tests
39973983 os .environ ['EASYBUILD_DISABLE_SHOW_PROGRESS_BAR' ] = '1'
39983984
0 commit comments