Skip to content

Commit

Permalink
fix: Correct type check problems in main.py and validate.py and
Browse files Browse the repository at this point in the history
test_validate.py.
  • Loading branch information
gkapfham committed Jul 18, 2023
1 parent 7614241 commit de57a7b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
8 changes: 2 additions & 6 deletions chasten/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def validate_file(
configuration_file_str: str,
configuration_file_yml: str,
yml_data_dict: Dict[str, Dict[str, Any]],
json_schema: Dict[str, Dict[str, Any]] = validate.JSON_SCHEMA_CONFIG,
json_schema: Dict[str, Any] = validate.JSON_SCHEMA_CONFIG,
) -> None:
"""Validate the provided file."""
# perform the validation of the configuration file
Expand Down Expand Up @@ -167,14 +167,10 @@ def configure(
validate.JSON_SCHEMA_CONFIG,
)
# if one or more exist, retrieve the name of the checks files
(found_checks_file, checks_file_name_list) = validate.extract_checks_file_name(
yml_data_dict
)
output.console.print(found_checks_file)
(_, checks_file_name_list) = validate.extract_checks_file_name(yml_data_dict)
# iteratively extract the contents of each checks file
# and then validate the contents of that checks file
for checks_file_name in checks_file_name_list:
output.console.print(checks_file_name)
(
configuration_file_str,
configuration_file_yml,
Expand Down
2 changes: 1 addition & 1 deletion chasten/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def extract_checks_file_name(

def validate_configuration(
configuration: Dict[str, Dict[str, Any]],
schema: Dict[str, Dict[str, Any]] = JSON_SCHEMA_CONFIG,
schema: Dict[str, Any] = JSON_SCHEMA_CONFIG,
) -> Tuple[bool, str]:
"""Validate the main configuration."""
# indicate that validation passed; since there
Expand Down
20 changes: 10 additions & 10 deletions tests/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
from hypothesis import given, strategies
from hypothesis_jsonschema import from_schema

from chasten.validate import JSON_SCHEMA, validate_main_configuration
from chasten.validate import JSON_SCHEMA_CONFIG, validate_configuration


def test_validate_config_valid_simple():
"""Confirm that validation with built-in schema works for a simple valid example."""
valid_config_correct_schema = {"chasten": {"verbose": True, "debug-level": "ERROR"}}
is_valid, errors = validate_main_configuration(valid_config_correct_schema)
is_valid, errors = validate_configuration(valid_config_correct_schema)
assert is_valid
assert not errors

Expand All @@ -29,15 +29,15 @@ def test_validate_config_valid_realistic():
],
}
}
is_valid, errors = validate_main_configuration(valid_config_correct_schema)
is_valid, errors = validate_configuration(valid_config_correct_schema)
assert is_valid
assert not errors


def test_validate_config_invalid_simple():
"""Confirm that validation with built-in schema does not work for a simple invalid example."""
invalid_config_correct_schema = {"chasten": {"verbose": "yes"}}
is_valid, errors = validate_main_configuration(invalid_config_correct_schema)
is_valid, errors = validate_configuration(invalid_config_correct_schema)
assert not is_valid
assert errors
assert "is not of type" in errors
Expand All @@ -57,7 +57,7 @@ def test_validate_config_invalid_realistic():
],
}
}
is_valid, errors = validate_main_configuration(valid_config_correct_schema)
is_valid, errors = validate_configuration(valid_config_correct_schema)
assert not is_valid
assert errors
assert "is not of type" in errors
Expand All @@ -69,7 +69,7 @@ def test_validate_config_invalid_realistic():
@pytest.mark.fuzz
def test_validate_empty_config(config):
"""Use Hypothesis to confirm that an empty configuration will validate."""
is_valid, errors = validate_main_configuration(config)
is_valid, errors = validate_configuration(config)
assert is_valid
assert not errors

Expand All @@ -88,7 +88,7 @@ def test_validate_empty_config(config):
@pytest.mark.fuzz
def test_validate_config_with_verbose(config):
"""Use Hypothesis to confirm that a very simple valid schema will validate correctly."""
is_valid, errors = validate_main_configuration(config)
is_valid, errors = validate_configuration(config)
assert is_valid
assert not errors

Expand All @@ -107,15 +107,15 @@ def test_validate_config_with_verbose(config):
@pytest.mark.fuzz
def test_validate_config_with_debug_level(config):
"""Use Hypothesis to confirm that a simple valid schema will validate correctly."""
is_valid, errors = validate_main_configuration(config)
is_valid, errors = validate_configuration(config)
assert is_valid
assert not errors


@given(from_schema(JSON_SCHEMA))
@given(from_schema(JSON_SCHEMA_CONFIG))
@pytest.mark.fuzz
def test_integers(config):
"""Use Hypothesis and the JSON schema plugin to confirm validation works for all possible valid instances."""
is_valid, errors = validate_main_configuration(config)
is_valid, errors = validate_configuration(config)
assert is_valid
assert not errors

0 comments on commit de57a7b

Please sign in to comment.