Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: passing parameters for graph construction #42

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dagrunner/execute_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def __init__(
Optional global keyword arguments to apply to all applicable plugins.
"""
self._nxgraph = _get_networkx(networkx_graph)
self._nxgraph_kwargs = networkx_graph_kwargs
self._nxgraph_kwargs = networkx_graph_kwargs or {}
self._plugin_executor = plugin_executor
if scheduler not in SCHEDULERS:
raise ValueError(
Expand Down Expand Up @@ -278,7 +278,7 @@ def _process_graph(self):
)

if callable(self._nxgraph):
self._nxgraph = self._nxgraph(self._nxgraph_kwargs)
self._nxgraph = self._nxgraph(**self._nxgraph_kwargs)

exec_graph = {}
for node_id, properties in self._nxgraph.nodes(data=True):
Expand Down
43 changes: 43 additions & 0 deletions dagrunner/tests/execute_graph/test_ExecuteGraph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# (C) Crown Copyright, Met Office. All rights reserved.
#
# This file is part of 'dagrunner' and is released under the BSD 3-Clause license.
# See LICENSE in the root of the repository for full licensing details.
import networkx as nx

from dagrunner.execute_graph import ExecuteGraph


def test___init___graph_non_callable():
"""Passing a non-callable graph to ExecuteGraph."""
dummy_digraph = nx.DiGraph()
exe_graph = ExecuteGraph(dummy_digraph)
assert exe_graph.nxgraph is dummy_digraph


def test___init___graph_callable_no_parameters():
"""Passing a callable graph to ExecuteGraph with no parameters."""
dummy_digraph = nx.DiGraph()
exe_graph = ExecuteGraph(lambda: dummy_digraph)
assert exe_graph.nxgraph is dummy_digraph


def setup_graph_gen_callable(graph):
def gen_graph(param_a, param_b):
graph.add_nodes_from([param_a, param_b])
return graph

return gen_graph


def test___init___graph_callable_with_parameters():
"""Passing a callable graph to ExecuteGraph with parameters."""
dummy_digraph = nx.DiGraph()
graph_gen = setup_graph_gen_callable(dummy_digraph)
exe_graph = ExecuteGraph(
graph_gen, networkx_graph_kwargs={"param_a": "val_a", "param_b": "val_b"}
)

target_graph = nx.DiGraph()
target_graph.add_nodes_from(["val_a", "val_b"])
assert exe_graph.nxgraph is dummy_digraph
assert dummy_digraph.nodes == target_graph.nodes
Loading