-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created unit tests for validation cases
- Loading branch information
Showing
1 changed file
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import pandas as pd | ||
import pytest | ||
|
||
from mbs_results.validation_checks import ( | ||
colnames_clash, | ||
period_and_reference_not_given, | ||
validate_config_datatype_input, | ||
validate_config_repeated_datatypes, | ||
validate_indices, | ||
) | ||
|
||
|
||
def test_colnames_clash(): | ||
test_config = { | ||
"period": "period", | ||
"reference": "reference", | ||
"responses_keep_cols": { | ||
"period": "date", | ||
"reference": "int", | ||
"strata": "str", | ||
}, | ||
"contributors_keep_cols": { | ||
"reference": "int", | ||
"period": "date", | ||
"strata": "str", | ||
}, | ||
"temporarily_remove_cols": [], | ||
} | ||
assert colnames_clash(**test_config) is True | ||
|
||
|
||
def test_period_and_reference_not_given(): | ||
test_config = { | ||
"period": "period", | ||
"reference": "reference", | ||
"responses_keep_cols": { | ||
"reference": "int", | ||
"strata": "str", | ||
}, | ||
"contributors_keep_cols": { | ||
"reference": "int", | ||
"period": "date", | ||
"strata": "str", | ||
}, | ||
"temporarily_remove_cols": [], | ||
} | ||
assert period_and_reference_not_given(**test_config) is True | ||
|
||
|
||
def test_validate_indices(): | ||
dictionary_data = { | ||
"reference": ["1"], | ||
"period": ["202212"], | ||
"target_variable": ["20"], | ||
"strata": ["101"], | ||
} | ||
responses = pd.DataFrame(data=dictionary_data).set_index(["reference", "period"]) | ||
dictionary_data["reference"] = ["2"] | ||
contributors = pd.DataFrame(data=dictionary_data).set_index(["reference", "period"]) | ||
with pytest.raises(ValueError): | ||
validate_indices(responses, contributors) | ||
|
||
|
||
def test_validate_config_datatype_input(): | ||
test_config = { | ||
"period": "period", | ||
"reference": "reference", | ||
"responses_keep_cols": { | ||
"period": "date", | ||
"reference": "int", | ||
}, | ||
"contributors_keep_cols": { | ||
"reference": "int", | ||
"period": "date", | ||
"strata": "string", | ||
}, | ||
"temporarily_remove_cols": [], | ||
} | ||
with pytest.raises(ValueError): | ||
validate_config_datatype_input(**test_config) | ||
|
||
|
||
def test_validate_config_repeated_datatypes(): | ||
test_config = { | ||
"period": "period", | ||
"reference": "reference", | ||
"responses_keep_cols": { | ||
"period": "date", | ||
"reference": "int", | ||
}, | ||
"contributors_keep_cols": { | ||
"reference": "int", | ||
"period": "str", | ||
"strata": "str", | ||
}, | ||
"temporarily_remove_cols": [], | ||
} | ||
with pytest.raises(ValueError): | ||
validate_config_repeated_datatypes(**test_config) |