Skip to content

Commit

Permalink
test valid and invalid filter parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-springer committed Dec 18, 2024
1 parent b7d34f7 commit ad2fe15
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
2 changes: 1 addition & 1 deletion rdtools/analysis_chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,7 @@ def plot_degradation_timeseries(self, case, rolling_days=365, **kwargs):
class ValidatedFilterDict(dict):
def __init__(self, valid_keys, *args, **kwargs):
self.valid_keys = valid_keys
self._err_msg = "Key '{0}' is not a valid filter parameters."
self._err_msg = "Key '{0}' is not a valid filter parameter."
super(ValidatedFilterDict, self).__init__(*args, **kwargs)
self._validate_keys()

Expand Down
53 changes: 50 additions & 3 deletions rdtools/test/analysis_chains_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ def test_validated_filter_dict_initialization():

def test_validated_filter_dict_invalid_key_initialization():
valid_keys = ["key1", "key2"]
with pytest.raises(KeyError, match="Key 'key3' is not a valid filter parameters."):
with pytest.raises(KeyError, match="Key 'key3' is not a valid filter parameter."):
ValidatedFilterDict(valid_keys, key1="value1", key3="value3")


Expand All @@ -766,7 +766,7 @@ def test_validated_filter_dict_setitem():
def test_validated_filter_dict_setitem_invalid_key():
valid_keys = ["key1", "key2"]
filter_dict = ValidatedFilterDict(valid_keys)
with pytest.raises(KeyError, match="Key 'key3' is not a valid filter parameters."):
with pytest.raises(KeyError, match="Key 'key3' is not a valid filter parameter."):
filter_dict["key3"] = "value3"


Expand All @@ -781,5 +781,52 @@ def test_validated_filter_dict_update():
def test_validated_filter_dict_update_invalid_key():
valid_keys = ["key1", "key2"]
filter_dict = ValidatedFilterDict(valid_keys)
with pytest.raises(KeyError, match="Key 'key3' is not a valid filter parameters."):
with pytest.raises(KeyError, match="Key 'key3' is not a valid filter parameter."):
filter_dict.update({"key1": "value1", "key3": "value3"})


@pytest.mark.parametrize(
"filter_param",
[
"normalized_filter",
"poa_filter",
"tcell_filter",
"clip_filter",
"hour_angle_filter",
"clearsky_filter",
"sensor_clearsky_filter",
"ad_hoc_filter",
],
)
def test_valid_filter_params(sensor_analysis, filter_param):
sensor_analysis.filter_params[filter_param] = {}
assert filter_param in sensor_analysis.filter_params


def test_invalid_filter_params(sensor_analysis, filter_param="invalid_filter"):
with pytest.raises(KeyError, match=f"Key '{filter_param}' is not a valid filter parameter."):
sensor_analysis.filter_params[filter_param] = {}


@pytest.mark.parametrize(
"filter_param_aggregated",
[
"two_way_window_filter",
"insolation_filter",
"hampel_filter",
"directional_tukey_filter",
"ad_hoc_filter",
],
)
def test_valid_filter_params_aggregated(sensor_analysis, filter_param_aggregated):
sensor_analysis.filter_params_aggregated[filter_param_aggregated] = {}
assert filter_param_aggregated in sensor_analysis.filter_params_aggregated


def test_invalid_filter_params_aggregated(
sensor_analysis, filter_param_aggregated="invalid_filter"
):
with pytest.raises(
KeyError, match=f"Key '{filter_param_aggregated}' is not a valid filter parameter."
):
sensor_analysis.filter_params_aggregated[filter_param_aggregated] = {}

0 comments on commit ad2fe15

Please sign in to comment.