Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to using fastjsonschema for schema validation. #809

Merged
merged 1 commit into from
Jun 13, 2024
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
2 changes: 1 addition & 1 deletion rosidl_generator_tests/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<test_depend>ament_index_python</test_depend>
<test_depend>python3-jsonschema</test_depend>
<test_depend>python3-fastjsonschema</test_depend>
<test_depend>rosidl_cmake</test_depend>
<test_depend>rosidl_generator_c</test_depend>
<test_depend>rosidl_generator_cpp</test_depend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@
from pathlib import Path

from ament_index_python import get_package_share_directory
import jsonschema
import fastjsonschema


def test_type_hash():
"""Test all rosidl_generator_type_description output files against defined schemas."""
schema_path = (
Path(get_package_share_directory('rosidl_generator_type_description')) / 'resource' /
'HashedTypeDescription.schema.json')

with schema_path.open('r') as schema_file:
schema = json.load(schema_file)
validator = fastjsonschema.compile(schema)

generated_files_dir = Path(os.environ['GENERATED_TEST_FILE_DIR'])
validated_files = 0
Expand All @@ -36,6 +38,6 @@ def test_type_hash():
assert p.suffix == '.json'
with p.open('r') as f:
instance = json.load(f)
jsonschema.validate(instance=instance, schema=schema)
validator(instance)
validated_files += 1
assert validated_files, 'Needed to validate at least one JSON output.'
Loading