Exemple #1
0
    class Test(Service):
        def get(self):
            return object()

        A = LazyMethodCall(get, singleton=True)
        B = LazyMethodCall(get, singleton=False)
        C = LazyMethodCall(get)
Exemple #2
0
        class Conf(Service):
            def fetch(self, value, service: Provide[MyService]):
                return value

            DATA = LazyMethodCall(fetch)
            KW = LazyMethodCall(fetch)(value='1')
            DATA2 = LazyMethodCall(fetch, singleton=False)
            KW2 = LazyMethodCall(fetch, singleton=False)(value='2')
Exemple #3
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 #4
0
    class Test(Service):
        def get(self):
            return "Hello"

        A = LazyMethodCall(get)
Exemple #5
0
    class Test(Service):
        def get(self, s):
            return s

        A = LazyMethodCall(get)(x)
Exemple #6
0
    class Dummy:
        def get(self, x):
            pass

        A = LazyMethodCall(get)
        B = LazyMethodCall(get)(x=1)
Exemple #7
0
def test_invalid_lazy_method_call():
    with pytest.raises(TypeError, match=".*method.*"):
        LazyMethodCall(method=object())

    with pytest.raises(TypeError, match=".*singleton.*"):
        LazyMethodCall(method=lambda: None, singleton=object())
Exemple #8
0
    class Test(Service):
        def get(self, *args_, **kwargs_):
            return args_, kwargs_

        A = LazyMethodCall(get)(*args, **kwargs)