def _instantiate_nodes( graph_schema: GraphSchema, model_storage: ModelStorage, execution_context: ExecutionContext, hooks: Optional[List[GraphNodeHook]] = None, ) -> Dict[Text, GraphNode]: return { node_name: GraphNode.from_schema_node(node_name, schema_node, model_storage, execution_context, hooks) for node_name, schema_node in graph_schema.nodes.items() }
def test_exception_handling_for_on_before_hook( on_before: Callable, on_after: Callable, default_model_storage: ModelStorage, default_execution_context: ExecutionContext, ): schema_node = SchemaNode( needs={}, uses=ProvideX, fn="provide", constructor_name="create", config={}, ) class MyHook(GraphNodeHook): def on_after_node( self, node_name: Text, execution_context: ExecutionContext, config: Dict[Text, Any], output: Any, input_hook_data: Dict, ) -> None: on_before() def on_before_node( self, node_name: Text, execution_context: ExecutionContext, config: Dict[Text, Any], received_inputs: Dict[Text, Any], ) -> Dict: on_after() return {} node = GraphNode.from_schema_node( "some_node", schema_node, default_model_storage, default_execution_context, hooks=[MyHook()], ) with pytest.raises(GraphComponentException): node()