Skip to content

Commit a45763f

Browse files
committed
also load module when testing use/unuse
1 parent 5293218 commit a45763f

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/framework/modules.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,29 +1148,69 @@ def test_module_use_unuse(self):
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))
11541161
self.modtool.use(test_dir2)
11551162
self.assertTrue(os.environ.get('MODULEPATH', '').startswith('%s:' % test_dir2))
11561163
self.modtool.use(test_dir3)
11571164
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+
11581171
self.modtool.unuse(test_dir3)
11591172
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+
11601178
self.modtool.unuse(test_dir2)
11611179
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+
11621185
self.modtool.unuse(test_dir1)
11631186
self.assertFalse(test_dir1 in os.environ.get('MODULEPATH', ''))
11641187

11651188
# also test use with high priority
11661189
self.modtool.use(test_dir2, priority=10000)
11671190
self.assertTrue(os.environ['MODULEPATH'].startswith('%s:' % test_dir2))
11681191

1192+
self.modtool.load(['test'])
1193+
self.assertEqual(os.getenv('TEST123'), 'two')
1194+
self.modtool.unload(['test'])
1195+
11691196
# check whether prepend with priority actually works (only for Lmod)
11701197
if isinstance(self.modtool, Lmod):
11711198
self.modtool.use(test_dir1, priority=100)
11721199
self.modtool.use(test_dir3)
11731200
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'])
11741214

11751215
def test_module_use_bash(self):
11761216
"""Test whether effect of 'module use' is preserved when a new bash session is started."""

0 commit comments

Comments
 (0)