diff options
Diffstat (limited to 'tests/test_handlers.py')
| -rw-r--r-- | tests/test_handlers.py | 96 |
1 files changed, 0 insertions, 96 deletions
diff --git a/tests/test_handlers.py b/tests/test_handlers.py deleted file mode 100644 index 79810ce0..00000000 --- a/tests/test_handlers.py +++ /dev/null @@ -1,96 +0,0 @@ -from infini.handler import Handler -from infini.input import Input -from infini.output import Output -from infini.router import Startswith - - -def test_handler(): - input = Input(".add 1 2") - - def add(input: Input) -> Output: - return Output( - "text", - str(sum(list(map(int, input.get_plain_text().lstrip(".add").split())))), - block=False, - ) - - def cmd(_: Input) -> Output: - return Output("text", "cmd", block=False) - - handler = Handler() - handler.handlers = [ - { - "priority": 2, - "router": Startswith(".add"), - "handler": add, - }, - { - "priority": 1, - "router": Startswith("."), - "handler": cmd, - }, - ] - - names = [] - for output in handler.input(input): - names.append(output.name) - assert names == ["cmd", "3"] - - -def test_handler_block(): - input = Input(".add 1 2") - - def add(input: Input) -> Output: - return Output( - "text", - str(sum(list(map(int, input.get_plain_text().lstrip(".add").split())))), - block=False, - ) - - def cmd(_: Input) -> Output: - return Output("text", "cmd", block=True) - - handler = Handler() - handler.handlers = [ - { - "priority": 2, - "router": Startswith(".add"), - "handler": add, - }, - { - "priority": 1, - "router": Startswith("."), - "handler": cmd, - }, - ] - - names = [] - for output in handler.input(input): - names.append(output.name) - assert names == ["cmd"] - - -def test_handler_interator(): - input = Input(".add 1 2") - - def add(input: Input): - yield Output( - "text", - str(sum(list(map(int, input.get_plain_text().lstrip(".add").split())))), - block=False, - ) - yield Output("text", "ok", block=False) - - handler = Handler() - handler.handlers = [ - { - "priority": 1, - "router": Startswith(".add"), - "handler": add, - }, - ] - - names = [] - for output in handler.input(input): - names.append(output.name) - assert names == ["3", "ok"] |
