Skip to content

Add JSON-LD output code path test for case_sparql_construct #8

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 1 commit into from
Jun 11, 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: 1 addition & 1 deletion case_utils/case_sparql_construct/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def main():
"format": output_format
}
if output_format == "json-ld":
context_dictionary = {k:v for (k,v) in graph.namespace_manager.namespaces()}
context_dictionary = {k:v for (k,v) in out_graph.namespace_manager.namespaces()}
serialize_kwargs["context"] = context_dictionary

out_graph.serialize(args.out_graph, **serialize_kwargs)
Expand Down
1 change: 1 addition & 0 deletions tests/case_sparql_construct/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
output.json
output.ttl
5 changes: 3 additions & 2 deletions tests/case_sparql_construct/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ all: \
output.ttl

check: \
output.json \
output.ttl
source $(tests_srcdir)/venv/bin/activate \
&& pytest \
Expand All @@ -30,10 +31,10 @@ clean:
@rm -rf \
__pycache__
@rm -f \
output.ttl \
output.* \
_*

output.ttl: \
output.%: \
$(tests_srcdir)/.venv.done.log \
$(top_srcdir)/case_utils/case_sparql_construct/__init__.py \
input-1.sparql \
Expand Down
9 changes: 7 additions & 2 deletions tests/case_sparql_construct/test_case_sparql_construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@

import case_utils

def test_templates_with_blank_nodes_result():
def _test_templates_with_blank_nodes_result(filename):
ground_truth_positive = {
("Alice", "Hacker"),
("Bob", "Hacker")
}
ground_truth_negative = set()

graph = rdflib.Graph()
graph.parse("output.ttl", format=case_utils.guess_format("output.ttl"))
graph.parse(filename, format=case_utils.guess_format(filename))

computed = set()
query_string = """\
Expand All @@ -47,3 +47,8 @@ def test_templates_with_blank_nodes_result():
l_family_name.toPython()
))
assert computed == ground_truth_positive

def test_templates_with_blank_nodes_result_json():
_test_templates_with_blank_nodes_result("output.json")
def test_templates_with_blank_nodes_result_turtle():
_test_templates_with_blank_nodes_result("output.ttl")