Skip to content

Commit 65676df

Browse files
committed
Handle Environment-Modules 4.x behavior in tests
1 parent 006186f commit 65676df

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

test/framework/modules.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,25 +1260,33 @@ def test_add_and_remove_module_path(self):
12601260
self.assertEqual(os.environ.get('MODULEPATH', ''), '')
12611261

12621262
# And with some more trickery
1263+
# Lmod seems to remove empty paths: /foo//bar/. -> /foo/bar
1264+
# Environment-Modules 4.x seems to resolve relative paths: /foo/../foo -> /foo
1265+
# Hence we can only check the real paths
1266+
def get_resolved_module_path():
1267+
return ':'.join(os.path.realpath(p) for p in os.environ['MODULEPATH'].split(':'))
1268+
12631269
test_dir1_relative = os.path.join(test_dir1, '..', os.path.basename(test_dir1))
12641270
test_dir2_dot = os.path.join(os.path.dirname(test_dir2), '.', os.path.basename(test_dir2))
12651271
self.modtool.add_module_path(test_dir1_relative)
1266-
self.assertEqual(os.environ['MODULEPATH'], test_dir1_relative)
1272+
self.assertEqual(get_resolved_module_path(), test_dir1)
1273+
# Adding the same path, but in a different form may be possible, but may also be ignored, e.g. in EnvModules
12671274
self.modtool.add_module_path(test_dir1)
1268-
self.assertEqual(os.environ['MODULEPATH'], test_dir1 + ':' + test_dir1_relative)
1269-
self.modtool.remove_module_path(test_dir1)
1270-
self.assertEqual(os.environ['MODULEPATH'], test_dir1_relative)
1275+
if get_resolved_module_path() != test_dir1:
1276+
self.assertEqual(get_resolved_module_path(), test_dir1 + ':' + test_dir1)
1277+
self.modtool.remove_module_path(test_dir1)
1278+
self.assertEqual(get_resolved_module_path(), test_dir1)
12711279
self.modtool.add_module_path(test_dir2_dot)
1272-
self.assertEqual(os.environ['MODULEPATH'], test_dir2 + ':' + test_dir1_relative)
1280+
self.assertEqual(get_resolved_module_path(), test_dir2 + ':' + test_dir1)
12731281
self.modtool.remove_module_path(test_dir2_dot)
1274-
self.assertEqual(os.environ['MODULEPATH'], test_dir1_relative)
1282+
self.assertEqual(get_resolved_module_path(), test_dir1)
12751283
# Force adding such a dot path which can be removed with either variant
12761284
os.environ['MODULEPATH'] = test_dir2_dot + ':' + test_dir1_relative
12771285
self.modtool.remove_module_path(test_dir2_dot)
1278-
self.assertEqual(os.environ['MODULEPATH'], test_dir1_relative)
1286+
self.assertEqual(get_resolved_module_path(), test_dir1)
12791287
os.environ['MODULEPATH'] = test_dir2_dot + ':' + test_dir1_relative
12801288
self.modtool.remove_module_path(test_dir2)
1281-
self.assertEqual(os.environ['MODULEPATH'], test_dir1_relative)
1289+
self.assertEqual(get_resolved_module_path(), test_dir1)
12821290

12831291
os.environ['MODULEPATH'] = old_module_path # Restore
12841292

0 commit comments

Comments
 (0)