diff options
| author | 2024-01-27 17:20:18 +0800 | |
|---|---|---|
| committer | 2024-01-27 17:20:18 +0800 | |
| commit | 1af6a296318751d9bc7fab1a2bbaf52d1fbf6c69 (patch) | |
| tree | 4958796d1b624b2edf02415f5a0b089d3485d0c1 /tests | |
| parent | d765a067d4781d2703b9976bdd06dc01572a33b7 (diff) | |
| download | infini-1af6a296318751d9bc7fab1a2bbaf52d1fbf6c69.tar.gz infini-1af6a296318751d9bc7fab1a2bbaf52d1fbf6c69.zip | |
:sparkles: test(handler): add new test for interator
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_handlers.py | 27 |
1 files changed, 27 insertions, 0 deletions
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"] |
