Skip to content

Commit

Permalink
test: add more variants highlighting bugs
Browse files Browse the repository at this point in the history
This patch adds some additional variants:

- diverse_triples: More than one triple using various features.
- diverse_quads: More than one quad in more than one graph using various
  features.
- more_quads: Simple quads in more than one graph.

This also highlights some additional issues:
- There is a bug in JSON-LD and HexTuple serialization that drops
  datatypes.
- The TriG parser gets confused about what graph a quad is in.
  • Loading branch information
aucampia committed May 8, 2022
1 parent eba1373 commit 09bbc64
Show file tree
Hide file tree
Showing 15 changed files with 297 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/data/variants/diverse_quads-asserts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"quad_count": 10,
"exact_match": true
}
73 changes: 73 additions & 0 deletions test/data/variants/diverse_quads.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"@graph": [
{
"@graph": [
{
"@id": "egschema:subject",
"egschema:predicate": [
12,
{
"@id": "egschema:object"
}
]
},
{
"@id": "eghttp:subject",
"predicate": {
"@language": "jpx",
"@value": "日本語の表記体系"
}
},
{
"@id": "egurn:subject",
"egschema:predicate": {
"@id": "egschema:subject"
}
}
],
"@id": "egschema:graph"
},
{
"@id": "egschema:subject",
"egschema:predicate": {
"@id": "egschema:object"
}
},
{
"@id": "eghttp:subject",
"predicate": "typeless"
},
{
"@graph": [
{
"@id": "egschema:subject",
"egschema:predicate": {
"@id": "egschema:object"
},
"predicate": [
"XSD string",
{
"@id": "eghttp:object"
}
]
}
],
"@id": "egurn:graph"
},
{
"@id": "egurn:subject",
"egurn:predicate": {
"@id": "egurn:object"
}
}
],
"@context": {
"predicate": {
"@id": "http://example.com/predicate"
},
"egurn": "urn:example:",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"egschema": "example:",
"eghttp": "http://example.com/"
}
}
10 changes: 10 additions & 0 deletions test/data/variants/diverse_quads.nq
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<http://example.com/subject> <http://example.com/predicate> "日本語の表記体系"@jpx <example:graph> .
<urn:example:subject> <example:predicate> <example:subject> <example:graph> .
<example:subject> <example:predicate> <example:object> <example:graph> .
<example:subject> <example:predicate> "12"^^<http://www.w3.org/2001/XMLSchema#integer> <example:graph> .
<example:subject> <example:predicate> <example:object> <urn:example:graph> .
<example:subject> <http://example.com/predicate> <http://example.com/object> <urn:example:graph> .
<example:subject> <http://example.com/predicate> "XSD string" <urn:example:graph> .
<example:subject> <example:predicate> <example:object> .
<http://example.com/subject> <http://example.com/predicate> "typeless" .
<urn:example:subject> <urn:example:predicate> <urn:example:object> .
27 changes: 27 additions & 0 deletions test/data/variants/diverse_quads.trig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@prefix egschema: <example:> .
@prefix eghttp: <http://example.com/> .
@prefix egurn: <urn:example:> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

egschema:graph {
eghttp:subject eghttp:predicate "日本語の表記体系"@jpx .

egurn:subject egschema:predicate egschema:subject .

egschema:subject egschema:predicate egschema:object,
12 .
}

egurn:graph {
egschema:subject egschema:predicate egschema:object ;
eghttp:predicate eghttp:object,
"XSD string"^^xsd:string .
}

{
egschema:subject egschema:predicate egschema:object .

eghttp:subject eghttp:predicate "typeless" .

egurn:subject egurn:predicate egurn:object .
}
4 changes: 4 additions & 0 deletions test/data/variants/diverse_triples-asserts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"quad_count": 5,
"exact_match": true
}
5 changes: 5 additions & 0 deletions test/data/variants/diverse_triples.hext
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
["urn:example:subject", "example:predicate", "example:subject", "globalId", "", ""]
["example:subject", "example:predicate", "example:object", "globalId", "", ""]
["example:object", "http://example.com/predicate", "XSD string", "http://www.w3.org/2001/XMLSchema#string", "", ""]
["http://example.com/subject", "http://example.com/predicate", "日本語の表記体系", "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString", "jpx", ""]
["example:subject", "example:predicate", "12", "http://www.w3.org/2001/XMLSchema#integer", "", ""]
40 changes: 40 additions & 0 deletions test/data/variants/diverse_triples.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"@graph": [
{
"@id": "egschema:object",
"eghttp:predicate": "XSD string"
},
{
"@id": "egschema:subject",
"egschema:predicate": [
12,
{
"@id": "egschema:object"
}
]
},
{
"@id": "eghttp:subject",
"eghttp:predicate": {
"@language": "jpx",
"@value": "日本語の表記体系"
}
},
{
"@id": "egurn:subject",
"egschema:predicate": {
"@id": "egschema:subject"
}
}
],
"@context": {
"predicate": {
"@id": "example:predicate",
"@type": "http://www.w3.org/2001/XMLSchema#integer"
},
"egurn": "urn:example:",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"egschema": "example:",
"eghttp": "http://example.com/"
}
}
5 changes: 5 additions & 0 deletions test/data/variants/diverse_triples.nt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<http://example.com/subject> <http://example.com/predicate> "日本語の表記体系"@jpx .
<urn:example:subject> <example:predicate> <example:subject> .
<example:object> <http://example.com/predicate> "XSD string" .
<example:subject> <example:predicate> <example:object> .
<example:subject> <example:predicate> "12"^^<http://www.w3.org/2001/XMLSchema#integer> .
13 changes: 13 additions & 0 deletions test/data/variants/diverse_triples.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@prefix eghttp: <http://example.com/> .
@prefix egurn: <urn:example:> .
@prefix egschema: <example:> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

eghttp:subject eghttp:predicate "日本語の表記体系"@jpx .

egurn:subject egschema:predicate egschema:subject .

egschema:object eghttp:predicate "XSD string"^^xsd:string .

egschema:subject egschema:predicate egschema:object,
12 .
4 changes: 4 additions & 0 deletions test/data/variants/more_quads-asserts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"quad_count": 6,
"exact_match": true
}
56 changes: 56 additions & 0 deletions test/data/variants/more_quads.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"@graph": [
{
"@graph": [
{
"@id": "example:s20",
"example:p20": {
"@id": "example:o20"
}
},
{
"@id": "example:s21",
"example:p21": {
"@id": "example:o21"
}
}
],
"@id": "example:g2"
},
{
"@id": "example:s00",
"p00": "example:o02"
},
{
"@id": "example:s01",
"p01": "example:o01"
},
{
"@id": "example:s10",
"p10": "example:o10"
},
{
"@id": "example:s11",
"p11": "example:o11"
}
],
"@context": {
"p10": {
"@id": "http://example.org/p10",
"@type": "@id"
},
"p01": {
"@id": "http://example.org/p01",
"@type": "@id"
},
"p00": {
"@id": "http://example.org/p00",
"@type": "@id"
},
"p11": {
"@id": "http://example.org/p11",
"@type": "@id"
},
"example": "http://example.org/"
}
}
6 changes: 6 additions & 0 deletions test/data/variants/more_quads.nq
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<http://example.org/s00> <http://example.org/p00> <http://example.org/o02> .
<http://example.org/s01> <http://example.org/p01> <http://example.org/o01> .
<http://example.org/s10> <http://example.org/p10> <http://example.org/o10> .
<http://example.org/s11> <http://example.org/p11> <http://example.org/o11> .
<http://example.org/s20> <http://example.org/p20> <http://example.org/o20> <http://example.org/g2> .
<http://example.org/s21> <http://example.org/p21> <http://example.org/o21> <http://example.org/g2> .
15 changes: 15 additions & 0 deletions test/data/variants/more_quads.trig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@prefix example: <http://example.org/>.

example:s00 example:p00 example:o02 .
example:s01 example:p01 example:o01 .


{
example:s10 example:p10 example:o10 .
example:s11 example:p11 example:o11 .
}

example:g2 {
example:s20 example:p20 example:o20 .
example:s21 example:p21 example:o21 .
}
12 changes: 12 additions & 0 deletions test/test_graph/test_variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,18 @@ def for_directory(
""",
raises=AssertionError,
),
("variants/diverse_quads"): pytest.mark.xfail(
reason="""
TriG parsing gets confused about what graph 'XSD string' appears in:
(rdflib.term.URIRef('example:subject'),
rdflib.term.URIRef('http://example.com/predicate'),
rdflib.term.Literal('XSD string'),
- rdflib.term.URIRef('example:graph')),
+ rdflib.term.URIRef('urn:example:graph')),
? ++++
""",
raises=AssertionError,
),
}


Expand Down
23 changes: 23 additions & 0 deletions test/test_roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,26 @@
""",
raises=AssertionError,
),
("json-ld", "diverse_quads.trig"): pytest.mark.xfail(
reason="""
jsonld serializer is dropping datatype:
only in first:
(rdflib.term.URIRef('example:subject'), rdflib.term.URIRef('http://example.com/predicate'), rdflib.term.Literal('XSD string', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#string')))
only in second:
(rdflib.term.URIRef('example:subject'), rdflib.term.URIRef('http://example.com/predicate'), rdflib.term.Literal('XSD string'))
""",
raises=AssertionError,
),
("hext", "diverse_quads.trig"): pytest.mark.xfail(
reason="""
hext serializer is dropping datatype:
only in first:
(rdflib.term.URIRef('example:subject'), rdflib.term.URIRef('http://example.com/predicate'), rdflib.term.Literal('XSD string', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#string')))
only in second:
(rdflib.term.URIRef('example:subject'), rdflib.term.URIRef('http://example.com/predicate'), rdflib.term.Literal('XSD string'))
""",
raises=AssertionError,
),
}

# This is for files which can only be represented properly in one format
Expand Down Expand Up @@ -291,6 +311,9 @@ def test_n3(checker: Callable[[str, str, Path], None], args: Tuple[str, str, Pat
(TEST_DATA_DIR / "variants" / "rdf_prefix.jsonld", "json-ld"),
(TEST_DATA_DIR / "variants" / "simple_quad.trig", "trig"),
(TEST_DATA_DIR / "variants" / "rdf11trig_eg2.trig", "trig"),
(TEST_DATA_DIR / "variants" / "diverse_triples.nt", "ntriples"),
(TEST_DATA_DIR / "variants" / "diverse_quads.nq", "nquads"),
(TEST_DATA_DIR / "variants" / "diverse_quads.trig", "trig"),
(TEST_DATA_DIR / "example-lots_of_graphs.n3", "n3"),
(TEST_DATA_DIR / "issue156.n3", "n3"),
]
Expand Down

0 comments on commit 09bbc64

Please sign in to comment.