diff options
| author | 2024-03-04 11:48:35 +0800 | |
|---|---|---|
| committer | 2024-03-04 11:48:35 +0800 | |
| commit | c5943be36fcdf442a92e2a4a4fc7fa03fbefc268 (patch) | |
| tree | 70bb997e6ed9efa6be7a0e3d916e575a81186a49 | |
| parent | 0f32d6f3520e03a48f9143f2a4f7e48be7742e9b (diff) | |
| download | infini-c5943be36fcdf442a92e2a4a4fc7fa03fbefc268.tar.gz infini-c5943be36fcdf442a92e2a4a4fc7fa03fbefc268.zip | |
feat(test): update tests for injector changes
| -rw-r--r-- | tests/test_injector.py | 32 | ||||
| -rw-r--r-- | tests/test_interceptor.py | 6 |
2 files changed, 36 insertions, 2 deletions
diff --git a/tests/test_injector.py b/tests/test_injector.py index 426e5684..ccd040ba 100644 --- a/tests/test_injector.py +++ b/tests/test_injector.py @@ -1,4 +1,9 @@ +from infini.handler import Handler from infini.injector import Injector +from infini.input import Input +from infini.loader import Loader +from infini.output import Output +from infini.router import Startswith def test_injector(): @@ -12,3 +17,30 @@ def test_injector(): injector.parameters = {"a": 12, "b": 20, "c": 0, "card_name": name} assert injector.inject(add)() == 32 assert injector.output(add) == 32 + + +def test_handler_injector(): + input = Input("test_message") + + def absolute(input: Input, plain_text: str) -> Output: + return input.output( + "text", + plain_text, + status=0, + block=False, + ) + + handler = Handler() + handler.handlers = [ + { + "priority": 2, + "router": Startswith(".add"), + "handler": absolute, + }, + ] + + core = Loader().into_core() + core.handler = handler + + for output in core.input(input): + assert output == "test_message" diff --git a/tests/test_interceptor.py b/tests/test_interceptor.py index ffb03d56..ded63471 100644 --- a/tests/test_interceptor.py +++ b/tests/test_interceptor.py @@ -27,10 +27,12 @@ def test_interceptor(): assert isinstance(valid_output, Input) assert valid_output.get_plain_text() == "这个叫苏向夜." - for output in interceptor.output("简律纯"): + for output in interceptor.output(Output("text", "none", block=True), "简律纯"): assert isinstance(output, Output) assert output.name == "block.jianlvchun" - for output in interceptor.output("这个叫苏向夜."): + for output in interceptor.output( + Output("text", "none", block=True), "这个叫苏向夜." + ): assert isinstance(output, str) assert output == "这个叫苏向夜." |
