5858from easybuild .framework .easyconfig .tools import categorize_files_by_type , check_sha256_checksums , dep_graph
5959from easybuild .framework .easyconfig .tools import find_related_easyconfigs , get_paths_for , parse_easyconfigs
6060from easybuild .framework .easyconfig .tweak import obtain_ec_for , tweak_one
61+ from easybuild .framework .extension import resolve_exts_filter_template
6162from easybuild .toolchains .system import SystemToolchain
6263from easybuild .tools .build_log import EasyBuildError
6364from easybuild .tools .config import module_classes
@@ -198,7 +199,7 @@ def test_validation(self):
198199 # introduce "TypeError: format requires mapping" issue"
199200 self .contents = self .contents .replace ("syntax_error'" , "foo = '%(name)s %s' % version" )
200201 self .prep ()
201- error_pattern = "Parsing easyconfig file failed: format requires a mapping \(line 8\)"
202+ error_pattern = r "Parsing easyconfig file failed: format requires a mapping \(line 8\)"
202203 self .assertErrorRegex (EasyBuildError , error_pattern , EasyConfig , self .eb_file )
203204
204205 def test_system_toolchain_constant (self ):
@@ -854,7 +855,7 @@ def test_obtain_easyconfig(self):
854855 # hidden dependencies must be included in list of dependencies
855856 res = obtain_ec_for (specs , [self .test_prefix ], None )
856857 self .assertEqual (res [0 ], True )
857- error_pattern = "Hidden deps with visible module names .* not in list of \(build\)dependencies: .*"
858+ error_pattern = r "Hidden deps with visible module names .* not in list of \(build\)dependencies: .*"
858859 self .assertErrorRegex (EasyBuildError , error_pattern , EasyConfig , res [1 ])
859860 remove_file (res [1 ])
860861
@@ -1559,7 +1560,6 @@ def test_quote_str(self):
15591560 'foo' : '"foo"' ,
15601561 'foo\' bar' : '"foo\' bar"' ,
15611562 'foo\' bar"baz' : '"""foo\' bar"baz"""' ,
1562- "foo'bar\" baz" : '"""foo\' bar"baz"""' ,
15631563 "foo\n bar" : '"foo\n bar"' ,
15641564 'foo bar' : '"foo bar"'
15651565 }
@@ -2499,9 +2499,9 @@ def test_copy_easyconfigs(self):
24992499 # verify whether copied easyconfig gets cleaned up (stripping out 'Built with' comment + build stats)
25002500 txt = read_file (copied_toy_ec )
25012501 regexs = [
2502- "# Built with EasyBuild" ,
2503- "# Build statistics" ,
2504- "buildstats\s*=" ,
2502+ r "# Built with EasyBuild" ,
2503+ r "# Build statistics" ,
2504+ r "buildstats\s*=" ,
25052505 ]
25062506 for regex in regexs :
25072507 regex = re .compile (regex , re .M )
@@ -2708,8 +2708,8 @@ def test_hidden_toolchain(self):
27082708 '--dry-run' ,
27092709 ]
27102710 outtxt = self .eb_main (args , raise_error = True )
2711- self .assertTrue (re .search ('module: GCC/\.4\.9\.2' , outtxt ))
2712- self .assertTrue (re .search ('module: gzip/1\.6-GCC-4\.9\.2' , outtxt ))
2711+ self .assertTrue (re .search (r 'module: GCC/\.4\.9\.2' , outtxt ))
2712+ self .assertTrue (re .search (r 'module: gzip/1\.6-GCC-4\.9\.2' , outtxt ))
27132713
27142714 def test_categorize_files_by_type (self ):
27152715 """Test categorize_files_by_type"""
@@ -2853,8 +2853,8 @@ def test_verify_easyconfig_filename(self):
28532853 # incorrect spec
28542854 specs ['versionsuffix' ] = ''
28552855 error_pattern = "filename '%s' does not match with expected filename 'toy-0.0-gompi-2018a.eb' " % toy_ec_name
2856- error_pattern += "\(specs: name: 'toy'; version: '0.0'; versionsuffix: ''; "
2857- error_pattern += "toolchain name, version: 'gompi', '2018a'\)"
2856+ error_pattern += r "\(specs: name: 'toy'; version: '0.0'; versionsuffix: ''; "
2857+ error_pattern += r "toolchain name, version: 'gompi', '2018a'\)"
28582858 self .assertErrorRegex (EasyBuildError , error_pattern , verify_easyconfig_filename , toy_ec , specs )
28592859 specs ['versionsuffix' ] = '-test'
28602860
@@ -2863,8 +2863,8 @@ def test_verify_easyconfig_filename(self):
28632863 toy_ec = os .path .join (self .test_prefix , 'toy.eb' )
28642864 write_file (toy_ec , toy_txt )
28652865 error_pattern = "filename 'toy.eb' does not match with expected filename 'toy-0.0-gompi-2018a-test.eb' "
2866- error_pattern += "\(specs: name: 'toy'; version: '0.0'; versionsuffix: '-test'; "
2867- error_pattern += "toolchain name, version: 'gompi', '2018a'\)"
2866+ error_pattern += r "\(specs: name: 'toy'; version: '0.0'; versionsuffix: '-test'; "
2867+ error_pattern += r "toolchain name, version: 'gompi', '2018a'\)"
28682868 self .assertErrorRegex (EasyBuildError , error_pattern , verify_easyconfig_filename , toy_ec , specs )
28692869
28702870 # incorrect file contents
@@ -2998,7 +2998,7 @@ def test_check_sha256_checksums(self):
29982998 toy_ec = os .path .join (test_ecs_dir , 't' , 'toy' , 'toy-0.0.eb' )
29992999 toy_ec_txt = read_file (toy_ec )
30003000
3001- checksums_regex = re .compile ('^checksums = \[\[(.|\n )*\]\]' , re .M )
3001+ checksums_regex = re .compile (r '^checksums = \[\[(.|\n)*\]\]' , re .M )
30023002
30033003 # wipe out specified checksums, to make check fail
30043004 test_ec = os .path .join (self .test_prefix , 'toy-0.0-fail.eb' )
@@ -3013,7 +3013,7 @@ def test_check_sha256_checksums(self):
30133013 self .assertTrue (res [0 ].startswith ('Checksums missing for one or more sources/patches in toy-0.0-fail.eb' ))
30143014
30153015 # test use of whitelist regex patterns: check passes because easyconfig is whitelisted by filename
3016- for regex in ['toy-.*' , '.*-0\.0-fail\.eb' ]:
3016+ for regex in [r 'toy-.*' , r '.*-0\.0-fail\.eb' ]:
30173017 res = check_sha256_checksums (ecs , whitelist = [regex ])
30183018 self .assertFalse (res )
30193019
@@ -3033,7 +3033,7 @@ def test_check_sha256_checksums(self):
30333033 # re-test with right checksum in place
30343034 toy_sha256 = '44332000aa33b99ad1e00cbd1a7da769220d74647060a10e807b916d73ea27bc'
30353035 test_ec_txt = checksums_regex .sub ('checksums = ["%s"]' % toy_sha256 , toy_ec_txt )
3036- test_ec_txt = re .sub ('patches = \[(.|\n )*\]' , '' , test_ec_txt )
3036+ test_ec_txt = re .sub (r 'patches = \[(.|\n)*\]' , '' , test_ec_txt )
30373037
30383038 test_ec = os .path .join (self .test_prefix , 'toy-0.0-ok.eb' )
30393039 write_file (test_ec , test_ec_txt )
@@ -3557,6 +3557,55 @@ def test_unexpected_version_keys_caught(self):
35573557
35583558 self .assertRaises (EasyBuildError , EasyConfig , test_ec )
35593559
3560+ def test_resolve_exts_filter_template (self ):
3561+ class TestExtension (object ):
3562+ def __init__ (self , values ):
3563+ self .name = values ['name' ]
3564+ self .version = values .get ('version' )
3565+ self .src = values .get ('src' )
3566+ self .options = values .get ('options' , {})
3567+
3568+ error_msg = 'exts_filter should be a list or tuple'
3569+ self .assertErrorRegex (EasyBuildError , error_msg , resolve_exts_filter_template ,
3570+ '[ 1 == 1 ]' , {})
3571+ self .assertErrorRegex (EasyBuildError , error_msg , resolve_exts_filter_template ,
3572+ ['[ 1 == 1 ]' ], {})
3573+ self .assertErrorRegex (EasyBuildError , error_msg , resolve_exts_filter_template ,
3574+ ['[ 1 == 1 ]' , 'true' , 'false' ], {})
3575+
3576+ test_cases = [
3577+ # Minimal case: just name
3578+ (['%(ext_name)s' , None ],
3579+ {'name' : 'foo' },
3580+ ('foo' , None ),
3581+ ),
3582+ # Minimal case with input
3583+ (['%(ext_name)s' , '>%(ext_name)s' ],
3584+ {'name' : 'foo' },
3585+ ('foo' , '>foo' ),
3586+ ),
3587+ # All values
3588+ (['%(ext_name)s-%(ext_version)s-%(src)s' , '>%(ext_name)s-%(ext_version)s-%(src)s' ],
3589+ {'name' : 'foo' , 'version' : 42 , 'src' : 'bar.tgz' },
3590+ ('foo-42-bar.tgz' , '>foo-42-bar.tgz' ),
3591+ ),
3592+ # options dict is accepted
3593+ (['%(ext_name)s-%(ext_version)s-%(src)s' , '>%(ext_name)s-%(ext_version)s-%(src)s' ],
3594+ {'name' : 'foo' , 'version' : 42 , 'src' : 'bar.tgz' , 'options' : {'dummy' : 'value' }},
3595+ ('foo-42-bar.tgz' , '>foo-42-bar.tgz' ),
3596+ ),
3597+ # modulename overwrites name
3598+ (['%(ext_name)s-%(ext_version)s-%(src)s' , '>%(ext_name)s-%(ext_version)s-%(src)s' ],
3599+ {'name' : 'foo' , 'version' : 42 , 'src' : 'bar.tgz' , 'options' : {'modulename' : 'baz' }},
3600+ ('baz-42-bar.tgz' , '>baz-42-bar.tgz' ),
3601+ ),
3602+ ]
3603+ for exts_filter , ext , expected_value in test_cases :
3604+ value = resolve_exts_filter_template (exts_filter , ext )
3605+ self .assertEqual (value , expected_value )
3606+ value = resolve_exts_filter_template (exts_filter , TestExtension (ext ))
3607+ self .assertEqual (value , expected_value )
3608+
35603609
35613610def suite ():
35623611 """ returns all the testcases in this module """
0 commit comments