Skip to content

Commit

Permalink
pnp config tests
Browse files Browse the repository at this point in the history
  • Loading branch information
woodac committed Dec 18, 2024
1 parent e9c3859 commit c1865b8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,15 +432,20 @@ def validate_config(config: dict) -> dict:
def validate_pnp_config(config: dict) -> None:
"""
Validate the PNP configuration settings.
Args:
config (dict): The configuration dictionary.
Returns:
dict: The validated configuration dictionary.
"""
# Check if PNP is set
if config["survey"]["survey_type"] == "PNP":
# List of values not compatible with PNP
incompatible_settings = ["output_short_form",
incompatible_settings = ["output_ni_full_responses",
"output_mapping_ni_qa",
"output_short_form",
"load_ni_data",
"output_ni_sas",
"output_intram_by_pg_gb"]
Expand All @@ -451,11 +456,11 @@ def validate_pnp_config(config: dict) -> None:
if any(values):
print(
"WARNING: PNP is set. The following settings are not compatible with PNP: "
"output_short_form, load_ni_data, output_ni_sas, output_intram_by_pg_gb.
" User config will be updated to False."
"output_ni_full_responses, output_mapping_ni_qa, output_short_form, load_ni_data,"
" output_ni_sas, output_intram_by_pg_gb. User config will be updated to False."
)
# Update the config to False for incompatible settings
for setting in incompatible_settings:
# Update the user config to False
for setting in incompatible_settings:
config["global"][setting] = False

return config
40 changes: 39 additions & 1 deletion tests/test_utils/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
_nulltype_conversion,
validate_freezing_config_settings,
validate_construction_config_settings,
validate_freezing_run_config
validate_freezing_run_config,
validate_pnp_config,
validate_config

)


Expand Down Expand Up @@ -609,3 +612,38 @@ def test_validate_freezing_run_config_raises(self):
msg = "Only one type of pipeline run is allowed.*"
with pytest.raises(ValueError, match=msg):
validate_freezing_run_config(config)

class TestValidateConfig (object):
"""Tests for validate_config."""

def test_validate_config(self):

input_config = {
"survey":{ "survey_type": "PNP"},
"global": {
"load_ni_data": True,
}

}
with pytest.raises(ValueError, match="Error: PNP is set. Northern Ireland data cannot be run. Please update "
"the user config.")
validate_config(input_config)

def test_validate_pnp_config(self):

input_config = {
"survey":{ "survey_type": "PNP"},
"global": {
"output_ni_full_responses": True,
"output_mapping_ni_qa": True,
"output_short_form": True,
"load_ni_data": True,
"output_ni_sas": True,
"output_intram_by_pg_gb": True
}

}
results = validate_pnp_config(input_config)
assert results == (False, False, False, False, False, False), (
"PNP config validation returned the expected config values."
)

0 comments on commit c1865b8

Please sign in to comment.