Пример #1
0
    def test_if_returns_instance_of_a_class(self, mock_container):
        provider = LazySingleInstanceWithDepsProvider(TestClass1,
                                                      mock_container)

        ret1 = provider.get_instance()

        assert isinstance(ret1, TestClass1)
Пример #2
0
    def test_if_provider_inject_registered_deps_to_function(self, mock_container):
        def func_with_deps(testclass1):
            return testclass1

        provider = LazySingleInstanceWithDepsProvider(func_with_deps, mock_container)

        ret1 = provider.get_instance()

        assert isinstance(ret1, TestClass1)
Пример #3
0
    def test_if_returns_different_instance_of_a_class(self, mock_container):
        provider = LazySingleInstanceWithDepsProvider(TestClass1, mock_container)

        ret1 = provider.get_instance()
        ret2 = provider.get_instance()

        assert isinstance(ret1, TestClass1)
        assert isinstance(ret2, TestClass1)
        assert ret1 is ret2
Пример #4
0
    def test_if_provider_inject_registered_deps_to_function(
            self, mock_container):
        def func_with_deps(testclass1):
            return testclass1

        provider = LazySingleInstanceWithDepsProvider(func_with_deps,
                                                      mock_container)

        ret1 = provider.get_instance()

        assert isinstance(ret1, TestClass1)
Пример #5
0
 def test_if_provider_raise_error_when_initialized_with_not_callable(
         self, mock_container):
     with pytest.raises(TypeError):
         LazySingleInstanceWithDepsProvider(1, mock_container)