Beispiel #1
0
 def test_creates_container():
     """should create new container and use it"""
     container = get_container()
     with use_container() as actual:
         assert actual is not None
         assert actual != container
         assert get_container() == actual
     assert get_container() == container
Beispiel #2
0
 def test_uses_passed_container():
     """should create new container and use it"""
     container = get_container()
     new_container = Container()
     with use_container(new_container) as actual:
         assert actual == new_container
         assert get_container() == actual
     assert get_container() == container
Beispiel #3
0
def test_add_function_resolver(dependency, function):
    """should add FunctionResolver to current container"""
    with use_container() as container:
        add_function_resolver(dependency, function)

        resolver = container.get_resolver(dependency)
        assert isinstance(resolver, FunctionResolver)
        assert resolver.resolve(container) == function(container)
Beispiel #4
0
def test_add_singleton(dependency, value):
    """add_singleton() should add SingletonResolver to current container"""
    with use_container() as container:
        add_singleton(dependency, value)

        resolver = container.get_resolver(dependency)
        assert isinstance(resolver, SingletonResolver)
        assert resolver.resolve(container) == value
Beispiel #5
0
def test_add_type(dependency, type_):
    """add_type() should add type resolver to current container"""
    with use_container() as container:
        add_type(dependency, TestType)
        resolver = container.get_resolver(dependency)

        actual = resolver.resolve(container)

        assert isinstance(actual, type_)
Beispiel #6
0
def container_fixture(request):
    with use_container() as container:
        request.cls.container = container
        yield container
Beispiel #7
0
def test_resolve(dependency, resolver):
    """resolve() should resolve dependency using current container"""
    with use_container() as container:
        add_resolver(dependency, resolver)

        assert resolve(dependency) == container.resolve(dependency)
Beispiel #8
0
def inject_fixture():
    with use_container() as container:
        yield container
Beispiel #9
0
def test_add_resolver(dependency, resolver):
    """add_resolver() should add dependency resolver to current container"""
    with use_container() as container:
        add_resolver(dependency, resolver)

        assert container.get_resolver(dependency) == resolver