Skip to content

Commit

Permalink
Created unit tests for validation cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Jday7879 committed Jul 1, 2024
1 parent 0ef3a27 commit b0e731c
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions tests/test_validation_checks.py
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)

0 comments on commit b0e731c

Please sign in to comment.