Exemplo n.º 1
0
    def test_this_second_thing(self):

        load_injection_container("../")
        test_vehicle: Vehicle = inject("bicycle")
        test_vehicle.forward()

        test_vehicle: Vehicle = inject("car")
        test_vehicle.forward()
    def test__load_injection_container__with_explicit_namespace(
            self, get_caller_filepath_mock, injection_container_mock):
        # given
        get_caller_filepath_mock.return_value = os.path.join(
            "fake", "path", "file.py")
        default_namespace = "TEST_NAMESPACE"

        # when
        load_injection_container(default_namespace=default_namespace)

        # then
        load = injection_container_mock.load_dependencies_from
        assert load.called is True
        default_namespace_arg = load.call_args[0][1]
        assert default_namespace_arg == default_namespace
    def test__load_injection_container__with_absolute_search_path(
            self, get_caller_filepath_mock, injection_container_mock):
        # given
        root = "/" if os.name != "nt" else "C:\\"
        search_path = os.path.join(root, "fake", "path")

        # when
        load_injection_container(search_path)

        # then
        assert get_caller_filepath_mock.called is False
        load = injection_container_mock.load_dependencies_from
        assert load.called is True
        search_path_arg = load.call_args[0][0]
        assert search_path_arg == search_path
    def test__load_injection_container__with_defaults(
            self, get_caller_filepath_mock, injection_container_mock):
        # given
        filedir = os.path.join("fake", "path")
        filepath = os.path.join(filedir, "file.py")
        get_caller_filepath_mock.return_value = filepath

        # when
        load_injection_container()

        # then
        assert get_caller_filepath_mock.called is True
        load = injection_container_mock.load_dependencies_from
        assert load.called is True
        search_path_arg, default_namespace_arg = load.call_args[0][:2]
        assert search_path_arg == filedir
        assert default_namespace_arg == DEFAULT_NAMESPACE
    def test__load_injection_container__with_relative_search_path(
            self, get_caller_filepath_mock, injection_container_mock):
        # given
        root = "/" if os.name != "nt" else "C:\\"
        filepath = os.path.join(root, "fake", "path", "file.py")
        get_caller_filepath_mock.return_value = filepath
        search_path = os.path.join("..", "relative", "path")
        expected_path = os.path.join(root, "fake", "relative", "path")

        # when
        load_injection_container(search_path)

        # then
        assert get_caller_filepath_mock.called is True
        load = injection_container_mock.load_dependencies_from
        assert load.called is True
        search_path_arg = load.call_args[0][0]
        assert search_path_arg == expected_path
Exemplo n.º 6
0
# sphinx-start
from typing import Optional, List

from examples import Example
from injectable import autowired, Autowired, injectable, load_injection_container


@injectable  # make examples also injectable for testing
class OptionalInjection(Example):
    @autowired
    def __init__(
            self,
            some_service: Autowired(Optional["foo"]),
            bunch_of_services: Autowired(Optional[List["bar"]]),
    ):
        self.some_service = some_service
        self.bunch_of_services = bunch_of_services

    def run(self):
        print(self.some_service)
        # None

        print(self.bunch_of_services)
        # []


if __name__ == "__main__":
    load_injection_container()
    example = OptionalInjection()
    example.run()
Exemplo n.º 7
0
def run_example():
    load_injection_container()
    example = LazyInjection()
    example.run()
Exemplo n.º 8
0
def run_example():
    load_injection_container()
    example = Factory()
    example.run()
Exemplo n.º 9
0
def test_issue_30_fix():
    reset_injection_container()
    load_injection_container()
    f()
Exemplo n.º 10
0
def run_example():
    load_injection_container()
    example = ServiceLocator()
    example.run()
Exemplo n.º 11
0
def test_issue_8_fix():
    reset_injection_container()
    load_injection_container()
    bar()
def run_example():
    load_injection_container()
    example = OptionalInjection()
    example.run()
Exemplo n.º 13
0
def run_example():
    load_injection_container()
    example = Namespaces()
    example.run()
Exemplo n.º 14
0
def run_example():
    load_injection_container()
    example = IllustrativeExample()
    example.run()
def run_example():
    load_injection_container()
    example = CyclicDependency()
    example.run()
Exemplo n.º 16
0
def run_example():
    load_injection_container()
    example = Singletons()
    example.run()
def run_example():
    load_injection_container()
    example = DependenciesPrecedence()
    example.run()
Exemplo n.º 18
0
def run_example():
    load_injection_container()
    example = InjectingExistingInstance()
    example.run()
def run_example():
    load_injection_container()
    example = QualifierOverloading()
    example.run()
Exemplo n.º 20
0
def test_issue_80_fix():
    load_injection_container()
    bar()
Exemplo n.º 21
0
def run_example():
    load_injection_container("../")
    example = InjectableMocking()
    example.run()
Exemplo n.º 22
0
def run_example():
    load_injection_container()
    example = BasicUsage()
    example.run()