forked from RDFLib/rdflib
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request RDFLib#1801 from aucampia/iwana-20220410T1604-more…
…_variants Add two xfails related to Example 2 from RDF 1.1 TriG specification Merging with only one review as this just adds tests within the variant and round trip test harnesses which are parameterized. Some of the added tests are xfails but given that the rest of the tests for the same parameterized harnesses pass it seems likely that the xfail tests are valid.
- Loading branch information
Showing
22 changed files
with
198 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
Iterable, | ||
List, | ||
Optional, | ||
OrderedDict, | ||
Pattern, | ||
Tuple, | ||
Union, | ||
|
@@ -45,10 +46,13 @@ class GraphAsserts: | |
""" | ||
|
||
quad_count: Optional[int] = None | ||
exact_match: bool = False | ||
|
||
def check(self, graph: ConjunctiveGraph) -> None: | ||
def check(self, first_graph: Optional[ConjunctiveGraph], graph: ConjunctiveGraph) -> None: | ||
if self.quad_count is not None: | ||
assert self.quad_count == len(list(graph.quads())) | ||
if first_graph is not None and self.exact_match: | ||
GraphHelper.assert_quad_sets_equals(first_graph, graph) | ||
|
||
|
||
@dataclass(order=True) | ||
|
@@ -58,7 +62,7 @@ class GraphVariants: | |
""" | ||
|
||
key: str | ||
variants: Dict[str, Path] = field(default_factory=dict) | ||
variants: Dict[str, Path] = field(default_factory=OrderedDict) | ||
asserts: GraphAsserts = field(default_factory=lambda: GraphAsserts()) | ||
|
||
_variant_regex: ClassVar[Pattern[str]] = re.compile( | ||
|
@@ -135,6 +139,29 @@ def for_directory( | |
reason="Some issue with handling base URI that does not end with a slash", | ||
raises=ValueError, | ||
), | ||
("variants/rdf11trig_eg2"): pytest.mark.xfail( | ||
reason=""" | ||
This fails randomly, passing less than 10% of the time, and always failing | ||
with comparing hext against trig. Not clear why, it may be a big with hext | ||
parsing. | ||
AssertionError: checking rdf11trig_eg2.hext against rdf11trig_eg2.trig | ||
in both: | ||
(rdflib.term.BNode('cb0'), rdflib.term.URIRef('http://xmlns.com/foaf/0.1/mbox'), rdflib.term.URIRef('mailto:[email protected]')) | ||
(rdflib.term.BNode('cb0'), rdflib.term.URIRef('http://xmlns.com/foaf/0.1/name'), rdflib.term.Literal('Bob')) | ||
(rdflib.term.URIRef('http://example.org/bob'), rdflib.term.URIRef('http://purl.org/dc/terms/publisher'), rdflib.term.Literal('Bob')) | ||
(rdflib.term.URIRef('http://example.org/alice'), rdflib.term.URIRef('http://purl.org/dc/terms/publisher'), rdflib.term.Literal('Alice')) | ||
only in first: | ||
(rdflib.term.BNode('cb0'), rdflib.term.URIRef('http://xmlns.com/foaf/0.1/knows'), rdflib.term.BNode('cbb5eb12b5dcf688537b0298cce144c6dd68cf047530d0b4a455a8f31f314244fd')) | ||
(rdflib.term.BNode('cbb5eb12b5dcf688537b0298cce144c6dd68cf047530d0b4a455a8f31f314244fd'), rdflib.term.URIRef('http://xmlns.com/foaf/0.1/mbox'), rdflib.term.URIRef('mailto:[email protected]')) | ||
(rdflib.term.BNode('cbb5eb12b5dcf688537b0298cce144c6dd68cf047530d0b4a455a8f31f314244fd'), rdflib.term.URIRef('http://xmlns.com/foaf/0.1/name'), rdflib.term.Literal('Alice')) | ||
only in second: | ||
(rdflib.term.BNode('cb0'), rdflib.term.URIRef('http://xmlns.com/foaf/0.1/knows'), rdflib.term.BNode('cbcd41774964510991c01701d8430149bc373e1f23734d9c938c81a40b1429aa33')) | ||
(rdflib.term.BNode('cbcd41774964510991c01701d8430149bc373e1f23734d9c938c81a40b1429aa33'), rdflib.term.URIRef('http://xmlns.com/foaf/0.1/mbox'), rdflib.term.URIRef('mailto:[email protected]')) | ||
(rdflib.term.BNode('cbcd41774964510991c01701d8430149bc373e1f23734d9c938c81a40b1429aa33'), rdflib.term.URIRef('http://xmlns.com/foaf/0.1/name'), rdflib.term.Literal('Alice')) | ||
""", | ||
raises=AssertionError, | ||
), | ||
} | ||
|
||
|
||
|
@@ -164,7 +191,8 @@ def test_variants(graph_variant: GraphVariants) -> None: | |
logging.debug("graph_variant = %s", graph_variant) | ||
public_id = URIRef(f"example:{graph_variant.key}") | ||
assert len(graph_variant.variants) > 0 | ||
first_graph: Optional[Graph] = None | ||
first_graph: Optional[ConjunctiveGraph] = None | ||
first_path: Optional[Path] = None | ||
for variant_key, variant_path in graph_variant.variants.items(): | ||
logging.debug("variant_path = %s", variant_path) | ||
format = guess_format(variant_path.name, fmap=SUFFIX_FORMAT_MAP) | ||
|
@@ -175,8 +203,10 @@ def test_variants(graph_variant: GraphVariants) -> None: | |
# opinions of when a bare string is of datatype XSD.string or not. | ||
# Probably something that needs more investigation. | ||
GraphHelper.strip_literal_datatypes(graph, {XSD.string}) | ||
graph_variant.asserts.check(graph) | ||
graph_variant.asserts.check(first_graph, graph) | ||
if first_graph is None: | ||
first_graph = graph | ||
first_path = variant_path | ||
else: | ||
GraphHelper.assert_isomorphic(first_graph, graph) | ||
assert first_path is not None | ||
GraphHelper.assert_isomorphic(first_graph, graph, f"checking {variant_path.relative_to(VARIANTS_DIR)} against {first_path.relative_to(VARIANTS_DIR)}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,6 +142,28 @@ | |
reason="results in invalid xml element name: <ns1:name(s)/>", | ||
raises=SAXParseException, | ||
), | ||
("trig", "rdf11trig_eg2.trig"): pytest.mark.xfail( | ||
reason=""" | ||
Something is going wrong here with blank node serialization. In the second | ||
graph below bob knows someone who does not exist, while in first he knows | ||
someone that does exist and has the name Alice. | ||
AssertionError: in both: | ||
(rdflib.term.BNode('cbb5eb12b5dcf688537b0298cce144c6dd68cf047530d0b4a455a8f31f314244fd'), rdflib.term.URIRef('http://xmlns.com/foaf/0.1/mbox'), rdflib.term.URIRef('mailto:[email protected]')) | ||
(rdflib.term.BNode('cbb5eb12b5dcf688537b0298cce144c6dd68cf047530d0b4a455a8f31f314244fd'), rdflib.term.URIRef('http://xmlns.com/foaf/0.1/name'), rdflib.term.Literal('Alice')) | ||
(rdflib.term.URIRef('http://example.org/alice'), rdflib.term.URIRef('http://purl.org/dc/terms/publisher'), rdflib.term.Literal('Alice')) | ||
(rdflib.term.URIRef('http://example.org/bob'), rdflib.term.URIRef('http://purl.org/dc/terms/publisher'), rdflib.term.Literal('Bob')) | ||
only in first: | ||
(rdflib.term.BNode('cb0'), rdflib.term.URIRef('http://xmlns.com/foaf/0.1/knows'), rdflib.term.BNode('cbb5eb12b5dcf688537b0298cce144c6dd68cf047530d0b4a455a8f31f314244fd')) | ||
(rdflib.term.BNode('cb0'), rdflib.term.URIRef('http://xmlns.com/foaf/0.1/mbox'), rdflib.term.URIRef('mailto:[email protected]')) | ||
(rdflib.term.BNode('cb0'), rdflib.term.URIRef('http://xmlns.com/foaf/0.1/name'), rdflib.term.Literal('Bob')) | ||
only in second: | ||
(rdflib.term.BNode('cb7be1d0397a49ddd4ae8aa96acc7b6135903c5f3fa5e47bf619c0e4b438aafcc1'), rdflib.term.URIRef('http://xmlns.com/foaf/0.1/knows'), rdflib.term.BNode('cb0')) | ||
(rdflib.term.BNode('cb7be1d0397a49ddd4ae8aa96acc7b6135903c5f3fa5e47bf619c0e4b438aafcc1'), rdflib.term.URIRef('http://xmlns.com/foaf/0.1/mbox'), rdflib.term.URIRef('mailto:[email protected]')) | ||
(rdflib.term.BNode('cb7be1d0397a49ddd4ae8aa96acc7b6135903c5f3fa5e47bf619c0e4b438aafcc1'), rdflib.term.URIRef('http://xmlns.com/foaf/0.1/name'), rdflib.term.Literal('Bob')) | ||
""", | ||
raises=AssertionError, | ||
), | ||
} | ||
|
||
# This is for files which can only be represented properly in one format | ||
|
@@ -267,6 +289,8 @@ def test_n3(checker: Callable[[str, str, Path], None], args: Tuple[str, str, Pat | |
(TEST_DIR / "variants" / "special_chars.nt", "ntriples"), | ||
(TEST_DIR / "variants" / "xml_literal.rdf", "xml"), | ||
(TEST_DIR / "variants" / "rdf_prefix.jsonld", "json-ld"), | ||
(TEST_DIR / "variants" / "simple_quad.trig", "trig"), | ||
(TEST_DIR / "variants" / "rdf11trig_eg2.trig", "trig"), | ||
] | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"quad_count": 7 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
["_:b", "http://xmlns.com/foaf/0.1/mbox", "mailto:[email protected]", "globalId", "", "http://example.org/alice"] | ||
["_:b", "http://xmlns.com/foaf/0.1/name", "Alice", "http://www.w3.org/2001/XMLSchema#string", "", "http://example.org/alice"] | ||
["_:a", "http://xmlns.com/foaf/0.1/mbox", "mailto:[email protected]", "globalId", "", "http://example.org/bob"] | ||
["_:a", "http://xmlns.com/foaf/0.1/name", "Bob", "http://www.w3.org/2001/XMLSchema#string", "", "http://example.org/bob"] | ||
["_:a", "http://xmlns.com/foaf/0.1/knows", "_:b", "localId", "", "http://example.org/bob"] | ||
["http://example.org/bob", "http://purl.org/dc/terms/publisher", "Bob", "http://www.w3.org/2001/XMLSchema#string", "", ""] | ||
["http://example.org/alice", "http://purl.org/dc/terms/publisher", "Alice", "http://www.w3.org/2001/XMLSchema#string", "", ""] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"@graph": [ | ||
{ | ||
"@graph": [ | ||
{ | ||
"@id": "http://example.org/bob", | ||
"http://purl.org/dc/terms/publisher": "Bob" | ||
}, | ||
{ | ||
"@id": "http://example.org/alice", | ||
"http://purl.org/dc/terms/publisher": "Alice" | ||
} | ||
] | ||
}, | ||
{ | ||
"@graph": [ | ||
{ | ||
"@id": "_:a", | ||
"http://xmlns.com/foaf/0.1/knows": { | ||
"@id": "_:b" | ||
}, | ||
"http://xmlns.com/foaf/0.1/mbox": { | ||
"@id": "mailto:[email protected]" | ||
}, | ||
"http://xmlns.com/foaf/0.1/name": "Bob" | ||
} | ||
], | ||
"@id": "http://example.org/bob" | ||
}, | ||
{ | ||
"@graph": [ | ||
{ | ||
"@id": "_:b", | ||
"http://xmlns.com/foaf/0.1/mbox": { | ||
"@id": "mailto:[email protected]" | ||
}, | ||
"http://xmlns.com/foaf/0.1/name": "Alice" | ||
} | ||
], | ||
"@id": "http://example.org/alice" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
_:a <http://xmlns.com/foaf/0.1/knows> _:b <http://example.org/bob> . | ||
_:a <http://xmlns.com/foaf/0.1/mbox> <mailto:[email protected]> <http://example.org/bob> . | ||
_:a <http://xmlns.com/foaf/0.1/name> "Bob" <http://example.org/bob> . | ||
_:b <http://xmlns.com/foaf/0.1/mbox> <mailto:[email protected]> <http://example.org/alice> . | ||
_:b <http://xmlns.com/foaf/0.1/name> "Alice" <http://example.org/alice> . | ||
<http://example.org/alice> <http://purl.org/dc/terms/publisher> "Alice" . | ||
<http://example.org/bob> <http://purl.org/dc/terms/publisher> "Bob" . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# from example 2 in https://www.w3.org/TR/trig/#sec-graph-statements | ||
|
||
# This document contains a default graph and two named graphs. | ||
|
||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . | ||
@prefix dc: <http://purl.org/dc/terms/> . | ||
@prefix foaf: <http://xmlns.com/foaf/0.1/> . | ||
|
||
# default graph | ||
{ | ||
<http://example.org/bob> dc:publisher "Bob" . | ||
<http://example.org/alice> dc:publisher "Alice" . | ||
} | ||
|
||
<http://example.org/bob> | ||
{ | ||
_:a foaf:name "Bob" . | ||
_:a foaf:mbox <mailto:[email protected]> . | ||
_:a foaf:knows _:b . | ||
} | ||
|
||
<http://example.org/alice> | ||
{ | ||
_:b foaf:name "Alice" . | ||
_:b foaf:mbox <mailto:[email protected]> . | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"quad_count": 3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"quad_count": 4 | ||
"quad_count": 4, | ||
"exact_match": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"quad_count": 1, | ||
"exact_match": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
["http://example.org/subject", "http://example.org/predicate", "http://example.org/object", "globalId", "", "http://example.org/graph"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[ | ||
{ | ||
"@graph": [ | ||
{ | ||
"@id": "http://example.org/subject", | ||
"http://example.org/predicate": [ | ||
{ | ||
"@id": "http://example.org/object" | ||
} | ||
] | ||
} | ||
], | ||
"@id": "http://example.org/graph" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<http://example.org/subject> <http://example.org/predicate> <http://example.org/object> <http://example.org/graph> . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@prefix example: <http://example.org/>. | ||
|
||
example:graph { | ||
example:subject example:predicate example:object . | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"quad_count": 1 | ||
"quad_count": 1, | ||
"exact_match": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<http://example.org/subject> <http://example.org/predicate> <http://example.org/object> . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<http://example.org/subject> <http://example.org/predicate> <http://example.org/object> . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"quad_count": 7 | ||
"quad_count": 7, | ||
"exact_match": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"quad_count": 1 | ||
"quad_count": 1, | ||
"exact_match": true | ||
} |