aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tests/test_injector.py
diff options
context:
space:
mode:
authorHsiangNianian <i@jyunko.cn>2025-08-02 11:30:27 +0800
committerHsiangNianian <i@jyunko.cn>2025-08-02 11:30:27 +0800
commitec4566c3d17370c778a1e6cd6b22ed85263731a0 (patch)
tree469258084d3ae0e72db37dd98593731ff20131e4 /tests/test_injector.py
parentc68a18ca6440f6460b3b5fce311901229f8f50a9 (diff)
downloadinfini-ec4566c3d17370c778a1e6cd6b22ed85263731a0.tar.gz
infini-ec4566c3d17370c778a1e6cd6b22ed85263731a0.zip
refactor(v3): publish v3 branch
Diffstat (limited to 'tests/test_injector.py')
-rw-r--r--tests/test_injector.py103
1 files changed, 0 insertions, 103 deletions
diff --git a/tests/test_injector.py b/tests/test_injector.py
deleted file mode 100644
index d6c6d3e8..00000000
--- a/tests/test_injector.py
+++ /dev/null
@@ -1,103 +0,0 @@
-from typing import Dict, List, Optional
-from unittest.mock import Base
-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():
- def name(nickname: str, c: int = 0):
- return nickname, c
-
- def add(a: int, b: int = 0):
- return a + b
-
- injector = Injector()
- injector.parameters = {"a": 12, "b": 20, "c": 10, "nickname": "苏向夜"}
- assert injector.inject(add)() == 32
- assert injector.output(add) == 32
- assert injector.output(name) == ("苏向夜", 10)
-
-
-def test_handler_injector():
- input = Input("test_message")
-
- def absolute(input: Input[str], plain_text: str) -> Output:
- return input.output(
- "text",
- "absolute",
- block=False,
- variables={
- "text": plain_text,
- },
- )
-
- def absolute_2(input: Input[str], plain_text: Optional[str]) -> Output:
- return input.output(
- "text",
- "absolute",
- block=False,
- variables={
- "text": plain_text,
- },
- )
-
- handler = Handler()
- handler.handlers = [
- {
- "priority": 2,
- "router": Startswith(""),
- "handler": absolute,
- },
- {
- "priority": 2,
- "router": Startswith(""),
- "handler": absolute_2,
- },
- ]
-
- core = Loader().into_core()
- core.handler = handler
- core.generator.events = {
- "absolute": "{{ text }}",
- }
-
- for output in core.input(input):
- assert output == "test_message"
-
-
-def test_instance_injector():
- class BaseClass: ...
-
- class Class(BaseClass):
- value = 10
-
- def test(
- a: int,
- base: BaseClass,
- b: int = 0,
- cls: Optional[BaseClass] = None,
- ):
- assert isinstance(base, Class)
- assert isinstance(cls, Class)
- assert cls.value == 10
- return a + b
-
- injector = Injector()
- injector.parameters = {"a": 12, "b": 20, "c": 0, "cls": Class(), "base": Class()}
-
- assert injector.output(test) == 32
-
-
-def test_complex_injector():
- def test(data: Dict[str, Dict[str, List[str]]]):
- assert isinstance(data, dict)
- return data["value"]
-
- injector = Injector()
- injector.parameters = {"data": {"value": 32}}
-
- assert injector.output(test) == 32