Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F60914063
test_data_handler.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, May 3, 08:38
Size
1 KB
Mime Type
text/x-python
Expires
Sun, May 5, 08:38 (2 d)
Engine
blob
Format
Raw Data
Handle
17403322
Attached To
rNIETZSCHEPYTHON nietzsche-python
test_data_handler.py
View Options
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
Log In to Comment