File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
src/neo4j_graphrag/experimental/pipeline
tests/unit/experimental/pipeline Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,11 @@ def __new__(
37
37
# extract required inputs and outputs from the run method signature
38
38
run_method = attrs .get ("run" )
39
39
run_context_method = attrs .get ("run_with_context" )
40
- run = run_context_method or run_method
40
+ run = run_context_method if run_context_method is not None else run_method
41
+ if run is None :
42
+ raise RuntimeError (
43
+ f"You must implement either `run` or `run_with_context` in Component '{ name } '"
44
+ )
41
45
sig = inspect .signature (run )
42
46
attrs ["component_inputs" ] = {
43
47
param .name : {
Original file line number Diff line number Diff line change 16
16
17
17
import pytest
18
18
19
+ from neo4j_graphrag .experimental .pipeline import Component
19
20
from neo4j_graphrag .experimental .pipeline .types .context import RunContext
20
21
from .components import ComponentMultiply , ComponentMultiplyWithContext , IntResultModel
21
22
@@ -73,3 +74,16 @@ async def test_component_run_with_context() -> None:
73
74
)
74
75
assert result .result == 2
75
76
notifier_mock .assert_awaited_once ()
77
+
78
+
79
+ def test_component_missing_method () -> None :
80
+ with pytest .raises (RuntimeError ) as e :
81
+
82
+ class WrongComponent (Component ):
83
+ # we must have either run or run_with_context
84
+ pass
85
+
86
+ assert (
87
+ "You must implement either `run` or `run_with_context` in Component 'WrongComponent'"
88
+ in str (e )
89
+ )
You can’t perform that action at this time.
0 commit comments