-
Notifications
You must be signed in to change notification settings - Fork 560
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for issue 248, GCraph.serialize() + base kwarg
- Loading branch information
Showing
1 changed file
with
130 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import rdflib | ||
from nose.exc import SkipTest | ||
import unittest | ||
|
||
|
||
class TestSerialization(unittest.TestCase): | ||
|
||
def test_issue_248(self): | ||
""" | ||
Ed Summers Thu, 24 May 2007 12:21:17 -0700 | ||
As discussed with eikeon in #redfoot it appears that the n3 serializer | ||
is ignoring the base option to Graph.serialize...example follows: | ||
-- | ||
#!/usr/bin/env python | ||
from rdflib.Graph import Graph | ||
from rdflib.URIRef import URIRef | ||
from rdflib import Literal, Namespace, RDF | ||
graph = Graph() | ||
DC = Namespace('http://purl.org/dc/terms/') | ||
SKOS = Namespace('http://www.w3.org/2004/02/skos/core#') | ||
LCCO = Namespace('http://loc.gov/catdir/cpso/lcco/') | ||
graph.bind('dc', DC) | ||
graph.bind('skos', SKOS) | ||
graph.bind('lcco', LCCO) | ||
concept = URIRef(LCCO['1']) | ||
graph.add((concept, RDF.type, SKOS['Concept'])) | ||
graph.add((concept, SKOS['prefLabel'], Literal('Scrapbooks'))) | ||
graph.add((concept, DC['LCC'], Literal('AC999.0999 - AC999999.Z9999'))) | ||
print graph.serialize(format='n3', base=LCCO) | ||
-- | ||
Which generates: | ||
-- | ||
@prefix dc: <http://purl.org/dc/terms/>. | ||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. | ||
@prefix skos: <http://www.w3.org/2004/02/skos/core#>. | ||
<http://loc.gov/catdir/cpso/lcco/1> a skos:Concept; | ||
dc:LCC "AC999.0999 - AC999999.Z9999"; | ||
skos:prefLabel "Scrapbooks". | ||
-- | ||
Notice | ||
<http://loc.gov/catdir/cpso/lcco/1> a skos:Concept; | ||
instead of: | ||
<1> a skos:Concept; | ||
//Ed | ||
""" | ||
graph = rdflib.Graph() | ||
DC = rdflib.Namespace('http://purl.org/dc/terms/') | ||
SKOS = rdflib.Namespace('http://www.w3.org/2004/02/skos/core#') | ||
LCCO = rdflib.Namespace('http://loc.gov/catdir/cpso/lcco/') | ||
|
||
graph.bind('dc', DC) | ||
graph.bind('skos', SKOS) | ||
graph.bind('lcco', LCCO) | ||
|
||
concept = rdflib.URIRef(LCCO['1']) | ||
graph.add( | ||
(concept, | ||
rdflib.RDF.type, | ||
SKOS['Concept'])) | ||
graph.add( | ||
(concept, | ||
SKOS['prefLabel'], | ||
rdflib.Literal('Scrapbooks'))) | ||
graph.add( | ||
(concept, | ||
DC['LCC'], | ||
rdflib.Literal('AC999.0999 - AC999999.Z9999'))) | ||
sg = graph.serialize(format='n3', base=LCCO) | ||
# See issue 248 | ||
self.assert_( | ||
'<http://loc.gov/catdir/cpso/lcco/1>' in sg, sg) # BAD BAD | ||
# Actual test should be the inverse of the below ... | ||
self.assert_('<1> a skos:Concept ;' not in sg, sg) | ||
|
||
def test_base(self): | ||
""" | ||
Further investigations | ||
""" | ||
|
||
raise SkipTest("base kwarg under investigation") | ||
|
||
gp = """\ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<rdf:RDF | ||
xmlns:lcco="http://loc.gov/catdir/cpso/lcco/" | ||
xmlns:dc="http://purl.org/dc/terms/" | ||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | ||
xmlns:skos="http://www.w3.org/2004/02/skos/core#" | ||
> | ||
<rdf:Description rdf:about="lcco:1"> | ||
<dc:LCC>AC999.0999 - AC999999.Z9999</dc:LCC> | ||
<rdf:type | ||
rdf:resource="http://www.w3.org/2004/02/skos/core#Concept"/> | ||
<skos:prefLabel>Scrapbooks</skos:prefLabel> | ||
</rdf:Description> | ||
</rdf:RDF> | ||
""" | ||
DC = rdflib.Namespace('http://purl.org/dc/terms/') | ||
SKOS = rdflib.Namespace('http://www.w3.org/2004/02/skos/core#') | ||
LCCO = rdflib.Namespace('http://loc.gov/catdir/cpso/lcco/') | ||
graph = rdflib.Graph() | ||
graph.bind('dc', DC) | ||
graph.bind('skos', SKOS) | ||
graph.bind('lcco', LCCO) | ||
graph.parse(data=gp, format="xml") | ||
sg = graph.serialize(format='n3', base=LCCO) | ||
self.assert_('<1> a skos:Concept ;' not in sg, sg) # BAD BAD BAD | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |