@@ -1157,11 +1157,11 @@ def test_module_use_unuse(self):
11571157
11581158 self .assertFalse (test_dir1 in os .environ .get ('MODULEPATH' , '' ))
11591159 self .modtool .use (test_dir1 )
1160- self .assertTrue (os .environ . get ( 'MODULEPATH' , '' ) .startswith ('%s:' % test_dir1 ))
1160+ self .assertTrue (os .environ [ 'MODULEPATH' ] .startswith ('%s:' % test_dir1 ))
11611161 self .modtool .use (test_dir2 )
1162- self .assertTrue (os .environ . get ( 'MODULEPATH' , '' ) .startswith ('%s:' % test_dir2 ))
1162+ self .assertTrue (os .environ [ 'MODULEPATH' ] .startswith ('%s:' % test_dir2 ))
11631163 self .modtool .use (test_dir3 )
1164- self .assertTrue (os .environ . get ( 'MODULEPATH' , '' ) .startswith ('%s:' % test_dir3 ))
1164+ self .assertTrue (os .environ [ 'MODULEPATH' ] .startswith ('%s:' % test_dir3 ))
11651165
11661166 # make sure the right test module is loaded
11671167 self .modtool .load (['test' ])
@@ -1193,8 +1193,9 @@ def test_module_use_unuse(self):
11931193 self .assertEqual (os .getenv ('TEST123' ), 'two' )
11941194 self .modtool .unload (['test' ])
11951195
1196- # check whether prepend with priority actually works (only for Lmod)
1196+ # Tests for Lmod only
11971197 if isinstance (self .modtool , Lmod ):
1198+ # check whether prepend with priority actually works (priority is specific to Lmod)
11981199 self .modtool .use (test_dir1 , priority = 100 )
11991200 self .modtool .use (test_dir3 )
12001201 self .assertTrue (os .environ ['MODULEPATH' ].startswith ('%s:%s:%s:' % (test_dir2 , test_dir1 , test_dir3 )))
@@ -1212,6 +1213,28 @@ def test_module_use_unuse(self):
12121213 self .assertEqual (os .getenv ('TEST123' ), 'three' )
12131214 self .modtool .unload (['test' ])
12141215
1216+ # Check load and unload for a single path when it is the only one
1217+ # Only for Lmod as we have some shortcuts for avoiding the module call there
1218+ old_module_path = os .environ ['MODULEPATH' ]
1219+ del os .environ ['MODULEPATH' ]
1220+ self .modtool .use (test_dir1 )
1221+ self .assertEqual (os .environ ['MODULEPATH' ], test_dir1 )
1222+ self .modtool .unuse (test_dir1 )
1223+ self .assertFalse ('MODULEPATH' in os .environ )
1224+ os .environ ['MODULEPATH' ] = old_module_path # Restore
1225+
1226+ # Using an empty path still works (technically) (Lmod only, ignored by Tcl)
1227+ old_module_path = os .environ ['MODULEPATH' ]
1228+ self .modtool .use ('' )
1229+ self .assertEqual (os .environ ['MODULEPATH' ], ':' + old_module_path )
1230+ self .modtool .unuse ('' )
1231+ self .assertEqual (os .environ ['MODULEPATH' ], old_module_path )
1232+ # Even works when the whole path is empty
1233+ os .environ ['MODULEPATH' ] = ''
1234+ self .modtool .unuse ('' )
1235+ self .assertFalse ('MODULEPATH' in os .environ )
1236+ os .environ ['MODULEPATH' ] = old_module_path # Restore
1237+
12151238 def test_module_use_bash (self ):
12161239 """Test whether effect of 'module use' is preserved when a new bash session is started."""
12171240 # this test is here as check for a nasty bug in how the modules tool is deployed
0 commit comments