コード例 #1
0
ファイル: test_Context.py プロジェクト: subokita/Aglyph
 def test_iter_components_yields_only_components(self):
     test_template = Template("test-template")
     self._context.register(test_template)
     test_component = Component("test-component")
     self._context.register(test_component)
     self.assertEqual(
         [test_component], list(self._context.iter_components()))
コード例 #2
0
ファイル: context.py プロジェクト: subokita/Aglyph
 def _init_definition(self):
     return Component(_identify(self._unique_id_spec),
                      dotted_name=_identify(self._dotted_name_spec)
                      if self._dotted_name_spec is not None else None,
                      factory_name=self._factory_name,
                      member_name=self._member_name,
                      strategy=self._strategy,
                      parent_id=_identify(self._parent_id_spec)
                      if self._parent_id_spec is not None else None,
                      after_inject=self._after_inject,
                      before_clear=self._before_clear)
コード例 #3
0
    def test_before_clear_ignored_for_prototype(self):
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            component = Component("test",
                                  strategy="prototype",
                                  before_clear="before_clear")

            self.assertEqual(1, len(w))
            self.assertEqual(
                "ignoring before_clear='before_clear' for prototype component "
                "with ID 'test'", str(w[0].message))

        self.assertIsNone(component.before_clear)
コード例 #4
0
    def test_strategy_must_be_imported_for_member_name(self):
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            component = Component("test.dummy.ModuleClass",
                                  member_name="NestedClass",
                                  strategy="prototype")

            self.assertEqual(1, len(w))
            self.assertEqual(
                "ignoring strategy 'prototype' for component "
                "'test.dummy.ModuleClass' -- strategy MUST be '_imported' "
                "(implicit) if member_name is specified", str(w[0].message))

        self.assertEqual("_imported", component.strategy)
コード例 #5
0
ファイル: context.py プロジェクト: subokita/Aglyph
    def _create_component(self, component_element):
        """Create a component object from a ``<component>`` element.

        :arg xml.etree.ElementTree.Element component_element:
           a ``<component>`` element
        :return:
           an Aglyph component object
        :rtype:
           :class:`aglyph.component.Component`

        """
        return Component(component_element.get("id"),
                         dotted_name=component_element.get("dotted-name"),
                         factory_name=component_element.get("factory-name"),
                         member_name=component_element.get("member-name"),
                         strategy=component_element.get("strategy"),
                         parent_id=component_element.get("parent-id"),
                         after_inject=component_element.get("after-inject"),
                         before_clear=component_element.get("before-clear"))
コード例 #6
0
ファイル: test_Context.py プロジェクト: subokita/Aglyph
 def test_register_rejects_duplicate_id(self):
     self._context["test"] = Component("test")
     self.assertRaises(
         AglyphError, self._context.register, Component("test"))
コード例 #7
0
 def test_member_name_at_init_time(self):
     component = Component("test-class",
                           dotted_name="test.dummy",
                           member_name="ModuleClass")
     self.assertEqual("ModuleClass", component.member_name)
コード例 #8
0
 def test_dotted_name_at_init_time(self):
     component = Component("test-class", dotted_name="test.dummy.Class")
     self.assertEqual("test.dummy.Class", component.dotted_name)
コード例 #9
0
 def setUp(self):
     # for TemplateTest, DependencySupportTest
     self._support = Component("test-component-depsupport")
コード例 #10
0
 def test_weakref_accepts_before_clear(self):
     component = Component("test",
                           strategy="weakref",
                           before_clear="before_clear")
     self.assertEqual("before_clear", component.before_clear)
コード例 #11
0
 def test_singleton_accepts_before_clear(self):
     component = Component("test",
                           strategy="singleton",
                           before_clear="before_clear")
     self.assertEqual("before_clear", component.before_clear)
コード例 #12
0
 def test_strategy_is_imported_by_default_for_member_name(self):
     support = Component("test.dummy.ModuleClass",
                         member_name="NestedClass")
     self.assertEqual("_imported", support.strategy)
コード例 #13
0
 def test_strategy_weakref(self):
     component = Component("test", strategy="weakref")
     self.assertEqual("weakref", component.strategy)
コード例 #14
0
 def test_strategy_borg(self):
     component = Component("test", strategy="borg")
     self.assertEqual("borg", component.strategy)
コード例 #15
0
 def test_strategy_singleton(self):
     component = Component("test", strategy="singleton")
     self.assertEqual("singleton", component.strategy)
コード例 #16
0
 def test_strategy_explicit_prototype(self):
     component = Component("test", strategy="prototype")
     self.assertEqual("prototype", component.strategy)
コード例 #17
0
ファイル: test_Context.py プロジェクト: subokita/Aglyph
 def test_get_component_returns_component(self):
     test_component = Component("test")
     self._context["test"] = test_component
     self.assertTrue(self._context.get_component("test") is test_component)
コード例 #18
0
 def test_before_clear_at_init_time(self):
     component = Component("test",
                           strategy="singleton",
                           before_clear="before_clear")
     self.assertEqual("before_clear", component.before_clear)
コード例 #19
0
 def test_can_augment_context_after_parsing(self):
     component = Component(self.id())
     self._context.register(component)
     self.assertTrue(self._context[self.id()] is component)