How to use the injectable.autowired function in injectable

To help you get started, we’ve selected a few injectable examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github allrod5 / injectable / tests / test_autowired.py View on Github external
def test_positional_arg_as_injectable_raises_type_error(self):
        with pytest.raises(TypeError):
            autowired(['b'])(foo)
github allrod5 / injectable / tests / test_autowired.py View on Github external
def test_autowiring(self):
        caller_args = (False, None, True)
        caller_kwargs = {
            'w': {},
            'x': "string",
            'f': lambda x: print(x),
            'kwargs': {'extra': True},
        }

        _, kwargs = autowired()(foo)(*caller_args, **caller_kwargs)

        assert isinstance(kwargs['y'], bool)
        assert isinstance(kwargs['z'], DummyClass)
        assert isinstance(kwargs['l'], DummyClass)
        assert isinstance(kwargs['s'], DummyClass)
github allrod5 / injectable / tests / test_autowired.py View on Github external
def test_injectable_with_non_instantiable_class_raises_type_error(self):
        # eligible injectable argument is annotated with non
        # instantiable class
        with pytest.raises(TypeError):
            autowired()(baz)
        with pytest.raises(TypeError):
            autowired()(qux)

        # specified argument for injection is annotated with non
        # instantiable class
        with pytest.raises(TypeError):
            autowired(['nope'])(baz)
        with pytest.raises(TypeError):
            autowired(['nope'])(qux)
github allrod5 / injectable / tests / test_examples.py View on Github external
    @autowired(lazy=True)
    def __init__(self, *, dep1: CircularDependant1, dep2: CircularDependant2):
        self.dep1 = dep1
        self.dep2 = dep2
github allrod5 / injectable / tests / test_autowired.py View on Github external
def test_missing_kwonly_args_raises_type_error(self):
        with pytest.raises(TypeError):
            autowired()(foo)(a=None, b=10, c='')
github allrod5 / injectable / tests / test_autowired.py View on Github external
def test_injectable_lazy_initialization(self):
        caller_args = (False, None, True)
        caller_kwargs = {
            'w': {},
            'x': "string",
            'f': lambda x: print(x),
            'kwargs': {'extra': True},
        }

        _, kwargs = autowired()(foo)(*caller_args, **caller_kwargs)

        assert isinstance(kwargs['l'], Proxy)
        assert isinstance(kwargs['l'], DummyClass)
        assert kwargs['l'].dummy_method() == 42
github allrod5 / injectable / examples / singletons / main.py View on Github external
    @autowired
    def __init__(
        self,
        composite_singleton: Autowired(CompositeSingleton),
        simple_singleton: Autowired(SimpleSingleton),
    ):
        self.composite_singleton = composite_singleton
        self.simple_singleton = simple_singleton
github allrod5 / injectable / examples / basic_usage / main.py View on Github external
    @autowired
    def __init__(
        self,
        simple_service: Autowired(SimpleService),
        dependable_service: Autowired(DependableService),
    ):
        self.simple_service = simple_service
        self.dependable_service = dependable_service
github allrod5 / injectable / examples / factory / factory_example.py View on Github external
    @autowired
    def __init__(
        self, client: Autowired(ExternalClient),
    ):
        self.client = client
github allrod5 / injectable / examples / cyclic_dependency / service_a.py View on Github external
    @autowired
    def __init__(self, service_b: Autowired("B", lazy=True)):
        self.service_b = service_b
        self.some_property = "some property from A"