Skip to content

Commit e5f3f1f

Browse files
authored
Added test for example at CBD definition. Fixes #1914. (#1915)
We have added a test for the example at the definition for Concise Bounded Definition [here](https://www.w3.org/Submission/CBD/#example). Fixes #1914
1 parent 5e5dcea commit e5f3f1f

File tree

3 files changed

+149
-0
lines changed

3 files changed

+149
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0"?>
2+
3+
<rdf:RDF
4+
xmlns:rdf ="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
5+
xmlns:rdfs ="http://www.w3.org/2000/01/rdf-schema#"
6+
xmlns:owl ="http://www.w3.org/2002/07/owl#"
7+
xmlns:dc ="http://purl.org/dc/elements/1.1/"
8+
xmlns:dct ="http://purl.org/dc/terms/"
9+
xmlns:xsd ="http://www.w3.org/2001/XMLSchema#"
10+
xmlns:foaf ="http://xmlns.com/foaf/0.1/"
11+
xmlns:ex ="http://example.com/">
12+
13+
<rdf:Description rdf:about="http://example.com/aReallyGreatBook">
14+
<dc:title>A Really Great Book</dc:title>
15+
<dc:publisher>Examples-R-Us</dc:publisher>
16+
<dc:creator>
17+
<rdf:Description>
18+
<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
19+
<foaf:name>John Doe</foaf:name>
20+
<foaf:mbox>john@example.com</foaf:mbox>
21+
<foaf:img>
22+
<rdf:Description rdf:about="http://example.com/john.jpg">
23+
<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Image"/>
24+
<dc:format>image/jpeg</dc:format>
25+
<dc:extent>1234</dc:extent>
26+
</rdf:Description>
27+
</foaf:img>
28+
<foaf:phone rdf:resource="tel:+1-999-555-1234"/>
29+
</rdf:Description>
30+
</dc:creator>
31+
<dc:contributor>
32+
<rdf:Description>
33+
<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
34+
<foaf:name>Jane Doe</foaf:name>
35+
</rdf:Description>
36+
</dc:contributor>
37+
<dc:language>en</dc:language>
38+
<dc:format>application/pdf</dc:format>
39+
<dc:rights>Copyright (C) 2004 Examples-R-Us. All rights reserved.</dc:rights>
40+
<dct:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2004-01-19</dct:issued>
41+
<rdfs:seeAlso rdf:resource="http://example.com/anotherGreatBook"/>
42+
</rdf:Description>
43+
44+
<rdf:Statement>
45+
<rdf:subject rdf:resource="http://example.com/aReallyGreatBook"/>
46+
<rdf:predicate rdf:resource="http://purl.org/dc/elements/1.1/format"/>
47+
<rdf:object>application/pdf</rdf:object>
48+
<rdfs:isDefinedBy rdf:resource="http://example.com/book-formats.rdf"/>
49+
</rdf:Statement>
50+
51+
<rdf:Statement>
52+
<rdf:subject rdf:resource="http://xmlns.com/foaf/0.1/Image"/>
53+
<rdf:predicate rdf:resource="http://purl.org/dc/elements/1.1/format"/>
54+
<rdf:object>image/jpeg</rdf:object>
55+
<rdfs:isDefinedBy rdf:resource="http://example.com/image-formats.rdf"/>
56+
</rdf:Statement>
57+
58+
<rdf:Description rdf:about="http://example.com/anotherGreatBook">
59+
<dc:title>Another Great Book</dc:title>
60+
<dc:publisher>Examples-R-Us</dc:publisher>
61+
<dc:creator>June Doe (june@example.com)</dc:creator>
62+
<dc:format>application/pdf</dc:format>
63+
<dc:language>en</dc:language>
64+
<dc:rights>Copyright (C) 2004 Examples-R-Us. All rights reserved.</dc:rights>
65+
<dct:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2004-05-03</dct:issued>
66+
<rdfs:seeAlso rdf:resource="http://example.com/aReallyGreatBook"/>
67+
</rdf:Description>
68+
69+
<rdf:Description rdf:about="http://example.com/aBookCritic">
70+
<ex:likes rdf:resource="http://example.com/aReallyGreatBook"/>
71+
<ex:dislikes rdf:resource="http://example.com/anotherGreatBook"/>
72+
</rdf:Description>
73+
74+
<rdf:Property rdf:about="http://xmlns.com/foaf/0.1/mbox">
75+
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#InverseFunctionalProperty"/>
76+
</rdf:Property>
77+
78+
</rdf:RDF>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0"?>
2+
3+
<rdf:RDF
4+
xmlns:rdf ="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
5+
xmlns:rdfs ="http://www.w3.org/2000/01/rdf-schema#"
6+
xmlns:owl ="http://www.w3.org/2002/07/owl#"
7+
xmlns:dc ="http://purl.org/dc/elements/1.1/"
8+
xmlns:dct ="http://purl.org/dc/terms/"
9+
xmlns:xsd ="http://www.w3.org/2001/XMLSchema#"
10+
xmlns:foaf ="http://xmlns.com/foaf/0.1/">
11+
12+
<rdf:Description rdf:about="http://example.com/aReallyGreatBook">
13+
<dc:title>A Really Great Book</dc:title>
14+
<dc:publisher>Examples-R-Us</dc:publisher>
15+
<dc:creator>
16+
<rdf:Description>
17+
<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
18+
<foaf:name>John Doe</foaf:name>
19+
<foaf:mbox>john@example.com</foaf:mbox>
20+
<foaf:img rdf:resource="http://example.com/john.jpg"/>
21+
<foaf:phone rdf:resource="tel:+1-999-555-1234"/>
22+
</rdf:Description>
23+
</dc:creator>
24+
<dc:contributor>
25+
<rdf:Description>
26+
<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
27+
<foaf:name>Jane Doe</foaf:name>
28+
</rdf:Description>
29+
</dc:contributor>
30+
<dc:language>en</dc:language>
31+
<dc:format>application/pdf</dc:format>
32+
<dc:rights>Copyright (C) 2004 Examples-R-Us. All rights reserved.</dc:rights>
33+
<dct:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2004-01-19</dct:issued>
34+
<rdfs:seeAlso rdf:resource="http://example.com/anotherGreatBook"/>
35+
</rdf:Description>
36+
37+
<rdf:Statement>
38+
<rdf:subject rdf:resource="http://example.com/aReallyGreatBook"/>
39+
<rdf:predicate rdf:resource="http://purl.org/dc/elements/1.1/format"/>
40+
<rdf:object>application/pdf</rdf:object>
41+
<rdfs:isDefinedBy rdf:resource="http://example.com/book-formats.rdf"/>
42+
</rdf:Statement>
43+
44+
</rdf:RDF>

test/test_graph/test_graph_cbd.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
import os
2+
from test.data import TEST_DATA_DIR
3+
from test.utils import GraphHelper
4+
15
import pytest
26

37
from rdflib import Graph, Namespace
8+
from rdflib.compare import isomorphic
9+
from rdflib.term import URIRef
10+
11+
EXAMPLE_GRAPH_FILE_PATH = TEST_DATA_DIR / "spec" / "cbd" / "example_graph.rdf"
12+
EXAMPLE_GRAPH_CBD_FILE_PATH = TEST_DATA_DIR / "spec" / "cbd" / "example_graph_cbd.rdf"
413

514
"""Tests the Graph class' cbd() function"""
615

@@ -109,3 +118,21 @@ def testCbdReified(get_graph):
109118
)
110119

111120
assert len(g.cbd(EX.R6)) == (3 + 5 + 5), "cbd() for R6 should return 12 triples"
121+
122+
123+
def test_cbd_example():
124+
"""
125+
Example from Concise Bounded Description definition at https://www.w3.org/Submission/CBD/#example
126+
"""
127+
g = Graph()
128+
g.parse(EXAMPLE_GRAPH_FILE_PATH)
129+
130+
g_cbd = Graph()
131+
g_cbd.parse(EXAMPLE_GRAPH_CBD_FILE_PATH)
132+
133+
query = "http://example.com/aReallyGreatBook"
134+
GraphHelper.assert_isomorphic(g.cbd(URIRef(query)), g_cbd)
135+
GraphHelper.assert_sets_equals(g.cbd(URIRef(query)), g_cbd, exclude_blanks=True)
136+
assert len(g.cbd(URIRef(query))) == (
137+
21
138+
), "cbd() for aReallyGreatBook should return 21 triples"

0 commit comments

Comments
 (0)