Exemplo n.º 1
0
    class IMDBMovieDB(MovieDB, Service):
        __antidote__ = Service.Conf(singleton=False)

        def __init__(self, imdb_api: Annotated[ImdbAPI, From(imdb_factory)]):
            self._imdb_api = imdb_api

        def get_best_movies(self):
            pass
Exemplo n.º 2
0
        class DummyB(Service):
            __antidote__ = Service.Conf()

            def __init__(self, s: Provide[Service1]):
                pass

            def get(self, s: Provide[Service1]):
                pass
Exemplo n.º 3
0
        class DummyC(Service):
            __antidote__ = Service.Conf().with_wiring(
                methods=['__init__', 'get'])

            def __init__(self):
                pass

            def get(self, my_service: Provide[Service1]):
                pass
Exemplo n.º 4
0
    class IMDBMovieDB(MovieDB, Service):
        __antidote__ = Service.Conf(singleton=False)  # New instance each time

        @inject({'imdb_api': ImdbAPI @ imdb_factory})
        def __init__(self, imdb_api: ImdbAPI):
            self._imdb_api = imdb_api

        def get_best_movies(self):
            pass
Exemplo n.º 5
0
        class Service3(Service):
            __antidote__ = Service.Conf(singleton=False).with_wiring(
                dependencies=dict(i=Interface @ impl,
                                  service2=Service2 @ BuildS2))

            def __init__(self, service1: Provide[Service1], service2: Service2,
                         i: Interface):
                self.service1 = service1
                self.service2 = service2
                self.i = i

            def get(self, service1: Provide[Service1]):
                pass

            X = LazyMethodCall(get)
Exemplo n.º 6
0
def test_conf_repr():
    conf = Service.Conf()
    assert "scope" in repr(conf)
Exemplo n.º 7
0
def test_invalid_copy():
    conf = Service.Conf()
    with pytest.raises(TypeError, match=".*both.*"):
        conf.copy(singleton=False, scope=None)
Exemplo n.º 8
0
def test_conf_copy(kwargs):
    conf = Service.Conf(singleton=True).copy(**kwargs)
    for k, v in kwargs.items():
        assert getattr(conf, k) == v
Exemplo n.º 9
0
def test_invalid_conf_args(kwargs, expectation):
    with expectation:
        Service.Conf(**kwargs)
Exemplo n.º 10
0
 class A(Service):
     __antidote__ = Service.Conf(parameters=parameters)
Exemplo n.º 11
0
 class Scoped(Service):
     __antidote__ = Service.Conf(scope=dummy_scope)
Exemplo n.º 12
0
 class Service1(Service):
     __antidote__ = Service.Conf(parameters=['test'])
Exemplo n.º 13
0
 class MyService(Service):
     __antidote__ = Service.Conf(scope=dummy_scope)
Exemplo n.º 14
0
        class DummyA(Service):
            __antidote__ = Service.Conf(wiring=None)

            @inject
            def __init__(self, service: Provide[Service1]):
                pass
Exemplo n.º 15
0
 class Singleton(Service):
     __antidote__ = Service.Conf(singleton=True)
Exemplo n.º 16
0
 class NoScope(Service):
     __antidote__ = Service.Conf(singleton=False)
Exemplo n.º 17
0
        class A(Service):
            __antidote__ = Service.Conf(parameters=['x'])

            def __init__(self, x: str = 'default'):
                self.x = x
Exemplo n.º 18
0
    class A(Service):
        __antidote__ = Service.Conf(parameters=['x'])

        def __init__(self, **kwargs):
            self.kwargs = kwargs
Exemplo n.º 19
0
        class B(Service):
            __antidote__ = Service.Conf(parameters=['x'])

            def __init__(self, x: Provide[A]):
                self.x = x