Skip to content

Commit

Permalink
handler request class check
Browse files Browse the repository at this point in the history
  • Loading branch information
nekufa committed Sep 23, 2023
1 parent 3d2988f commit c45284d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
7 changes: 5 additions & 2 deletions sharded_queue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ async def create(cls) -> Self:

@classmethod
def request_cls(cls) -> type[T]:
return list(get_type_hints(cls.handle).values())[0]
cls = list(get_type_hints(cls.handle).values())[0]
if cls is T:
raise NotImplementedError
return cls

@classmethod
async def route(cls, *requests: T) -> list[Route]:
Expand All @@ -41,7 +44,7 @@ async def start(self) -> None:
pass

async def handle(self, *requests: T) -> None:
raise NotImplementedError()
raise NotImplementedError

async def stop(self) -> None:
pass
Expand Down
23 changes: 23 additions & 0 deletions tests/test_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from pytest import mark, raises

from sharded_queue import Handler, Queue, Worker
from sharded_queue.drivers import RuntimeLock, RuntimeStorage
from sharded_queue.protocols import Storage


class AbstractRequest:
...


class AbstractHandler(Handler):
...


@mark.asyncio
async def test_handler() -> None:
storage: Storage = RuntimeStorage()
queue: Queue = Queue(storage)
await queue.register(AbstractHandler, AbstractRequest())

with raises(NotImplementedError):
await Worker(RuntimeLock(), queue).loop(1)

0 comments on commit c45284d

Please sign in to comment.