Skip to content

Commit

Permalink
Test for parent param not allowed at node
Browse files Browse the repository at this point in the history
  • Loading branch information
brynpickering committed Nov 10, 2023
1 parent 6d46370 commit fc3ae50
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/calliope/preprocess/model_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,17 @@ def _get_relevant_node_refs(self, techs_dict: AttrDict, node: str) -> list[str]:
):
techs_dict.set_key(key, val + ":" + node)

for tech_dict in techs_dict.values():
for tech_name, tech_dict in techs_dict.items():
if tech_dict is None or not tech_dict.get("active", True):
continue
else:
if "parent" in tech_dict.keys():
raise exceptions.ModelError(
f"(nodes, {node}), (techs, {tech_name}) | Defining a technology `parent` at a node is not supported; "
"limit yourself to defining this parameter within `techs` or `tech_groups`"
)
refs.update(tech_dict.keys())

return list(refs)

def _param_dict_to_array(self, param_name: str, param_data: Param) -> xr.DataArray:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_model_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,20 @@ def test_get_relevant_node_refs_no_ts_data(
refs = model_data_factory._get_relevant_node_refs(techs_dict, "A")
assert set(refs) == set(["key1", "key2", "key3"])

def test_get_relevant_node_refs_parent_at_node_not_supported(
self, model_data_factory: ModelDataFactory
):
techs_dict = AttrDict(
{"bar": {"key1": 1}, "foo": {"parent": "foobar"}, "baz": None}
)
with pytest.raises(exceptions.ModelError) as excinfo:
model_data_factory._get_relevant_node_refs(techs_dict, "A")

assert check_error_or_warning(
excinfo,
"(nodes, A), (techs, foo) | Defining a technology `parent` at a node is not supported",
)

def test_param_dict_to_array_with_defaults(
self, model_data_factory: ModelDataFactory
):
Expand Down

0 comments on commit fc3ae50

Please sign in to comment.