Example #1
0
async def _(api: Api) -> None:
    component = use_component(RootComponent, api=api)
    assert component.baz("foo", "bar")
    another = use_component(RootAnotherComponent, api=api)
    assert await another.foobar()
    with raises(LookupError):
        use_component(MountedComponent)
Example #2
0
async def _(api: Api, store: type[AnyComponentProtocol]):
    async with api.client():
        store_instance = use_component(store, api=api)
        assert isinstance(store_instance, store)
        store_instance._startup.assert_called_once()
        store_instance._shutdown.assert_not_called()

    store_instance._shutdown.assert_called_once()
Example #3
0
 class MountedView:
     async def on_get(self, req: Request, resp: Response, /,
                      **kw) -> Response:
         try:
             use_component(MountedComponent)
         except KeyError:
             return resp.set_status(
                 HTTPStatus.NOT_FOUND).set_text("not found")
         return resp.set_status(HTTPStatus.OK).set_text("ok")
Example #4
0
async def _(root_api: Api, mounted_api: Api) -> None:
    assert use_component(RootComponent, api=root_api)
    with raises(KeyError):
        use_component(RootComponent, api=mounted_api)
    assert use_component(MountedComponent, api=mounted_api)
    with raises(KeyError):
        use_component(MountedComponent, api=root_api)
Example #5
0
 async def startup(self):
     assert use_component(self.__class__)
Example #6
0
 def baz(self, *args) -> str:
     another = use_component(RootAnotherComponent)
     another.barbaz()
     self._already_in_context()
     return str(args)
Example #7
0
 async def shutdown(self):
     with raises(KeyError):
         use_component(RootComponent)