From 1af6a296318751d9bc7fab1a2bbaf52d1fbf6c69 Mon Sep 17 00:00:00 2001 From: 苏向夜 Date: Sat, 27 Jan 2024 17:20:18 +0800 Subject: :sparkles: test(handler): add new test for interator --- tests/test_handlers.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/test_handlers.py b/tests/test_handlers.py index bf9dd9a0..00bb6f84 100644 --- a/tests/test_handlers.py +++ b/tests/test_handlers.py @@ -70,3 +70,30 @@ def test_handler_block(): 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())))), + status=0, + block=False, + ) + yield Output("text", "ok", status=0, block=False) + + handler = Handler() + handler.handlers = [ + { + "priority": 1, + "router": StartswithRouter(".add"), + "handler": add, + }, + ] + + names = [] + for output in handler.input(input): + names.append(output.name) + assert names == ["3", "ok"] -- cgit v1.2.3-70-g09d2