diff --git a/rdflib/plugins/shared/jsonld/context.py b/rdflib/plugins/shared/jsonld/context.py index 23ab6db23..d0224d4a4 100644 --- a/rdflib/plugins/shared/jsonld/context.py +++ b/rdflib/plugins/shared/jsonld/context.py @@ -421,13 +421,13 @@ def _prep_sources( ): for source in inputs: source_url = in_source_url + new_base = base if isinstance(source, str): source_url = source source_doc_base = base or self.doc_base new_ctx = self._fetch_context( source, source_doc_base, referenced_contexts ) - new_base = base if new_ctx is None: continue else: diff --git a/test/jsonld/test_context.py b/test/jsonld/test_context.py index b7628fb3e..6578268a2 100644 --- a/test/jsonld/test_context.py +++ b/test/jsonld/test_context.py @@ -3,6 +3,7 @@ """ from functools import wraps +from pathlib import Path from typing import Any, Dict from rdflib.plugins.shared.jsonld import context, errors @@ -213,3 +214,23 @@ def test_invalid_remote_context(): ctx_url = "http://example.org/recursive.jsonld" SOURCES[ctx_url] = {"key": "value"} ctx = Context(ctx_url) + + +def test_file_source(tmp_path: Path) -> None: + """ + A file URI source to `Context` gets processed correctly. + """ + file = tmp_path / "context.jsonld" + file.write_text(r"""{ "@context": { "ex": "http://example.com/" } }""") + ctx = Context(source=file.as_uri()) + assert "http://example.com/" == ctx.terms["ex"].id + + +def test_dict_source(tmp_path: Path) -> None: + """ + A dictionary source to `Context` gets processed correctly. + """ + file = tmp_path / "context.jsonld" + file.write_text(r"""{ "@context": { "ex": "http://example.com/" } }""") + ctx = Context(source=[{"@context": file.as_uri()}]) + assert "http://example.com/" == ctx.terms["ex"].id