Skip to content

Commit

Permalink
Improve test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
irm-codebase committed Feb 13, 2025
1 parent bc02208 commit 3fc1a0c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
23 changes: 18 additions & 5 deletions tests/schemas_test/data_table_schema_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@


class TestCalliopeDataTable:
@pytest.fixture(scope="class")
@pytest.fixture
def full_data_table_config(self):
return """
return read_rich_yaml("""
data: time_varying_df
rows: timesteps
columns: [comment, nodes, techs]
Expand All @@ -27,15 +27,15 @@ def full_data_table_config(self):
costs: monetary
rename_dims:
location: nodes
"""
""")

@pytest.mark.parametrize(
"data_table",
[{"rows": "timesteps"}, {"rows": "timesteps", "columns": ["techs", "nodes"]}],
)
def test_path_not_provided(self, data_table):
"""Not providing the path should result in a failure."""
with pytest.raises(ValidationError):
with pytest.raises(ValidationError, match="validation error for Data table"):
CalliopeDataTable(**data_table)

@pytest.mark.parametrize("data_table", [{"data": "foo"}])
Expand Down Expand Up @@ -73,7 +73,7 @@ def test_add_dims_overlap(self, rows, columns, add_dims):

def test_full_table_config(self, full_data_table_config):
"""Test a fully fledged data table configuration."""
CalliopeDataTable(**read_rich_yaml(full_data_table_config))
CalliopeDataTable(**full_data_table_config)

@pytest.mark.parametrize("model_path", utils.EXAMPLE_MODELS + utils.TEST_MODELS)
def test_example_models(self, model_path):
Expand All @@ -82,3 +82,16 @@ def test_example_models(self, model_path):
if "data_tables" in model_def:
for data_table_def in model_def["data_tables"].values():
CalliopeDataTable(**data_table_def)

@pytest.mark.parametrize(
("rename_dims", "drop"),
[({"bar": "foo"}, None), ({"locations": "nodes"}, "nodes")],
)
def test_invalid_rename(self, rename_dims, drop, full_data_table_config):
"""Renaming inexistent dimensions should be impossible."""
full_data_table_config.update({"drop": drop, "rename_dims": rename_dims})
with pytest.raises(
ValidationError,
match="Renamed dimensions must be in either rows or columns.",
):
CalliopeDataTable(**full_data_table_config)
7 changes: 7 additions & 0 deletions tests/schemas_test/general_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,10 @@ def test_config_model_no_resolved_refs(self, config_model_submodel):
no_defs_json_schema["properties"]["nested"]
== json_schema["$defs"]["SubModel"]
)

def test_config_model_flat_no_defs(self, config_model_flat):
"""Calling `model_no_ref_schema` should not alter flat models."""
json_schema = config_model_flat.model_json_schema()
no_defs_schema = config_model_flat.model_no_ref_schema()

assert json_schema == no_defs_schema

0 comments on commit 3fc1a0c

Please sign in to comment.