@@ -5148,6 +5148,43 @@ def test_easyconfigs_caches(self):
51485148 regex = re .compile (r"libtoy/0\.0 is already installed" , re .M )
51495149 self .assertTrue (regex .search (stdout ), "Pattern '%s' should be found in: %s" % (regex .pattern , stdout ))
51505150
5151+ def test_templates (self ):
5152+ """
5153+ Test use of template values like %(version)s
5154+ """
5155+ test_ecs_dir = os .path .join (os .path .dirname (os .path .abspath (__file__ )), 'easyconfigs' , 'test_ecs' )
5156+ toy_ec = os .path .join (test_ecs_dir , 't' , 'toy' , 'toy-0.0.eb' )
5157+
5158+ test_ec_txt = read_file (toy_ec )
5159+ test_ec_txt += '\n description = "name: %(name)s, version: %(version)s"'
5160+
5161+ test_ec = os .path .join (self .test_prefix , 'test.eb' )
5162+ write_file (test_ec , test_ec_txt )
5163+ ec = EasyConfig (test_ec )
5164+
5165+ # get_ref provides access to non-templated raw value
5166+ self .assertEqual (ec .get_ref ('description' ), "name: %(name)s, version: %(version)s" )
5167+ self .assertEqual (ec ['description' ], "name: toy, version: 0.0" )
5168+
5169+ # error when using wrong template value or using template value that can not be resolved yet too early
5170+ test_ec_txt += '\n description = "name: %(name)s, version: %(version)s, pyshortver: %(pyshortver)s"'
5171+ write_file (test_ec , test_ec_txt )
5172+ ec = EasyConfig (test_ec )
5173+
5174+ self .assertEqual (ec .get_ref ('description' ), "name: %(name)s, version: %(version)s, pyshortver: %(pyshortver)s" )
5175+ error_pattern = "Failed to resolve all templates in.* %\(pyshortver\)s.* using template dictionary:"
5176+ self .assertErrorRegex (EasyBuildError , error_pattern , ec .__getitem__ , 'description' )
5177+
5178+ # EasyBuild can be configured to allow unresolved templates
5179+ update_build_option ('allow_unresolved_templates' , True )
5180+ self .assertEqual (ec .get_ref ('description' ), "name: %(name)s, version: %(version)s, pyshortver: %(pyshortver)s" )
5181+ with self .mocked_stdout_stderr () as (stdout , stderr ):
5182+ self .assertEqual (ec ['description' ], "name: %(name)s, version: %(version)s, pyshortver: %(pyshortver)s" )
5183+
5184+ self .assertFalse (stdout .getvalue ())
5185+ regex = re .compile (r"WARNING: Failed to resolve all templates.* %\(pyshortver\)s" , re .M )
5186+ self .assertRegex (stderr .getvalue (), regex )
5187+
51515188
51525189def suite ():
51535190 """ returns all the testcases in this module """
0 commit comments