12
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
# See the License for the specific language governing permissions and
14
14
# limitations under the License.
15
- from .components import ComponentMultiply
15
+ from unittest .mock import MagicMock , AsyncMock
16
+
17
+ import pytest
18
+
19
+ from neo4j_graphrag .experimental .pipeline .types .context import RunContext
20
+ from .components import ComponentMultiply , ComponentMultiplyWithContext , IntResultModel
16
21
17
22
18
23
def test_component_inputs () -> None :
@@ -26,3 +31,41 @@ def test_component_inputs() -> None:
26
31
def test_component_outputs () -> None :
27
32
outputs = ComponentMultiply .component_outputs
28
33
assert "result" in outputs
34
+ assert outputs ["result" ]["has_default" ] is True
35
+ assert outputs ["result" ]["annotation" ] == int
36
+
37
+
38
+ @pytest .mark .asyncio
39
+ async def test_component_run () -> None :
40
+ c = ComponentMultiply ()
41
+ result = await c .run (number1 = 1 , number2 = 2 )
42
+ assert isinstance (result , IntResultModel )
43
+ assert isinstance (
44
+ result .result , ComponentMultiply .component_outputs ["result" ]["annotation" ]
45
+ )
46
+
47
+
48
+ @pytest .mark .asyncio
49
+ async def test_component_run_with_context_default_implementation () -> None :
50
+ c = ComponentMultiply ()
51
+ result = await c .run_with_context (
52
+ # context can not be null in the function signature,
53
+ # but it's ignored in this case
54
+ None , # type: ignore
55
+ number1 = 1 ,
56
+ number2 = 2 ,
57
+ )
58
+ assert result .result == 2
59
+
60
+
61
+ @pytest .mark .asyncio
62
+ async def test_component_run_with_context () -> None :
63
+ c = ComponentMultiplyWithContext ()
64
+ notifier_mock = AsyncMock ()
65
+ result = await c .run_with_context (
66
+ RunContext (run_id = "run_id" , task_name = "task_name" , notifier = notifier_mock ),
67
+ number1 = 1 ,
68
+ number2 = 2 ,
69
+ )
70
+ assert result .result == 2
71
+ notifier_mock .assert_awaited_once ()
0 commit comments