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:
@@ -37,17 +37,19 @@ def parse_type_spec(type_spec: TypeSpec) -> Tuple[str, Optional[Dict[str, Any]]]
|
|||||||
return "unknown", None
|
return "unknown", None
|
||||||
|
|
||||||
|
|
||||||
def check_type(value: Any, expected_type: TypeSpec) -> Tuple[bool, Optional[str]]:
|
def check_type(
|
||||||
|
value: Any, expected_type: TypeSpec
|
||||||
|
) -> Tuple[bool, Optional[str]]:
|
||||||
"""Check if a value matches the expected type specification."""
|
"""Check if a value matches the expected type specification."""
|
||||||
actual_type = infer_type(value)
|
actual_type = infer_type(value)
|
||||||
type_name, type_info = parse_type_spec(expected_type)
|
type_name, type_info = parse_type_spec(expected_type)
|
||||||
|
|
||||||
if type_name == "any":
|
if type_name == "any":
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
if actual_type != type_name:
|
if actual_type != type_name:
|
||||||
return False, f"Expected {type_name}, got {actual_type}"
|
return False, f"Expected {type_name}, got {actual_type}"
|
||||||
|
|
||||||
if type_name == "object" and isinstance(type_info, dict):
|
if type_name == "object" and isinstance(type_info, dict):
|
||||||
properties = type_info.get("properties", {})
|
properties = type_info.get("properties", {})
|
||||||
required = type_info.get("required", [])
|
required = type_info.get("required", [])
|
||||||
@@ -56,12 +58,12 @@ def check_type(value: Any, expected_type: TypeSpec) -> Tuple[bool, Optional[str]
|
|||||||
prop_valid, error = check_type(value[prop_name], prop_type)
|
prop_valid, error = check_type(value[prop_name], prop_type)
|
||||||
if not prop_valid:
|
if not prop_valid:
|
||||||
return False, f"Property '{prop_name}': {error}"
|
return False, f"Property '{prop_name}': {error}"
|
||||||
|
|
||||||
if isinstance(required, list):
|
if isinstance(required, list):
|
||||||
for req_prop in required:
|
for req_prop in required:
|
||||||
if req_prop not in value:
|
if req_prop not in value:
|
||||||
return False, f"Missing required property: '{req_prop}'"
|
return False, f"Missing required property: '{req_prop}'"
|
||||||
|
|
||||||
if type_name == "array" and isinstance(type_info, dict):
|
if type_name == "array" and isinstance(type_info, dict):
|
||||||
items = type_info.get("items")
|
items = type_info.get("items")
|
||||||
if items is not None:
|
if items is not None:
|
||||||
@@ -69,11 +71,13 @@ def check_type(value: Any, expected_type: TypeSpec) -> Tuple[bool, Optional[str]
|
|||||||
item_valid, error = check_type(item, items)
|
item_valid, error = check_type(item, items)
|
||||||
if not item_valid:
|
if not item_valid:
|
||||||
return False, f"Array item {i}: {error}"
|
return False, f"Array item {i}: {error}"
|
||||||
|
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
|
|
||||||
def validate_types(data: Any, type_spec: TypeSpec, path: str = "root") -> List[str]:
|
def validate_types(
|
||||||
|
data: Any, type_spec: TypeSpec, path: str = "root"
|
||||||
|
) -> List[str]:
|
||||||
"""Validate data against a type specification and return all errors."""
|
"""Validate data against a type specification and return all errors."""
|
||||||
errors = []
|
errors = []
|
||||||
valid, error = check_type(data, type_spec)
|
valid, error = check_type(data, type_spec)
|
||||||
@@ -102,11 +106,11 @@ def validate_types(data: Any, type_spec: TypeSpec, path: str = "root") -> List[s
|
|||||||
def infer_schema_from_data(data: Any) -> Dict[str, Any]:
|
def infer_schema_from_data(data: Any) -> Dict[str, Any]:
|
||||||
"""Infer a JSON Schema from data."""
|
"""Infer a JSON Schema from data."""
|
||||||
schema: Dict[str, Any] = {}
|
schema: Dict[str, Any] = {}
|
||||||
|
|
||||||
def build_schema(value: Any, schema_obj: Dict[str, Any]) -> None:
|
def build_schema(value: Any, schema_obj: Dict[str, Any]) -> None:
|
||||||
type_name = infer_type(value)
|
type_name = infer_type(value)
|
||||||
schema_obj["type"] = type_name
|
schema_obj["type"] = type_name
|
||||||
|
|
||||||
if type_name == "object" and isinstance(value, dict):
|
if type_name == "object" and isinstance(value, dict):
|
||||||
schema_obj["properties"] = {}
|
schema_obj["properties"] = {}
|
||||||
required = []
|
required = []
|
||||||
@@ -118,10 +122,10 @@ def infer_schema_from_data(data: Any) -> Dict[str, Any]:
|
|||||||
required.append(key)
|
required.append(key)
|
||||||
if required:
|
if required:
|
||||||
schema_obj["required"] = required
|
schema_obj["required"] = required
|
||||||
|
|
||||||
elif type_name == "array" and isinstance(value, list) and value:
|
elif type_name == "array" and isinstance(value, list) and value:
|
||||||
schema_obj["items"] = {}
|
schema_obj["items"] = {}
|
||||||
build_schema(value[0], schema_obj["items"])
|
build_schema(value[0], schema_obj["items"])
|
||||||
|
|
||||||
build_schema(data, schema)
|
build_schema(data, schema)
|
||||||
return schema
|
return schema
|
||||||
|
|||||||
Reference in New Issue
Block a user