def test_squash_simple(self): """Test toolchain filter""" tc_first = {'version': '10', 'name': self.tc_first} tc_last = {'version': '100', 'name': self.tc_last} tc_tmpl = '%(name)s == %(version)s' default_version = '1.0' all_versions = [default_version, '0.0', '1.0'] txt = [ '[SUPPORTED]', 'versions = %s' % ', '.join(all_versions), 'toolchains = %s,%s' % (tc_tmpl % tc_first, tc_tmpl % tc_last), ] co = ConfigObj(txt) cov = EBConfigObj(co) found_tcs = [tmptc.as_dict() for tmptc in cov.sections['toolchains']] self.assertEqual(found_tcs, [tc_first, tc_last]) for tc in [tc_first, tc_last]: for version in all_versions: co = ConfigObj(txt) cov = EBConfigObj(co) res = cov.squash(version, tc['name'], tc['version']) self.assertEqual(res, {}) # very simple
def test_toolchain_squash_nested(self): """Test toolchain filter on nested sections""" tc_first = {'version': '10', 'name': self.tc_first} tc_last = {'version': '100', 'name': self.tc_last} tc_tmpl = '%(name)s == %(version)s' tc_section_first = tc_tmpl % tc_first tc_section_last = tc_tmpl % tc_last txt = [ '[SUPPORTED]', 'versions = 1.0, 0.0, 1.1, 1.6, 2.1', 'toolchains = %s,%s' % (tc_section_first, tc_tmpl % tc_last), '[DEFAULT]', 'y=a', '[> 1.0]', 'y=b', 'x = 1', '[[>= 1.5]]', 'x = 2', 'y=c', '[[[%s]]]' % tc_section_first, 'y=z2', '[[>= 1.6]]', 'z=3', '[> 2.0]', 'x = 3', 'y=d', '[%s]' % tc_section_first, 'y=z1', ] # tests tests = [ (tc_last, '1.0', {'y':'a'}), (tc_last, '1.1', {'y':'b', 'x':'1'}), (tc_last, '1.5', {}), # not a supported version (tc_last, '1.6', {'y':'c', 'x':'2', 'z':'3'}), # nested (tc_last, '2.1', {'y':'d', 'x':'3', 'z':'3'}), # values from most precise versop (tc_first, '1.0', {'y':'z1'}), # toolchain section, not default (tc_first, '1.1', {'y':'b', 'x':'1'}), # the version section precedes the toolchain section (tc_first, '1.5', {}), # not a supported version (tc_first, '1.6', {'y':'z2', 'x':'2', 'z':'3'}), # nested (tc_first, '2.1', {'y':'d', 'x':'3', 'z':'3'}), # values from most precise versop ] for tc, version, res in tests: co = ConfigObj(txt) cov = EBConfigObj(co) squashed = cov.squash(version, tc['name'], tc['version']) self.assertEqual(squashed, res, 'Test for tc %s version %s' % (tc, version))
def get_config_dict(self): """Return the best matching easyconfig dict""" self.log.experimental(self.__class__.__name__) # the toolchain name/version should not be specified in the pyheader, # but other toolchain options are allowed cfg = copy.deepcopy(self.pyheader_localvars) self.log.debug("Config dict based on Python header: %s" % cfg) co = EBConfigObj(self.configobj) version = self.specs.get('version', None) tc_spec = self.specs.get('toolchain', {}) toolchain_name = tc_spec.get('name', None) toolchain_version = tc_spec.get('version', None) # parse and interpret, dealing with defaults etc version, tcname, tcversion = co.get_version_toolchain( version, toolchain_name, toolchain_version) # format 2.0 will squash self.log.debug('Squashing with version %s and toolchain %s' % (version, (tcname, tcversion))) res = co.squash(version, tcname, tcversion) cfg.update(res) self.log.debug( "Config dict after processing applicable easyconfig sections: %s" % cfg) # FIXME what about updating dict values/appending to list values? # FIXME how do we allow both redefining and updating? = and +=? # update config with correct version/toolchain (to avoid using values specified in default section) cfg.update({ 'version': version, 'toolchain': { 'name': tcname, 'version': tcversion }, }) self.log.debug( "Final config dict (including correct version/toolchain): %s" % cfg) return cfg
def get_config_dict(self): """Return the best matching easyconfig dict""" self.log.experimental(self.__class__.__name__) # the toolchain name/version should not be specified in the pyheader, # but other toolchain options are allowed cfg = copy.deepcopy(self.pyheader_localvars) self.log.debug("Config dict based on Python header: %s" % cfg) co = EBConfigObj(self.configobj) version = self.specs.get('version', None) tc_spec = self.specs.get('toolchain', {}) toolchain_name = tc_spec.get('name', None) toolchain_version = tc_spec.get('version', None) # parse and interpret, dealing with defaults etc version, tcname, tcversion = co.get_version_toolchain(version, toolchain_name, toolchain_version) # format 2.0 will squash self.log.debug('Squashing with version %s and toolchain %s' % (version, (tcname, tcversion))) res = co.squash(version, tcname, tcversion) cfg.update(res) self.log.debug("Config dict after processing applicable easyconfig sections: %s" % cfg) # FIXME what about updating dict values/appending to list values? # FIXME how do we allow both redefining and updating? = and +=? # update config with correct version/toolchain (to avoid using values specified in default section) cfg.update({ 'version': version, 'toolchain': {'name': tcname, 'version': tcversion}, }) self.log.debug("Final config dict (including correct version/toolchain): %s" % cfg) return cfg