Page MenuHomec4science

test_data_handler.py
No OneTemporary

File Metadata

Created
Fri, May 3, 08:38

test_data_handler.py

import unittest
from os import sep, path
from os.path import dirname, isfile
import inspect
from rdflib import Graph, URIRef, Literal, BNode, OWL, RDF, RDFS, XSD
import rdflib
import sys
sys.path.append('shared_util')
from myxmlwriter import xml2dict
sys.path.append('svgscripts')
from datatypes.image import Image
from datatypes.page import Page
from datatypes.text_field import TextField
sys.path.append('py2ttl')
from data_handler import RDFDataHandler
class TestRDFDataHandler(unittest.TestCase):
def setUp(self):
RDFDataHandler.UNITTESTING = True
DATADIR = dirname(__file__) + sep + 'test_data'
self.mapping_dictionary = xml2dict(DATADIR + sep + 'mapping_dict.xml')
self.xml_file = DATADIR + sep + 'N_VII_1_page001.xml'
def test_add_data(self):
data_handler = RDFDataHandler('test.ttl', self.mapping_dictionary)
page = Page(self.xml_file)
data_handler.add_data(page, page.title.replace(' ', '_'))
#print(data_handler.data_graph.serialize(format="turtle"))
#data_handler.write()
def test_init(self):
with self.assertRaises(Exception):
RDFDataHandler(None, {})
mapping_dictionary = { 'ontology': { 'project_name': 'test', 'project_uri': 'test' }}
data_handler = RDFDataHandler('test.ttl', mapping_dictionary)
self.assertEqual(data_handler.project_name, 'test')
def test_create_identifier_uri(self):
tf = TextField()
mapping_dictionary = { 'ontology': { 'project_name': 'test', 'project_uri': 'test' }}
data_handler = RDFDataHandler('test.ttl', mapping_dictionary)
identifier_uri = data_handler.create_identifier_uri(tf, 'asdf')
data_handler.data_graph.add((identifier_uri, RDF.type, OWL.Class))
next_identifier_uri = data_handler.create_identifier_uri(tf, 'asdf')
self.assertEqual(identifier_uri != next_identifier_uri, True)
if __name__ == "__main__":
unittest.main()

Event Timeline