Skip to content

Recognize jsonld extension #3

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

Merged
merged 2 commits into from
May 4, 2021
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: 2 additions & 0 deletions case_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
12 changes: 12 additions & 0 deletions tests/case_utils/test_guess_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

Expand All @@ -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"

Expand All @@ -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"