Skip to content

Commit

Permalink
add unit tests for ValidatedFilterDict
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-springer committed Dec 18, 2024
1 parent 9430250 commit b7d34f7
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions rdtools/test/analysis_chains_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from rdtools import TrendAnalysis, normalization, filtering
from conftest import assert_isinstance, assert_warnings
from rdtools.analysis_chains import ValidatedFilterDict
import pytest
import pvlib
import pandas as pd
Expand Down Expand Up @@ -740,3 +741,45 @@ def test_plot_degradation_timeseries(sensor_analysis, clearsky_analysis):
assert_isinstance(
clearsky_analysis.plot_degradation_timeseries("clearsky"), plt.Figure
)


def test_validated_filter_dict_initialization():
valid_keys = ["key1", "key2"]
filter_dict = ValidatedFilterDict(valid_keys, key1="value1", key2="value2")
assert filter_dict["key1"] == "value1"
assert filter_dict["key2"] == "value2"


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."):
ValidatedFilterDict(valid_keys, key1="value1", key3="value3")


def test_validated_filter_dict_setitem():
valid_keys = ["key1", "key2"]
filter_dict = ValidatedFilterDict(valid_keys)
filter_dict["key1"] = "value1"
assert filter_dict["key1"] == "value1"


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."):
filter_dict["key3"] = "value3"


def test_validated_filter_dict_update():
valid_keys = ["key1", "key2"]
filter_dict = ValidatedFilterDict(valid_keys)
filter_dict.update({"key1": "value1", "key2": "value2"})
assert filter_dict["key1"] == "value1"
assert filter_dict["key2"] == "value2"


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."):
filter_dict.update({"key1": "value1", "key3": "value3"})

0 comments on commit b7d34f7

Please sign in to comment.