Exemplo n.º 1
0
    def test_if_adding_already_registered_sub_container_throws_error(self):
        container_class = self.container()
        container = container_class('container')
        sub_container = SimpleContainer(name='sub_container')

        container.add_sub_container(sub_container)
        with pytest.raises(KeyError):
            container.add_sub_container(sub_container)
Exemplo n.º 2
0
    def test_if_adding_and_getting_sub_container_return_same_instance(self):
        container_class = self.container()
        container = container_class('container')
        sub_container = SimpleContainer(name='sub_container')
        container.add_sub_container(sub_container)
        ret = container.get_sub_container('sub_container')

        assert isinstance(ret, SimpleContainer)
        assert ret is sub_container
Exemplo n.º 3
0
    def test_1(self):
        container_class = self.get_container()
        container = container_class('componenet')
        container.register_callable(TEST_CLASS_2_NAME, TestClass2)

        sub_container = SimpleContainer(name='sub')
        sub_container.register_callable(TEST_CLASS_1_NAME, TestClass1)

        container.add_sub_container(sub_container)

        ret1 = container.resolve(TEST_CLASS_2_NAME)
        assert isinstance(ret1, TestClass2)

        ret2 = container.resolve('%s__%s' % ('sub', TEST_CLASS_1_NAME))
        assert isinstance(ret2, TestClass1)
Exemplo n.º 4
0
    def test_if_container_returns_list_of_registered_objects_including_subcontainers(
            self):
        container_class = self.container()
        container = container_class('container')

        sub_container = SimpleContainer(name='sub_container')
        sub_container.register_callable(TEST_CLASS_2_NAME, TestClass2)

        container.add_sub_container(sub_container)
        container.register_callable(TEST_CLASS_1_NAME, TestClass1)

        registered_keys = container.get_all_keys()

        assert TEST_CLASS_1_NAME in registered_keys['container']
        assert TEST_CLASS_2_NAME in registered_keys['sub_container']
        assert len(registered_keys) == 2
Exemplo n.º 5
0
 def test_adding_sub_containers(self):
     container_class = self.container()
     container = container_class('container')
     container.add_sub_container(SimpleContainer('sub_container_1'))