Skip to content

Commit

Permalink
modify test_create_check_success()
Browse files Browse the repository at this point in the history
  • Loading branch information
sf-dcp committed Jan 10, 2025
1 parent 89866a9 commit 9410f2d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- unregistered_func_with_args:
args:
min_value: 100
- unregistered_func_without_args
- greater_than # missing args
- greater_than:
args:
min_value: 5
unexpected_key: value
16 changes: 16 additions & 0 deletions dcpy/test/lifecycle/validate/resources/valid_data_checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- in_range:
description: My custom check description.
args:
min_value: 100
max_value: 200
warn_only: true

- greater_than:
args:
min_value: 5
warn_only: false

- greater_than:
args:
min_value: abc # adding this for visibility. Pandera sees this as a valid check
warn_only: false
71 changes: 40 additions & 31 deletions dcpy/test/lifecycle/validate/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,52 @@
signature,
) # used for checking expected attributes in a class signuture

from dcpy.models.dataset import Column
from dcpy.models.dataset import Column, CheckAttributes
from dcpy.lifecycle.validate import utils

from . import RESOURCES


def get_valid_checks():
"""A list of test models.dataset.Column.checks objects."""
with open(RESOURCES / "valid_data_checks.yml") as f:
data_checks = TypeAdapter(
list[str | dict[str, CheckAttributes]]
).validate_python(yaml.safe_load(f))
return data_checks


def get_invalid_checks():
"""A list of test models.dataset.Column.checks objects."""
with open(RESOURCES / "invalid_data_checks.yml") as f:
data_checks = TypeAdapter(
list[str | dict[str, CheckAttributes]]
).validate_python(yaml.safe_load(f))
return data_checks


valid_data_checks = get_valid_checks()
invalid_data_checks = get_invalid_checks()


@pytest.mark.parametrize(
"input_data, expected_pa_check",
[
(
{
"in_range": {
"args": {
"min_value": 100,
"max_value": 200,
},
"warn_only": True,
}
},
pa.Check.in_range(min_value=100, max_value=200, raise_warning=True),
valid_data_checks[0],
pa.Check.in_range(
min_value=100,
max_value=200,
raise_warning=True,
description="My custom check description.",
),
),
(
{"greater_than": {"args": {"min_value": "5"}}},
pa.Check.greater_than(min_value="5", raise_warning=False),
valid_data_checks[1],
pa.Check.greater_than(min_value=5, raise_warning=False),
),
# Adding this case for visibility. You would expect pandera to fail but it doesn't
(
{"greater_than": {"args": {"min_value": "abc"}}},
valid_data_checks[2],
pa.Check.greater_than(min_value="abc"),
),
# TODO: add custom registered check
Expand All @@ -49,29 +67,20 @@ def test_create_check_success(input_data, expected_pa_check):
"input_data, error_message_substring",
[
(
{"invalid_func": {"args": {"min_value": 100}}},
invalid_data_checks[0],
"Unregistered check name",
),
# Unexpected key in check 'args'
(
{"greater_than": {"args": {"min_value": 5, "unexpected_key": "value"}}},
"Invalid argument keys found for check",
invalid_data_checks[1],
"Unregistered check name",
),
# Unexpected key in check's dict (top level)
(
{
"greater_than": {
"args": {"min_value": 5},
"warn_only": True,
"invalid_key": "value",
},
},
"can't be parsed, please check attributes",
invalid_data_checks[2],
"couldn't be created",
),
# Missing args
(
"greater_than",
"couldn't be created",
invalid_data_checks[3],
"Invalid argument keys found for check",
),
],
)
Expand Down

0 comments on commit 9410f2d

Please sign in to comment.