def test_render_value(self): source = { 'str': 'pkgcore.test', 'bool': 'yes', 'list': '0 1 2', 'callable': 'pkgcore.test.config.test_basics.passthrough', } destination = { 'str': 'pkgcore.test', 'bool': True, 'list': ['0', '1', '2'], 'callable': passthrough, } # valid gets for typename, value in destination.iteritems(): self.assertEqual( value, basics.convert_string(None, source[typename], typename)) # reprs for typename, value in source.iteritems(): self.assertEqual(('str', value), basics.convert_string(None, source[typename], 'repr')) # invalid gets # not callable self.assertRaises(errors.ConfigurationError, basics.convert_string, None, source['str'], 'callable') # not importable self.assertRaises(errors.ConfigurationError, basics.convert_string, None, source['bool'], 'callable') # Bogus type. self.assertRaises(errors.ConfigurationError, basics.convert_string, None, source['bool'], 'frob')
def test_section_ref(self): def spoon(): """Noop.""" target_config = central.CollapsedConfig( basics.ConfigType(spoon), {}, None) class TestCentral(object): def collapse_named_section(self, section): try: return {'target': target_config}[section] except KeyError: raise errors.ConfigurationError(section) self.assertEqual( basics.convert_string( TestCentral(), 'target', 'ref:spoon').collapse(), target_config) self.assertRaises( errors.ConfigurationError, basics.convert_string( TestCentral(), 'missing', 'ref:spoon').instantiate)
def test_section_ref(self): def spoon(): """Noop.""" target_config = central.CollapsedConfig( basics.ConfigType(spoon), {}, None) class TestCentral: def collapse_named_section(self, section): try: return {'target': target_config}[section] except KeyError: raise errors.ConfigurationError(section) self.assertEqual( basics.convert_string( TestCentral(), 'target', 'ref:spoon').collapse(), target_config) self.assertRaises( errors.ConfigurationError, basics.convert_string( TestCentral(), 'missing', 'ref:spoon').instantiate)
def test_section_refs(self): def spoon(): """Noop.""" config1 = central.CollapsedConfig( basics.ConfigType(spoon), {}, None) config2 = central.CollapsedConfig( basics.ConfigType(spoon), {}, None) class TestCentral(object): def collapse_named_section(self, section): try: return {'1': config1, '2': config2}[section] except KeyError: raise errors.ConfigurationError(section) self.assertEqual( list(ref.collapse() for ref in basics.convert_string( TestCentral(), '1 2', 'refs:spoon')), [config1, config2]) lazy_refs = basics.convert_string(TestCentral(), '2 3', 'refs:spoon') self.assertEqual(2, len(lazy_refs)) self.assertRaises(errors.ConfigurationError, lazy_refs[1].collapse)
def test_section_refs(self): def spoon(): """Noop.""" config1 = central.CollapsedConfig(basics.ConfigType(spoon), {}, None) config2 = central.CollapsedConfig(basics.ConfigType(spoon), {}, None) class TestCentral(object): def collapse_named_section(self, section): try: return {'1': config1, '2': config2}[section] except KeyError: raise errors.ConfigurationError(section) self.assertEqual( list(ref.collapse() for ref in basics.convert_string( TestCentral(), '1 2', 'refs:spoon')), [config1, config2]) lazy_refs = basics.convert_string(TestCentral(), '2 3', 'refs:spoon') self.assertEqual(2, len(lazy_refs)) self.assertRaises(errors.ConfigurationError, lazy_refs[1].collapse)
def test_render_value(self): source = { 'str': 'pkgcore.test', 'bool': 'yes', 'list': '0 1 2', 'callable': 'pkgcore.test.config.test_basics.passthrough', } destination = { 'str': 'pkgcore.test', 'bool': True, 'list': ['0', '1', '2'], 'callable': passthrough, } # valid gets for typename, value in destination.iteritems(): self.assertEqual( value, basics.convert_string(None, source[typename], typename)) # reprs for typename, value in source.iteritems(): self.assertEqual( ('str', value), basics.convert_string(None, source[typename], 'repr')) # invalid gets # not callable self.assertRaises( errors.ConfigurationError, basics.convert_string, None, source['str'], 'callable') # not importable self.assertRaises( errors.ConfigurationError, basics.convert_string, None, source['bool'], 'callable') # Bogus type. self.assertRaises( errors.ConfigurationError, basics.convert_string, None, source['bool'], 'frob')