@@ -435,7 +435,8 @@ def test_make_module_req(self):
435435 # this is not a path that should be picked up
436436 os .mkdir (os .path .join (eb .installdir , 'CPATH' ))
437437
438- guess = eb .make_module_req ()
438+ with eb .module_generator .start_module_creation ():
439+ guess = eb .make_module_req ()
439440
440441 if get_module_syntax () == 'Tcl' :
441442 self .assertTrue (re .search (r"^prepend-path\s+CLASSPATH\s+\$root/bla.jar$" , guess , re .M ))
@@ -462,7 +463,8 @@ def test_make_module_req(self):
462463
463464 # check that bin is only added to PATH if there are files in there
464465 write_file (os .path .join (eb .installdir , 'bin' , 'test' ), 'test' )
465- guess = eb .make_module_req ()
466+ with eb .module_generator .start_module_creation ():
467+ guess = eb .make_module_req ()
466468 if get_module_syntax () == 'Tcl' :
467469 self .assertTrue (re .search (r"^prepend-path\s+PATH\s+\$root/bin$" , guess , re .M ))
468470 self .assertFalse (re .search (r"^prepend-path\s+PATH\s+\$root/sbin$" , guess , re .M ))
@@ -481,7 +483,8 @@ def test_make_module_req(self):
481483 self .assertFalse ('prepend_path("CMAKE_LIBRARY_PATH", pathJoin(root, "lib64"))' in guess )
482484 # -- With files
483485 write_file (os .path .join (eb .installdir , 'lib64' , 'libfoo.so' ), 'test' )
484- guess = eb .make_module_req ()
486+ with eb .module_generator .start_module_creation ():
487+ guess = eb .make_module_req ()
485488 if get_module_syntax () == 'Tcl' :
486489 self .assertTrue (re .search (r"^prepend-path\s+CMAKE_LIBRARY_PATH\s+\$root/lib64$" , guess , re .M ))
487490 elif get_module_syntax () == 'Lua' :
@@ -490,7 +493,8 @@ def test_make_module_req(self):
490493 write_file (os .path .join (eb .installdir , 'lib' , 'libfoo.so' ), 'test' )
491494 shutil .rmtree (os .path .join (eb .installdir , 'lib64' ))
492495 os .symlink ('lib' , os .path .join (eb .installdir , 'lib64' ))
493- guess = eb .make_module_req ()
496+ with eb .module_generator .start_module_creation ():
497+ guess = eb .make_module_req ()
494498 if get_module_syntax () == 'Tcl' :
495499 self .assertFalse (re .search (r"^prepend-path\s+CMAKE_LIBRARY_PATH\s+\$root/lib64$" , guess , re .M ))
496500 elif get_module_syntax () == 'Lua' :
@@ -509,7 +513,8 @@ def test_make_module_req(self):
509513
510514 # check for behavior when a string value is used as dict value by make_module_req_guesses
511515 eb .make_module_req_guess = lambda : {'PATH' : 'bin' }
512- txt = eb .make_module_req ()
516+ with eb .module_generator .start_module_creation ():
517+ txt = eb .make_module_req ()
513518 if get_module_syntax () == 'Tcl' :
514519 self .assertTrue (re .match (r"^\nprepend-path\s+PATH\s+\$root/bin\n$" , txt , re .M ))
515520 elif get_module_syntax () == 'Lua' :
@@ -520,7 +525,8 @@ def test_make_module_req(self):
520525 # check for correct behaviour if empty string is specified as one of the values
521526 # prepend-path statements should be included for both the 'bin' subdir and the install root
522527 eb .make_module_req_guess = lambda : {'PATH' : ['bin' , '' ]}
523- txt = eb .make_module_req ()
528+ with eb .module_generator .start_module_creation ():
529+ txt = eb .make_module_req ()
524530 if get_module_syntax () == 'Tcl' :
525531 self .assertTrue (re .search (r"\nprepend-path\s+PATH\s+\$root/bin\n" , txt , re .M ))
526532 self .assertTrue (re .search (r"\nprepend-path\s+PATH\s+\$root\n" , txt , re .M ))
@@ -535,7 +541,8 @@ def test_make_module_req(self):
535541 for path in ['pathA' , 'pathB' , 'pathC' ]:
536542 os .mkdir (os .path .join (eb .installdir , 'lib' , path ))
537543 write_file (os .path .join (eb .installdir , 'lib' , path , 'libfoo.so' ), 'test' )
538- txt = eb .make_module_req ()
544+ with eb .module_generator .start_module_creation ():
545+ txt = eb .make_module_req ()
539546 if get_module_syntax () == 'Tcl' :
540547 self .assertTrue (re .search (r"\nprepend-path\s+LD_LIBRARY_PATH\s+\$root/lib/pathC\n" +
541548 r"prepend-path\s+LD_LIBRARY_PATH\s+\$root/lib/pathA\n" +
@@ -1152,7 +1159,7 @@ def test_make_module_step(self):
11521159 # purposely use a 'nasty' description, that includes (unbalanced) special chars: [, ], {, }
11531160 descr = "This {is a}} [fancy]] [[description]]. {{[[TEST}]"
11541161 modextravars = {'PI' : '3.1415' , 'FOO' : 'bar' }
1155- modextrapaths = {'PATH' : ' pibin' , 'CPATH' : 'pi/include' }
1162+ modextrapaths = {'PATH' : ( 'bin' , ' pibin') , 'CPATH' : 'pi/include' }
11561163 self .contents = '\n ' .join ([
11571164 'easyblock = "ConfigureMake"' ,
11581165 'name = "%s"' % name ,
@@ -1177,6 +1184,10 @@ def test_make_module_step(self):
11771184 eb .make_builddir ()
11781185 eb .prepare_step ()
11791186
1187+ # Create a dummy file in bin to test if the duplicate entry of modextrapaths is ignored
1188+ os .makedirs (os .path .join (eb .installdir , 'bin' ))
1189+ write_file (os .path .join (eb .installdir , 'bin' , 'dummy_exe' ), 'hello' )
1190+
11801191 modpath = os .path .join (eb .make_module_step (), name , version )
11811192 if get_module_syntax () == 'Lua' :
11821193 modpath += '.lua'
@@ -1210,14 +1221,20 @@ def test_make_module_step(self):
12101221 self .assertTrue (False , "Unknown module syntax: %s" % get_module_syntax ())
12111222 self .assertTrue (regex .search (txt ), "Pattern %s found in %s" % (regex .pattern , txt ))
12121223
1213- for (key , val ) in modextrapaths .items ():
1214- if get_module_syntax () == 'Tcl' :
1215- regex = re .compile (r'^prepend-path\s+%s\s+\$root/%s$' % (key , val ), re .M )
1216- elif get_module_syntax () == 'Lua' :
1217- regex = re .compile (r'^prepend_path\("%s", pathJoin\(root, "%s"\)\)$' % (key , val ), re .M )
1218- else :
1219- self .assertTrue (False , "Unknown module syntax: %s" % get_module_syntax ())
1220- self .assertTrue (regex .search (txt ), "Pattern %s found in %s" % (regex .pattern , txt ))
1224+ for (key , vals ) in modextrapaths .items ():
1225+ if isinstance (vals , string_type ):
1226+ vals = [vals ]
1227+ for val in vals :
1228+ if get_module_syntax () == 'Tcl' :
1229+ regex = re .compile (r'^prepend-path\s+%s\s+\$root/%s$' % (key , val ), re .M )
1230+ elif get_module_syntax () == 'Lua' :
1231+ regex = re .compile (r'^prepend_path\("%s", pathJoin\(root, "%s"\)\)$' % (key , val ), re .M )
1232+ else :
1233+ self .assertTrue (False , "Unknown module syntax: %s" % get_module_syntax ())
1234+ self .assertTrue (regex .search (txt ), "Pattern %s found in %s" % (regex .pattern , txt ))
1235+ # Check for duplicates
1236+ num_prepends = len (regex .findall (txt ))
1237+ self .assertEqual (num_prepends , 1 , "Expected exactly 1 %s command in %s" % (regex .pattern , txt ))
12211238
12221239 for (name , ver ) in [('GCC' , '6.4.0-2.28' )]:
12231240 if get_module_syntax () == 'Tcl' :
0 commit comments