def __parse_autowire(self, autowire): abstract = autowire.getAttribute("abstract") concrete = autowire.getAttribute("concrete") return (ConfigTools.fqn_to_pair(abstract), (ConfigTools.fqn_to_pair(concrete), dict(self.__parse_parameter(parameter) for parameter in autowire.getElementsByTagNameNS(self.NAMESPACE_URI, "parameter"))))
def as_names(some_map): """ Returns an abstract-to-concrete map as name @param some_map: dict(str,str) dict(tuple(str,str),tuple(str,str)) or dict(object, object) @rtype: iter(tuple(str,str)) """ if len(some_map): key = some_map.iterkeys().next() if isinstance(key, basestring): return some_map.iteritems() elif isinstance(key, TupleType) and isinstance(key[0], basestring): return ((ConfigTools.pair_to_fqn(a), [ConfigTools.pair_to_fqn(cs)]) for (a, (cs, _args)) in some_map.iteritems() ) else: return ((ConfigTools.to_fqn(a), map(ConfigTools.to_fqn, cs)) for (a, cs) in some_map.iteritems()) else: return ()
def dump(): configurator = _ConfiguratorInternal() configurator.load_configuration(flavors=[]) abstracts_to_concrete_map = configurator.get_adapter_map() args_map = dict(abstracts_to_concrete_map.itervalues()) generator = PlainAutoWireConfigGenerator( abstracts_to_concrete_map, selection_strategy_func=lambda abstract, concretes: concretes[0], # select the single concrete adapter for each abstract adapter args_func=lambda concrete_name: args_map[ConfigTools.fqn_to_pair( concrete_name)], ) for line in generator.get_configuration_lines(): print line
def test_is_autoconfigurable_class_4(self): self.assertFalse(ConfigTools.is_autoconfigurable_class(Test, "cac_class"))
def test_is_autoconfigurable_class_2(self): self.assertTrue(ConfigTools.is_autoconfigurable_class(Test, "aac_class"))
def test_is_autoconfigurable_class_3(self): self.assertFalse(ConfigTools.is_autoconfigurable_class(Test, "cac_instance"))
def test_is_autoconfigurable_object_3(self): self.assertFalse(ConfigTools.is_autoconfigurable_object(Test.cac_instance))
def test_is_autoconfigurable_object_4(self): self.assertFalse(ConfigTools.is_autoconfigurable_object(Test.cac_class))
def test_decode_parameter_value_class_1(self): self.assertEquals(ConcreteAutoConfigurable, ConfigTools.decode_parameter_value(dict({"value": "test.commons.testdata.config_tools_testdata.ConcreteAutoConfigurable", "type": "class"}), lambda module, cls: ConcreteAutoConfigurable if (module, cls)==("test.commons.testdata.config_tools_testdata", "ConcreteAutoConfigurable") else None))
def test_is_autoconfigurable_object_1(self): self.assertTrue(ConfigTools.is_autoconfigurable_object(Test.aac_instance))
def test_get_abstract_adapter_types_for_config_variables_set(self): self.assertEquals([AbstractAutoConfigurable], list(ConfigTools.get_abstract_adapter_types_for_config_variables_set([(config_tools_testdata, "config_var_class"), (config_tools_testdata, "config_var_instance"), (config_tools_testdata, "config_var_class"), (config_tools_testdata, "config_var_instance")])))
def test_get_config_variables_iter(self): self.assertEquals([(config_tools_testdata, "config_var_class"), (config_tools_testdata, "config_var_instance")], sorted(ConfigTools.get_config_variables_iter([config_tools_testdata])))
def test_is_class_any_autoconfigurable_1(self): self.assertTrue(ConfigTools.is_class_any_autoconfigurable(AbstractAutoConfigurable))
def test_is_class_any_autoconfigurable_2(self): self.assertTrue(ConfigTools.is_class_any_autoconfigurable(ConcreteAutoConfigurable))
def test_is_class_concrete_autoconfigurable_1(self): self.assertFalse(ConfigTools.is_class_concrete_autoconfigurable(AbstractAutoConfigurable))
def test_is_class_abstract_autoconfigurable_2(self): self.assertFalse(ConfigTools.is_class_abstract_autoconfigurable(ConcreteAutoConfigurable))
def test_decode_parameter_value_object_1(self): obj = ConfigTools.decode_parameter_value(dict({"value": "test.commons.testdata.config_tools_testdata.ConcreteAutoConfigurable", "type": "object"}), lambda module, cls: ConcreteAutoConfigurable if (module, cls)==("test.commons.testdata.config_tools_testdata", "ConcreteAutoConfigurable") else None) self.assertTrue(isinstance(obj, ConcreteAutoConfigurable))
def test_get_type_of_autoconfigurable_class_or_instance_1(self): self.assertEquals(AbstractAutoConfigurable, ConfigTools.get_type_of_autoconfigurable_class_or_instance(Test.aac_class))
def test_fqn_to_pair_2(self): self.assertEquals(("package.module", "Class"), ConfigTools.fqn_to_pair("package.module.Class"))
def test_is_class_any_autoconfigurable_3(self): self.assertFalse(ConfigTools.is_class_any_autoconfigurable(UnrelatedClass))
def test_decode_parameter_value_2(self): self.assertEquals(14, ConfigTools.decode_parameter_value(dict({"value": "14", "type": "int"}), None))
def test_to_fqn(self): self.assertEquals("test.unit_tests.commons.testdata.config_tools_testdata.AbstractAutoConfigurable", ConfigTools.to_fqn(AbstractAutoConfigurable))
def test_get_config_variables_single(self): self.assertEquals(["config_var_class", "config_var_instance"], sorted(ConfigTools.get_config_variables_single(config_tools_testdata)))