From aa3b687db65737f66a7075afe5ed453d9ea87fae Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Tue, 11 Jun 2024 13:08:00 +0000 Subject: [PATCH] Switch to using fastjsonschema for schema validation. The main reason to do this is because jsonschema (what we currently use) depends on referencing, which depends on rpds-py, which has C libraries. That means that when using the python debug interpreter on Windows, we would have to build a custom pip package for it to work. In contrast, fastjsonschema is pure python and has no dependencies. It is also available on all of our default platforms. So switch to using it here so things work on Windows debug. Signed-off-by: Chris Lalancette --- rosidl_generator_tests/package.xml | 2 +- .../rosidl_generator_type_description/test_type_hash.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/rosidl_generator_tests/package.xml b/rosidl_generator_tests/package.xml index f83848956..414a720bb 100644 --- a/rosidl_generator_tests/package.xml +++ b/rosidl_generator_tests/package.xml @@ -24,7 +24,7 @@ ament_lint_auto ament_lint_common ament_index_python - python3-jsonschema + python3-fastjsonschema rosidl_cmake rosidl_generator_c rosidl_generator_cpp diff --git a/rosidl_generator_tests/test/rosidl_generator_type_description/test_type_hash.py b/rosidl_generator_tests/test/rosidl_generator_type_description/test_type_hash.py index 4fde93d05..1785d11b9 100644 --- a/rosidl_generator_tests/test/rosidl_generator_type_description/test_type_hash.py +++ b/rosidl_generator_tests/test/rosidl_generator_type_description/test_type_hash.py @@ -17,7 +17,7 @@ from pathlib import Path from ament_index_python import get_package_share_directory -import jsonschema +import fastjsonschema def test_type_hash(): @@ -25,8 +25,10 @@ def test_type_hash(): 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 @@ -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.'