Exemple #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
Exemple #2
0
        class DummyB(Service):
            __antidote__ = Service.Conf()

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

            def get(self, s: Provide[Service1]):
                pass
Exemple #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
Exemple #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
Exemple #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)
Exemple #6
0
def test_conf_repr():
    conf = Service.Conf()
    assert "scope" in repr(conf)
Exemple #7
0
def test_invalid_copy():
    conf = Service.Conf()
    with pytest.raises(TypeError, match=".*both.*"):
        conf.copy(singleton=False, scope=None)
Exemple #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
Exemple #9
0
def test_invalid_conf_args(kwargs, expectation):
    with expectation:
        Service.Conf(**kwargs)
Exemple #10
0
 class A(Service):
     __antidote__ = Service.Conf(parameters=parameters)
Exemple #11
0
 class Scoped(Service):
     __antidote__ = Service.Conf(scope=dummy_scope)
Exemple #12
0
 class Service1(Service):
     __antidote__ = Service.Conf(parameters=['test'])
Exemple #13
0
 class MyService(Service):
     __antidote__ = Service.Conf(scope=dummy_scope)
Exemple #14
0
        class DummyA(Service):
            __antidote__ = Service.Conf(wiring=None)

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

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

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

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