Skip to content

Commit

Permalink
update test for json ld context #232 :
Browse files Browse the repository at this point in the history
- remove nulls from metadata document first as it would break the test.
  • Loading branch information
jh-RLI committed Jan 9, 2025
1 parent 48962a4 commit 85d9627
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions tests/metadata/v2/v20/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ def is_valid_type(value):
return False


def clean_null_ids(data):
"""Recursively remove @id entries with null values."""
if isinstance(data, dict):
return {
key: clean_null_ids(value)
for key, value in data.items()
if not (key == "@id" and value is None)
}
elif isinstance(data, list):
return [clean_null_ids(item) for item in data]
return data


def test_jsonld_combination(load_files):
"""Test combining example.json with context.json and validating JSON-LD."""
# try:
Expand All @@ -67,10 +80,12 @@ def test_jsonld_combination(load_files):
for resource in example_data.get("resources", []):
resource["@context"] = cleaned_context

# Remove @id with null values from resources
cleaned_example_data = clean_null_ids(example_data)

# Validate each resource as JSON-LD
for resource in example_data["resources"]:
for resource in cleaned_example_data["resources"]:
expanded = jsonld.expand(resource)
assert expanded, f"Validation failed for resource: {resource['@id']}"

# except Exception as e:
# pytest.fail(f"JSON-LD combination and validation failed: {e}")
assert (
expanded
), f"Validation failed for resource: {resource.get('@id', 'unknown')}"

0 comments on commit 85d9627

Please sign in to comment.