Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions hed/scripts/schema_script_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _is_prerelease_partner(base_schema) -> bool:
return hed_cache.get_hed_version_path(with_standard, check_prerelease=False) is None


def validate_schema_object(base_schema, schema_name, check_warnings=False):
def validate_schema_object(base_schema, schema_name, check_for_warnings=False):
"""Validate a schema object by checking compliance and roundtrip conversion.

Tests the schema for compliance issues and validates that it can be successfully
Expand All @@ -40,17 +40,17 @@ def validate_schema_object(base_schema, schema_name, check_warnings=False):
Parameters:
base_schema (HedSchema): The schema object to validate.
schema_name (str): The name/path of the schema for error reporting.
check_warnings (bool): If True, include warnings in the validation. Default is False.
check_for_warnings (bool): If True, include warnings in the validation. Default is False.

Returns:
list: A list of validation issue strings. Empty if no issues found.
"""
validation_issues = []
try:
issues = base_schema.check_compliance(check_for_warnings=check_warnings)
if issues and check_warnings:
issues = base_schema.check_compliance(check_for_warnings=check_for_warnings)
if issues and check_for_warnings:
errors, warnings = separate_issues(issues)
issues = errors + warnings
issues = errors + warnings # Ensure errors are listed before warnings
else:
errors = issues

Expand Down Expand Up @@ -79,7 +79,7 @@ def validate_schema_object(base_schema, schema_name, check_warnings=False):
return validation_issues


def validate_schema(file_path, check_warnings=False):
def validate_schema(file_path, check_for_warnings=False):
"""Validate a schema file, ensuring it can save/load and passes validation.

Loads the schema from file, checks the file extension is lowercase,
Expand All @@ -90,7 +90,7 @@ def validate_schema(file_path, check_warnings=False):
If loading a TSV file, this should be a single filename where:
Template: basename.tsv, where files are named basename_Struct.tsv, basename_Tag.tsv, etc.
Alternatively, you can point to a directory containing the .tsv files.
check_warnings (bool): If True, include warnings in the validation. Default is False.
check_for_warnings (bool): If True, include warnings in the validation. Default is False.

Returns:
list: A list of validation issue strings. Empty if no issues found.
Expand All @@ -105,7 +105,7 @@ def validate_schema(file_path, check_warnings=False):
validation_issues = []
try:
base_schema = load_schema(file_path)
validation_issues = validate_schema_object(base_schema, file_path, check_warnings=check_warnings)
validation_issues = validate_schema_object(base_schema, file_path, check_for_warnings=check_for_warnings)
except HedFileError as e:
print(f"Saving/loading error: {file_path} {e.message}")
error_text = e.message
Expand Down
30 changes: 15 additions & 15 deletions tests/scripts/test_script_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def test_uppercase_extension_policy_enforcement(self):


class TestCheckWarnings(unittest.TestCase):
"""Tests for the check_warnings parameter in validate_schema_object and validate_schema."""
"""Tests for the check_for_warnings parameter in validate_schema_object and validate_schema."""

@classmethod
def setUpClass(cls):
Expand All @@ -283,22 +283,22 @@ def setUpClass(cls):
cls.warning_schema = copy.deepcopy(clean)
cls.warning_schema.header_attributes["version"] = "999.0.0"

def test_clean_schema_check_warnings_false(self):
"""A fully compliant schema produces no issues with check_warnings=False."""
def test_clean_schema_check_for_warnings_false(self):
"""A fully compliant schema produces no issues with check_for_warnings=False."""
with contextlib.redirect_stdout(io.StringIO()):
issues = validate_schema_object(self.clean_schema, "test", check_warnings=False)
issues = validate_schema_object(self.clean_schema, "test", check_for_warnings=False)
self.assertEqual(issues, [])

def test_clean_schema_check_warnings_true(self):
"""A fully compliant schema produces no issues with check_warnings=True."""
def test_clean_schema_check_for_warnings_true(self):
"""A fully compliant schema produces no issues with check_for_warnings=True."""
with contextlib.redirect_stdout(io.StringIO()):
issues = validate_schema_object(self.clean_schema, "test", check_warnings=True)
issues = validate_schema_object(self.clean_schema, "test", check_for_warnings=True)
self.assertEqual(issues, [])

def test_warning_schema_check_warnings_true_reports_issues(self):
"""A prerelease version generates a warning that is reported when check_warnings=True."""
def test_warning_schema_check_for_warnings_true_reports_issues(self):
"""A prerelease version generates a warning that is reported when check_for_warnings=True."""
with contextlib.redirect_stdout(io.StringIO()):
issues = validate_schema_object(self.warning_schema, "test", check_warnings=True)
issues = validate_schema_object(self.warning_schema, "test", check_for_warnings=True)
combined = "\n".join(issues)
self.assertTrue(issues, "Expected at least one issue for prerelease version warning")
self.assertIn(
Expand All @@ -313,14 +313,14 @@ def test_warning_schema_check_warnings_true_reports_issues(self):
# because a clean schema with only a version warning should roundtrip without further errors.
self.assertEqual(len(issues), 1, "Roundtrip should have run and produced no additional errors")

def test_warning_schema_check_warnings_false_suppresses_warnings(self):
"""Warnings are suppressed and validation passes when check_warnings=False."""
def test_warning_schema_check_for_warnings_false_suppresses_warnings(self):
"""Warnings are suppressed and validation passes when check_for_warnings=False."""
with contextlib.redirect_stdout(io.StringIO()):
issues = validate_schema_object(self.warning_schema, "test", check_warnings=False)
issues = validate_schema_object(self.warning_schema, "test", check_for_warnings=False)
self.assertEqual(issues, [])

def test_validate_schema_default_is_warnings_false(self):
"""validate_schema default check_warnings=False matches explicit False."""
"""validate_schema default check_for_warnings=False matches explicit False."""
schema_path = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
"data",
Expand All @@ -329,5 +329,5 @@ def test_validate_schema_default_is_warnings_false(self):
)
with contextlib.redirect_stdout(io.StringIO()):
default_issues = validate_schema(schema_path)
explicit_issues = validate_schema(schema_path, check_warnings=False)
explicit_issues = validate_schema(schema_path, check_for_warnings=False)
self.assertEqual(default_issues, explicit_issues)