Fix CI/CD issues: linting errors and test file corruption
Some checks failed
CI / test (ubuntu-latest, 3.10) (push) Has been cancelled
CI / test (ubuntu-latest, 3.11) (push) Has been cancelled
CI / test (ubuntu-latest, 3.12) (push) Has been cancelled
CI / test (ubuntu-latest, 3.8) (push) Has been cancelled
CI / test (ubuntu-latest, 3.9) (push) Has been cancelled
CI / test-minimal (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / build (push) Has been cancelled
CI / release (push) Has been cancelled
Some checks failed
CI / test (ubuntu-latest, 3.10) (push) Has been cancelled
CI / test (ubuntu-latest, 3.11) (push) Has been cancelled
CI / test (ubuntu-latest, 3.12) (push) Has been cancelled
CI / test (ubuntu-latest, 3.8) (push) Has been cancelled
CI / test (ubuntu-latest, 3.9) (push) Has been cancelled
CI / test-minimal (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / build (push) Has been cancelled
CI / release (push) Has been cancelled
This commit is contained in:
@@ -11,7 +11,11 @@ from .parsers import load_data
|
|||||||
class SchemaValidator:
|
class SchemaValidator:
|
||||||
"""Handle JSON Schema validation for data files."""
|
"""Handle JSON Schema validation for data files."""
|
||||||
|
|
||||||
def __init__(self, schema: Optional[Dict[str, Any]] = None, schema_file: Optional[str] = None):
|
def __init__(
|
||||||
|
self,
|
||||||
|
schema: Optional[Dict[str, Any]] = None,
|
||||||
|
schema_file: Optional[str] = None,
|
||||||
|
):
|
||||||
"""Initialize validator with optional schema."""
|
"""Initialize validator with optional schema."""
|
||||||
self.schema = None
|
self.schema = None
|
||||||
self.validator_class = None
|
self.validator_class = None
|
||||||
@@ -28,6 +32,7 @@ class SchemaValidator:
|
|||||||
self.validator_class = Draft7Validator
|
self.validator_class = Draft7Validator
|
||||||
elif "draft-2019-09" in draft:
|
elif "draft-2019-09" in draft:
|
||||||
from jsonschema import Draft201909Validator
|
from jsonschema import Draft201909Validator
|
||||||
|
|
||||||
self.validator_class = Draft201909Validator
|
self.validator_class = Draft201909Validator
|
||||||
else:
|
else:
|
||||||
self.validator_class = Draft7Validator
|
self.validator_class = Draft7Validator
|
||||||
@@ -37,7 +42,9 @@ class SchemaValidator:
|
|||||||
schema_data = load_data(schema_file)
|
schema_data = load_data(schema_file)
|
||||||
self.set_schema(schema_data)
|
self.set_schema(schema_data)
|
||||||
|
|
||||||
def validate(self, data: Any, raise_on_error: bool = False) -> List[ValidationError]:
|
def validate(
|
||||||
|
self, data: Any, raise_on_error: bool = False
|
||||||
|
) -> List[ValidationError]:
|
||||||
"""Validate data against the schema."""
|
"""Validate data against the schema."""
|
||||||
if self.schema is None:
|
if self.schema is None:
|
||||||
raise ValueError("No schema has been set for validation")
|
raise ValueError("No schema has been set for validation")
|
||||||
@@ -47,7 +54,9 @@ class SchemaValidator:
|
|||||||
raise ValidationError(errors[0].message)
|
raise ValidationError(errors[0].message)
|
||||||
return errors
|
return errors
|
||||||
|
|
||||||
def validate_file(self, file_path: str, format: Optional[str] = None) -> List[ValidationError]:
|
def validate_file(
|
||||||
|
self, file_path: str, format: Optional[str] = None
|
||||||
|
) -> List[ValidationError]:
|
||||||
"""Validate a file against the schema."""
|
"""Validate a file against the schema."""
|
||||||
data = load_data(file_path, format)
|
data = load_data(file_path, format)
|
||||||
return self.validate(data)
|
return self.validate(data)
|
||||||
@@ -61,7 +70,9 @@ class SchemaValidator:
|
|||||||
return messages
|
return messages
|
||||||
|
|
||||||
|
|
||||||
def validate_data(data: Any, schema: Dict[str, Any]) -> tuple[bool, List[str]]:
|
def validate_data(
|
||||||
|
data: Any, schema: Dict[str, Any]
|
||||||
|
) -> tuple[bool, List[str]]:
|
||||||
"""Validate data against a schema and return success status and error messages."""
|
"""Validate data against a schema and return success status and error messages."""
|
||||||
validator = SchemaValidator(schema=schema)
|
validator = SchemaValidator(schema=schema)
|
||||||
errors = validator.validate(data)
|
errors = validator.validate(data)
|
||||||
@@ -69,7 +80,9 @@ def validate_data(data: Any, schema: Dict[str, Any]) -> tuple[bool, List[str]]:
|
|||||||
return len(errors) == 0, messages
|
return len(errors) == 0, messages
|
||||||
|
|
||||||
|
|
||||||
def validate_file(file_path: str, schema_file: str, format: Optional[str] = None) -> tuple[bool, List[str]]:
|
def validate_file(
|
||||||
|
file_path: str, schema_file: str, format: Optional[str] = None
|
||||||
|
) -> tuple[bool, List[str]]:
|
||||||
"""Validate a file against a schema file."""
|
"""Validate a file against a schema file."""
|
||||||
validator = SchemaValidator(schema_file=schema_file)
|
validator = SchemaValidator(schema_file=schema_file)
|
||||||
errors = validator.validate_file(file_path, format)
|
errors = validator.validate_file(file_path, format)
|
||||||
|
|||||||
Reference in New Issue
Block a user