Skip to content

Commit

Permalink
Refactor the tests to check old and new signature
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhuppmann committed Mar 14, 2024
1 parent 455eecf commit 595be43
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions tests/test_feature_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,20 +238,36 @@ def test_validate_top_level(test_df):
assert list(test_df.exclude) == [False, True]


def test_category_none(test_df):
test_df.categorize("category", "Testing", {"Primary Energy": {"up": 0.8}})
# include args for deprecated legacy signature
@pytest.mark.parametrize(
"args",
(
dict(variable="Primary Energy", upper_bound=0),
dict(criteria={"Primary Energy": {"up": 0}}),
),
)
def test_category_no_match(test_df, args):
test_df.categorize("category", "foo", **args)
assert "category" not in test_df.meta.columns


def test_category_pass(test_df):
# include args for deprecated legacy signature
@pytest.mark.parametrize(
"args",
(
dict(variable="Primary Energy", upper_bound=6),
dict(criteria={"Primary Energy": {"up": 6}}),
),
)
def test_category_match(test_df, args):
dct = {
"model": ["model_a", "model_a"],
"scenario": ["scen_a", "scen_b"],
"category": ["foo", None],
}
exp = pd.DataFrame(dct).set_index(["model", "scenario"])["category"]

test_df.categorize("category", "foo", {"Primary Energy": {"up": 6, "year": 2010}})
test_df.categorize("category", "foo", **args)
obs = test_df["category"]
pd.testing.assert_series_equal(obs, exp)

Expand Down

0 comments on commit 595be43

Please sign in to comment.