コード例 #1
0
    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)
コード例 #2
0
 def test_alias(self):
     def spoon():
         """Noop."""
     foon = central.CollapsedConfig(basics.ConfigType(spoon), {}, None)
     class MockManager:
         def collapse_named_section(self, name):
             if name == 'foon':
                 return foon
             return object()
     manager = MockManager()
     alias = basics.section_alias('foon', 'spoon')
     type_obj = basics.ConfigType(alias.render_value(manager, 'class',
                                                  'callable'))
     self.assertEqual('spoon', type_obj.name)
     self.assertIdentical(
         foon,
         alias.render_value(manager, 'target', 'ref:spoon').collapse())
コード例 #3
0
 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)