From f7d04eefdcb17cfd489149f6d2a057d4c5e6d63b Mon Sep 17 00:00:00 2001 From: Alex Nelson Date: Mon, 3 May 2021 21:13:31 -0400 Subject: [PATCH 1/2] Recognize .jsonld extension IANA lists `application/ld+json` as a media type, including the `.jsonld` file extension, here: https://www.iana.org/assignments/media-types/application/ld+json via https://www.iana.org/assignments/media-types/media-types.xhtml via https://w3c.github.io/json-ld-syntax/#iana-considerations Signed-off-by: Alex Nelson --- case_utils/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/case_utils/__init__.py b/case_utils/__init__.py index 6ec055e..b79a05e 100644 --- a/case_utils/__init__.py +++ b/case_utils/__init__.py @@ -37,6 +37,8 @@ def guess_format(fpath, fmap=None): updated_fmap = {key:rdflib.util.SUFFIX_FORMAT_MAP[key] for key in rdflib.util.SUFFIX_FORMAT_MAP} if not "json" in updated_fmap: updated_fmap["json"] = "json-ld" + if not "jsonld" in updated_fmap: + updated_fmap["jsonld"] = "json-ld" else: updated_fmap = {k:fmap[k] for k in fmap} From 6ea9f5728b1e91569ec3b48bd35a19b8d341b7af Mon Sep 17 00:00:00 2001 From: Alex Nelson Date: Mon, 3 May 2021 21:21:34 -0400 Subject: [PATCH 2/2] Update tests to repeated expected .json behavior for .jsonld Signed-off-by: Alex Nelson --- tests/case_utils/test_guess_format.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/case_utils/test_guess_format.py b/tests/case_utils/test_guess_format.py index a62504f..d54f4aa 100644 --- a/tests/case_utils/test_guess_format.py +++ b/tests/case_utils/test_guess_format.py @@ -18,6 +18,7 @@ PATH_TO_TTL = "/nonexistent/foo.ttl" PATH_TO_JSON = "/nonexistent/foo.json" +PATH_TO_JSONLD = "/nonexistent/foo.jsonld" PATH_TO_XHTML = "/nonexistent/foo.xhtml" FMAP_XHTML_GRDDL = {"xhtml": "grddl"} @@ -41,6 +42,10 @@ def test_rdflib_util_guess_format_ttl_fmap(): def test_rdflib_util_guess_format_json(): assert rdflib.util.guess_format(PATH_TO_JSON) == "json-ld", "Failed to recognize .json RDF file extension" +@pytest.mark.xfail(reason="rdflib 5.0.0 known to not recognize .jsonld", strict=True) +def test_rdflib_util_guess_format_jsonld(): + assert rdflib.util.guess_format(PATH_TO_JSONLD) == "json-ld", "Failed to recognize .jsonld RDF file extension" + def test_case_utils_guess_format_ttl_default(): assert case_utils.guess_format(PATH_TO_TTL) == "turtle", "Failed to recognize .ttl RDF file extension" @@ -54,3 +59,10 @@ def test_case_utils_guess_format_json_default(): @pytest.mark.xfail(reason="Preserving behavior - rdflib 5.0.0 guess_format fmap argument overwrites base module's extension map", strict=True) def test_case_utils_guess_format_json_fmap(): assert case_utils.guess_format(PATH_TO_JSON, FMAP_XHTML_GRDDL) == "json-ld", "Failed to recognize .json RDF file extension when using fmap" + +def test_case_utils_guess_format_jsonld_default(): + assert case_utils.guess_format(PATH_TO_JSONLD) == "json-ld", "Failed to recognize .jsonld RDF file extension" + +@pytest.mark.xfail(reason="Preserving behavior - rdflib 5.0.0 guess_format fmap argument overwrites base module's extension map", strict=True) +def test_case_utils_guess_format_jsonld_fmap(): + assert case_utils.guess_format(PATH_TO_JSONLD, FMAP_XHTML_GRDDL) == "json-ld", "Failed to recognize .jsonld RDF file extension when using fmap"