Skip to content

Commit b9783fd

Browse files
committed
Update tests to use filtering module generator
1 parent fe0489c commit b9783fd

File tree

2 files changed

+46
-31
lines changed

2 files changed

+46
-31
lines changed

test/framework/easyblock.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,8 @@ def test_make_module_req(self):
431431
# this is not a path that should be picked up
432432
os.mkdir(os.path.join(eb.installdir, 'CPATH'))
433433

434-
guess = eb.make_module_req()
434+
with eb.module_generator.start_module_creation():
435+
guess = eb.make_module_req()
435436

436437
if get_module_syntax() == 'Tcl':
437438
self.assertTrue(re.search(r"^prepend-path\s+CLASSPATH\s+\$root/bla.jar$", guess, re.M))
@@ -458,7 +459,8 @@ def test_make_module_req(self):
458459

459460
# check that bin is only added to PATH if there are files in there
460461
write_file(os.path.join(eb.installdir, 'bin', 'test'), 'test')
461-
guess = eb.make_module_req()
462+
with eb.module_generator.start_module_creation():
463+
guess = eb.make_module_req()
462464
if get_module_syntax() == 'Tcl':
463465
self.assertTrue(re.search(r"^prepend-path\s+PATH\s+\$root/bin$", guess, re.M))
464466
self.assertFalse(re.search(r"^prepend-path\s+PATH\s+\$root/sbin$", guess, re.M))
@@ -477,7 +479,8 @@ def test_make_module_req(self):
477479
self.assertFalse('prepend_path("CMAKE_LIBRARY_PATH", pathJoin(root, "lib64"))' in guess)
478480
# -- With files
479481
write_file(os.path.join(eb.installdir, 'lib64', 'libfoo.so'), 'test')
480-
guess = eb.make_module_req()
482+
with eb.module_generator.start_module_creation():
483+
guess = eb.make_module_req()
481484
if get_module_syntax() == 'Tcl':
482485
self.assertTrue(re.search(r"^prepend-path\s+CMAKE_LIBRARY_PATH\s+\$root/lib64$", guess, re.M))
483486
elif get_module_syntax() == 'Lua':
@@ -486,7 +489,8 @@ def test_make_module_req(self):
486489
write_file(os.path.join(eb.installdir, 'lib', 'libfoo.so'), 'test')
487490
shutil.rmtree(os.path.join(eb.installdir, 'lib64'))
488491
os.symlink('lib', os.path.join(eb.installdir, 'lib64'))
489-
guess = eb.make_module_req()
492+
with eb.module_generator.start_module_creation():
493+
guess = eb.make_module_req()
490494
if get_module_syntax() == 'Tcl':
491495
self.assertFalse(re.search(r"^prepend-path\s+CMAKE_LIBRARY_PATH\s+\$root/lib64$", guess, re.M))
492496
elif get_module_syntax() == 'Lua':
@@ -505,7 +509,8 @@ def test_make_module_req(self):
505509

506510
# check for behavior when a string value is used as dict value by make_module_req_guesses
507511
eb.make_module_req_guess = lambda: {'PATH': 'bin'}
508-
txt = eb.make_module_req()
512+
with eb.module_generator.start_module_creation():
513+
txt = eb.make_module_req()
509514
if get_module_syntax() == 'Tcl':
510515
self.assertTrue(re.match(r"^\nprepend-path\s+PATH\s+\$root/bin\n$", txt, re.M))
511516
elif get_module_syntax() == 'Lua':
@@ -516,7 +521,8 @@ def test_make_module_req(self):
516521
# check for correct behaviour if empty string is specified as one of the values
517522
# prepend-path statements should be included for both the 'bin' subdir and the install root
518523
eb.make_module_req_guess = lambda: {'PATH': ['bin', '']}
519-
txt = eb.make_module_req()
524+
with eb.module_generator.start_module_creation():
525+
txt = eb.make_module_req()
520526
if get_module_syntax() == 'Tcl':
521527
self.assertTrue(re.search(r"\nprepend-path\s+PATH\s+\$root/bin\n", txt, re.M))
522528
self.assertTrue(re.search(r"\nprepend-path\s+PATH\s+\$root\n", txt, re.M))
@@ -531,7 +537,8 @@ def test_make_module_req(self):
531537
for path in ['pathA', 'pathB', 'pathC']:
532538
os.mkdir(os.path.join(eb.installdir, 'lib', path))
533539
write_file(os.path.join(eb.installdir, 'lib', path, 'libfoo.so'), 'test')
534-
txt = eb.make_module_req()
540+
with eb.module_generator.start_module_creation():
541+
txt = eb.make_module_req()
535542
if get_module_syntax() == 'Tcl':
536543
self.assertTrue(re.search(r"\nprepend-path\s+LD_LIBRARY_PATH\s+\$root/lib/pathC\n" +
537544
r"prepend-path\s+LD_LIBRARY_PATH\s+\$root/lib/pathA\n" +

test/framework/module_generator.py

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,10 @@ def test_swap(self):
670670
def test_append_paths(self):
671671
"""Test generating append-paths statements."""
672672
# test append_paths
673+
def append_paths(*args, **kwargs):
674+
"""Wrap this into start_module_creation which need to be called prior to append_paths"""
675+
with self.modgen.start_module_creation():
676+
return self.modgen.append_paths(*args, **kwargs)
673677

674678
if self.MODULE_GENERATOR_CLASS == ModuleGeneratorTcl:
675679
expected = ''.join([
@@ -678,17 +682,17 @@ def test_append_paths(self):
678682
"append-path\tkey\t\t$root\n",
679683
])
680684
paths = ['path1', 'path2', '']
681-
self.assertEqual(expected, self.modgen.append_paths("key", paths))
685+
self.assertEqual(expected, append_paths("key", paths))
682686
# 2nd call should still give same result, no side-effects like manipulating passed list 'paths'!
683-
self.assertEqual(expected, self.modgen.append_paths("key", paths))
687+
self.assertEqual(expected, append_paths("key", paths))
684688

685689
expected = "append-path\tbar\t\t$root/foo\n"
686-
self.assertEqual(expected, self.modgen.append_paths("bar", "foo"))
690+
self.assertEqual(expected, append_paths("bar", "foo"))
687691

688-
res = self.modgen.append_paths("key", ["/abs/path"], allow_abs=True)
692+
res = append_paths("key", ["/abs/path"], allow_abs=True)
689693
self.assertEqual("append-path\tkey\t\t/abs/path\n", res)
690694

691-
res = self.modgen.append_paths('key', ['[email protected]'], expand_relpaths=False)
695+
res = append_paths('key', ['[email protected]'], expand_relpaths=False)
692696
self.assertEqual("append-path\tkey\t\t[email protected]\n", res)
693697

694698
else:
@@ -698,22 +702,22 @@ def test_append_paths(self):
698702
'append_path("key", root)\n',
699703
])
700704
paths = ['path1', 'path2', '']
701-
self.assertEqual(expected, self.modgen.append_paths("key", paths))
705+
self.assertEqual(expected, append_paths("key", paths))
702706
# 2nd call should still give same result, no side-effects like manipulating passed list 'paths'!
703-
self.assertEqual(expected, self.modgen.append_paths("key", paths))
707+
self.assertEqual(expected, append_paths("key", paths))
704708

705709
expected = 'append_path("bar", pathJoin(root, "foo"))\n'
706-
self.assertEqual(expected, self.modgen.append_paths("bar", "foo"))
710+
self.assertEqual(expected, append_paths("bar", "foo"))
707711

708712
expected = 'append_path("key", "/abs/path")\n'
709-
self.assertEqual(expected, self.modgen.append_paths("key", ["/abs/path"], allow_abs=True))
713+
self.assertEqual(expected, append_paths("key", ["/abs/path"], allow_abs=True))
710714

711-
res = self.modgen.append_paths('key', ['[email protected]'], expand_relpaths=False)
715+
res = append_paths('key', ['[email protected]'], expand_relpaths=False)
712716
self.assertEqual('append_path("key", "[email protected]")\n', res)
713717

714718
self.assertErrorRegex(EasyBuildError, "Absolute path %s/foo passed to update_paths "
715-
"which only expects relative paths." % self.modgen.app.installdir,
716-
self.modgen.append_paths, "key2", ["bar", "%s/foo" % self.modgen.app.installdir])
719+
"which only expects relative paths." % self.modgen.app.installdir,
720+
append_paths, "key2", ["bar", "%s/foo" % self.modgen.app.installdir])
717721

718722
def test_module_extensions(self):
719723
"""test the extensions() for extensions"""
@@ -745,6 +749,10 @@ def test_module_extensions(self):
745749
def test_prepend_paths(self):
746750
"""Test generating prepend-paths statements."""
747751
# test prepend_paths
752+
def prepend_paths(*args, **kwargs):
753+
"""Wrap this into start_module_creation which need to be called prior to append_paths"""
754+
with self.modgen.start_module_creation():
755+
return self.modgen.prepend_paths(*args, **kwargs)
748756

749757
if self.MODULE_GENERATOR_CLASS == ModuleGeneratorTcl:
750758
expected = ''.join([
@@ -753,17 +761,17 @@ def test_prepend_paths(self):
753761
"prepend-path\tkey\t\t$root\n",
754762
])
755763
paths = ['path1', 'path2', '']
756-
self.assertEqual(expected, self.modgen.prepend_paths("key", paths))
764+
self.assertEqual(expected, prepend_paths("key", paths))
757765
# 2nd call should still give same result, no side-effects like manipulating passed list 'paths'!
758-
self.assertEqual(expected, self.modgen.prepend_paths("key", paths))
766+
self.assertEqual(expected, prepend_paths("key", paths))
759767

760768
expected = "prepend-path\tbar\t\t$root/foo\n"
761-
self.assertEqual(expected, self.modgen.prepend_paths("bar", "foo"))
769+
self.assertEqual(expected, prepend_paths("bar", "foo"))
762770

763-
res = self.modgen.prepend_paths("key", ["/abs/path"], allow_abs=True)
771+
res = prepend_paths("key", ["/abs/path"], allow_abs=True)
764772
self.assertEqual("prepend-path\tkey\t\t/abs/path\n", res)
765773

766-
res = self.modgen.prepend_paths('key', ['[email protected]'], expand_relpaths=False)
774+
res = prepend_paths('key', ['[email protected]'], expand_relpaths=False)
767775
self.assertEqual("prepend-path\tkey\t\t[email protected]\n", res)
768776

769777
else:
@@ -773,22 +781,22 @@ def test_prepend_paths(self):
773781
'prepend_path("key", root)\n',
774782
])
775783
paths = ['path1', 'path2', '']
776-
self.assertEqual(expected, self.modgen.prepend_paths("key", paths))
784+
self.assertEqual(expected, prepend_paths("key", paths))
777785
# 2nd call should still give same result, no side-effects like manipulating passed list 'paths'!
778-
self.assertEqual(expected, self.modgen.prepend_paths("key", paths))
786+
self.assertEqual(expected, prepend_paths("key", paths))
779787

780788
expected = 'prepend_path("bar", pathJoin(root, "foo"))\n'
781-
self.assertEqual(expected, self.modgen.prepend_paths("bar", "foo"))
789+
self.assertEqual(expected, prepend_paths("bar", "foo"))
782790

783791
expected = 'prepend_path("key", "/abs/path")\n'
784-
self.assertEqual(expected, self.modgen.prepend_paths("key", ["/abs/path"], allow_abs=True))
792+
self.assertEqual(expected, prepend_paths("key", ["/abs/path"], allow_abs=True))
785793

786-
res = self.modgen.prepend_paths('key', ['[email protected]'], expand_relpaths=False)
794+
res = prepend_paths('key', ['[email protected]'], expand_relpaths=False)
787795
self.assertEqual('prepend_path("key", "[email protected]")\n', res)
788796

789797
self.assertErrorRegex(EasyBuildError, "Absolute path %s/foo passed to update_paths "
790-
"which only expects relative paths." % self.modgen.app.installdir,
791-
self.modgen.prepend_paths, "key2", ["bar", "%s/foo" % self.modgen.app.installdir])
798+
"which only expects relative paths." % self.modgen.app.installdir,
799+
prepend_paths, "key2", ["bar", "%s/foo" % self.modgen.app.installdir])
792800

793801
def test_det_user_modpath(self):
794802
"""Test for generic det_user_modpath method."""

0 commit comments

Comments
 (0)