Skip to content

Commit 2761288

Browse files
committed
Add test to demonstrate local schema validation
1 parent 89371ae commit 2761288

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

space_packet_parser/xtce/validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def _is_http_url(s):
170170
# Fix and parse the schema content
171171
try:
172172
try:
173-
schema_root_element = ElementTree.XML(schema_content, parser)
173+
schema_root_element = ElementTree.XML(schema_content.encode("utf-8"), parser)
174174
return ElementTree.XMLSchema(schema_root_element), schema_root_element.get("version", "unknown")
175175
except ElementTree.XMLSchemaError as e:
176176
# Try to fix known issues

tests/unit/test_xtce/test_validation.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,22 @@ def test_validate_xtce_all_mode(test_data_dir):
348348
# Should have schema information
349349
assert result.schema_location is not None
350350
assert result.schema_version is not None
351+
352+
353+
def test_schema_validation_with_local_xsd(test_data_dir):
354+
"""Test schema validation using a local XSD file instead of downloading from URL"""
355+
# Use an existing test XTCE document
356+
xtce_path = test_data_dir / "test_xtce.xml"
357+
local_xsd_path = test_data_dir / "SpaceSystem.xsd"
358+
359+
# Validate using the local XSD
360+
result = validate_xtce(xtce_path, level="schema", local_xsd=local_xsd_path)
361+
362+
# Verify validation was performed
363+
assert result.validation_level.value == "schema"
364+
assert result.schema_location == str(local_xsd_path)
365+
assert result.schema_version is not None
366+
367+
# The document should be valid against the schema
368+
assert result.valid
369+
assert len(result.errors) == 0

0 commit comments

Comments
 (0)