@@ -1142,24 +1142,75 @@ def test_module_caches(self):
11421142 self .assertEqual (mod .MODULE_AVAIL_CACHE , {})
11431143 self .assertEqual (mod .MODULE_SHOW_CACHE , {})
11441144
1145- def test_module_use (self ):
1146- """Test 'module use'."""
1145+ def test_module_use_unuse (self ):
1146+ """Test 'module use' and 'module unuse' ."""
11471147 test_dir1 = os .path .join (self .test_prefix , 'one' )
11481148 test_dir2 = os .path .join (self .test_prefix , 'two' )
11491149 test_dir3 = os .path .join (self .test_prefix , 'three' )
11501150
1151+ for subdir in ('one' , 'two' , 'three' ):
1152+ modtxt = '\n ' .join ([
1153+ '#%Module' ,
1154+ "setenv TEST123 %s" % subdir ,
1155+ ])
1156+ write_file (os .path .join (self .test_prefix , subdir , 'test' ), modtxt )
1157+
11511158 self .assertFalse (test_dir1 in os .environ .get ('MODULEPATH' , '' ))
11521159 self .modtool .use (test_dir1 )
11531160 self .assertTrue (os .environ .get ('MODULEPATH' , '' ).startswith ('%s:' % test_dir1 ))
1161+ self .modtool .use (test_dir2 )
1162+ self .assertTrue (os .environ .get ('MODULEPATH' , '' ).startswith ('%s:' % test_dir2 ))
1163+ self .modtool .use (test_dir3 )
1164+ self .assertTrue (os .environ .get ('MODULEPATH' , '' ).startswith ('%s:' % test_dir3 ))
1165+
1166+ # make sure the right test module is loaded
1167+ self .modtool .load (['test' ])
1168+ self .assertEqual (os .getenv ('TEST123' ), 'three' )
1169+ self .modtool .unload (['test' ])
1170+
1171+ self .modtool .unuse (test_dir3 )
1172+ self .assertFalse (test_dir3 in os .environ .get ('MODULEPATH' , '' ))
1173+
1174+ self .modtool .load (['test' ])
1175+ self .assertEqual (os .getenv ('TEST123' ), 'two' )
1176+ self .modtool .unload (['test' ])
1177+
1178+ self .modtool .unuse (test_dir2 )
1179+ self .assertFalse (test_dir2 in os .environ .get ('MODULEPATH' , '' ))
1180+
1181+ self .modtool .load (['test' ])
1182+ self .assertEqual (os .getenv ('TEST123' ), 'one' )
1183+ self .modtool .unload (['test' ])
1184+
1185+ self .modtool .unuse (test_dir1 )
1186+ self .assertFalse (test_dir1 in os .environ .get ('MODULEPATH' , '' ))
11541187
11551188 # also test use with high priority
11561189 self .modtool .use (test_dir2 , priority = 10000 )
11571190 self .assertTrue (os .environ ['MODULEPATH' ].startswith ('%s:' % test_dir2 ))
11581191
1192+ self .modtool .load (['test' ])
1193+ self .assertEqual (os .getenv ('TEST123' ), 'two' )
1194+ self .modtool .unload (['test' ])
1195+
11591196 # check whether prepend with priority actually works (only for Lmod)
11601197 if isinstance (self .modtool , Lmod ):
1198+ self .modtool .use (test_dir1 , priority = 100 )
11611199 self .modtool .use (test_dir3 )
1162- self .assertTrue (os .environ ['MODULEPATH' ].startswith ('%s:%s:' % (test_dir2 , test_dir3 )))
1200+ self .assertTrue (os .environ ['MODULEPATH' ].startswith ('%s:%s:%s:' % (test_dir2 , test_dir1 , test_dir3 )))
1201+ self .modtool .load (['test' ])
1202+ self .assertEqual (os .getenv ('TEST123' ), 'two' )
1203+ self .modtool .unload (['test' ])
1204+
1205+ self .modtool .unuse (test_dir2 )
1206+ self .modtool .load (['test' ])
1207+ self .assertEqual (os .getenv ('TEST123' ), 'one' )
1208+ self .modtool .unload (['test' ])
1209+
1210+ self .modtool .unuse (test_dir1 )
1211+ self .modtool .load (['test' ])
1212+ self .assertEqual (os .getenv ('TEST123' ), 'three' )
1213+ self .modtool .unload (['test' ])
11631214
11641215 def test_module_use_bash (self ):
11651216 """Test whether effect of 'module use' is preserved when a new bash session is started."""
0 commit comments