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

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

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

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

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

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

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