async def test_services_from_normalization(): app_services = Services() def handler(services): assert services is app_services return None method = normalize_handler(Route(b"/", handler), app_services) await method(None)
def normalize_handlers(self): configured_handlers = set() for route in self.router: if route.handler in configured_handlers: continue route.handler = normalize_handler(route, self.services) configured_handlers.add(route.handler) configured_handlers.clear()
async def test_services_from_normalization(): app_services = {} def handler(services): assert services is app_services return services method = normalize_handler(Route(b'/', handler), app_services) services = await method(None) assert services is app_services
def test_raises_for_unsupported_signature(): app_services = Services() def handler(services, *args): assert services is app_services return services def handler2(services, **kwargs): assert services is app_services return services def handler3(services, *, key_only): assert services is app_services return services with pytest.raises(UnsupportedSignatureError): normalize_handler(Route(b"/", handler), Services()) with pytest.raises(UnsupportedSignatureError): normalize_handler(Route(b"/", handler2), Services()) with pytest.raises(UnsupportedSignatureError): normalize_handler(Route(b"/", handler3), Services())