Skip to content

Commit

Permalink
added tests for dumping dictionaryprovider to rdf
Browse files Browse the repository at this point in the history
  • Loading branch information
dieuska committed May 20, 2014
1 parent 2bdcd56 commit 68412ca
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 22 deletions.
4 changes: 2 additions & 2 deletions skosprovider_rdf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def rdf_dumper(provider):
for l in c.labels:
predicate = URIRef(SKOS + l.type)
lang = l.language
if lang:
if isinstance(lang, bytes):
lang = lang.decode("UTF-8")
graph.add((subject, predicate, Literal(l.label, lang=lang)))
if isinstance(c, Concept):
Expand All @@ -55,7 +55,7 @@ def rdf_dumper(provider):
for n in c.notes:
predicate = URIRef(SKOS + "#" + n.type)
lang = n.language
if lang:
if isinstance(lang, bytes):
lang = lang.decode("UTF-8")
graph.add((subject, predicate, Literal(n.note, lang=lang)))
elif isinstance(c, Collection):
Expand Down
120 changes: 100 additions & 20 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
from rdflib import Graph
from rdflib.namespace import RDF, SKOS
from skosprovider.providers import DictionaryProvider
from skosprovider_rdf.providers import RDFProvider
from skosprovider_rdf import utils
from rdflib.term import URIRef
Expand All @@ -17,33 +18,112 @@ def setUp(self):
# Set up testdata
self._create_test_data()

# Set up provider
self.provider = RDFProvider(
{'id': 'PRODUCTS', 'conceptscheme_id': 1}, self.graph)

def tearDown(self):
return
del self.larch_dump
del self.chestnut_dump
del self.world_dump

def _create_test_data(self):
self.graph = Graph()
filepath=os.path.dirname(os.path.realpath(__file__))
abspath=os.path.abspath(filepath + "/data/simple_turtle_products")
filepath = os.path.dirname(os.path.realpath(__file__))
abspath = os.path.abspath(filepath + "/data/simple_turtle_products")
self.graph.parse(abspath, format="turtle")

self.u_products=URIRef("http://www.products.com/")
self.u_jewellery=URIRef("http://www.products.com/Jewellery")
self.u_perfume=URIRef("http://www.products.com/Perfume")
self.u_product=URIRef("http://www.products.com/Product")
self.u_stuff=URIRef("http://www.products.com/Stuff")
self.u_products = URIRef("http://www.products.com/")
self.u_jewellery = URIRef("http://www.products.com/Jewellery")
self.u_perfume = URIRef("http://www.products.com/Perfume")
self.u_product = URIRef("http://www.products.com/Product")
self.u_stuff = URIRef("http://www.products.com/Stuff")

self.larch_dump = {
'id': '1',
'uri': 'http://id.trees.org/1',
'type': 'concept',
'labels': [
{'type': 'prefLabel', 'language': 'en', 'label': 'The Larch'},
{'type': 'prefLabel', 'language': 'nl', 'label': 'De Lariks'}
],
'notes': [
{'type': 'definition',
'language': 'en',
'note': 'A type of tree.'}
],
'narrower': [],
'broader': [],
'related': [],
'member_of': ['3']
}
self.chestnut_dump = {
'id': '2',
'uri': 'http://id.trees.org/2',
'type': 'concept',
'labels': [
{'type': 'prefLabel',
'language': 'en',
'label': 'The Chestnut'},
{'type': 'altLabel',
'language': 'nl',
'label': 'De Paardekastanje'},
{'type': 'altLabel',
'language': 'fr',
'label': 'la châtaigne'}
],
'notes': [
{
'type': 'definition', 'language': 'en',
'note': 'A different type of tree.'
}
],
'narrower': [],
'broader': [],
'related': [],
'member_of': ['3']
}
self.species_dump = {
'id': 3,
'uri': 'http://id.trees.org/3',
'labels': [
{'type': 'prefLabel', 'language': 'en', 'label': 'Trees by species'},
{'type': 'prefLabel', 'language': 'nl', 'label': 'Bomen per soort'}
],
'type': 'collection',
'members': ['1', '2'],
'member_of': []
}
self.world_dump = {
'id': '1',
'uri': 'urn:x-skosprovider:geography:1',
'type': 'concept',
'labels': [
{'type': 'prefLabel', 'language': 'en', 'label': 'World'}
],
'notes': [
],
'narrower': [2, 3],
'broader': [],
'related': [],
'member_of': []
}

self.tree_provider = DictionaryProvider({'id': 'TREE'}, [self.larch_dump,self.chestnut_dump,self.species_dump])
self.world_provider = DictionaryProvider({'id': 'WORLD'}, [self.world_dump])
# Set up rdf_provider
self.rdf_products_provider = RDFProvider(
{'id': 'PRODUCTS', 'conceptscheme_id': 1}, self.graph)

def test_dump_rdf_to_rdf(self):
graph_dump = utils.rdf_dumper(self.rdf_products_provider)
xml = graph_dump.serialize(format='xml', encoding="UTF-8").decode()
self.assertEquals("<?xml", xml[:5])

def test_include(self):
return
def test_dump_rdf_compare_type(self):
graph_dump = utils.rdf_dumper(self.rdf_products_provider)
self.assertEquals(type(graph_dump), Graph)

def test_dump_rdf(self):
graph_dump=utils.rdf_dumper(self.provider)
xml=graph_dump.serialize(format='xml',encoding="UTF-8").decode()
def test_dump_tree_to_rdf(self):
graph_dump = utils.rdf_dumper(self.tree_provider)
xml = graph_dump.serialize(format='xml', encoding="UTF-8").decode()
self.assertEquals("<?xml", xml[:5])

def test_compare_dump_rdf(self):
graph_dump=utils.rdf_dumper(self.provider)
self.assertEquals(type(graph_dump),Graph)
def test_include_me(self):
return

0 comments on commit 68412ca

Please sign in to comment.