@@ -1157,11 +1157,11 @@ def test_module_use_unuse(self):
1157
1157
1158
1158
self .assertFalse (test_dir1 in os .environ .get ('MODULEPATH' , '' ))
1159
1159
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 ))
1161
1161
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 ))
1163
1163
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 ))
1165
1165
1166
1166
# make sure the right test module is loaded
1167
1167
self .modtool .load (['test' ])
@@ -1193,8 +1193,9 @@ def test_module_use_unuse(self):
1193
1193
self .assertEqual (os .getenv ('TEST123' ), 'two' )
1194
1194
self .modtool .unload (['test' ])
1195
1195
1196
- # check whether prepend with priority actually works (only for Lmod)
1196
+ # Tests for Lmod only
1197
1197
if isinstance (self .modtool , Lmod ):
1198
+ # check whether prepend with priority actually works (priority is specific to Lmod)
1198
1199
self .modtool .use (test_dir1 , priority = 100 )
1199
1200
self .modtool .use (test_dir3 )
1200
1201
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):
1212
1213
self .assertEqual (os .getenv ('TEST123' ), 'three' )
1213
1214
self .modtool .unload (['test' ])
1214
1215
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
+
1215
1238
def test_module_use_bash (self ):
1216
1239
"""Test whether effect of 'module use' is preserved when a new bash session is started."""
1217
1240
# this test is here as check for a nasty bug in how the modules tool is deployed
0 commit comments