Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F74440430
test_class_spec.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
Sat, Jul 27, 20:34
Size
3 KB
Mime Type
text/x-python
Expires
Mon, Jul 29, 20:34 (2 d)
Engine
blob
Format
Raw Data
Handle
19394256
Attached To
rNIETZSCHEPYTHON nietzsche-python
test_class_spec.py
View Options
import
unittest
from
os
import
sep
,
path
import
inspect
from
rdflib
import
Graph
,
URIRef
,
Literal
,
BNode
,
OWL
,
RDF
,
RDFS
,
XSD
import
sys
sys
.
path
.
append
(
'svgscripts'
)
from
datatypes.image
import
Image
from
datatypes.word
import
Word
from
datatypes.simple_word
import
SimpleWord
sys
.
path
.
append
(
'py2ttl'
)
try
:
from
class_spec
import
SemanticClass
except
ImportError
:
sys
.
path
.
append
(
dirname
(
dirname
(
realpath
(
__file__
))))
from
py2ttl.class_spec
import
SemanticClass
class
TestSemanticClassFail
(
SemanticClass
):
def
__init__
(
self
):
pass
class
Dummy
:
def
__init__
(
self
,
id
):
self
.
id
=
id
class
TestSemanticClassOK
(
SemanticClass
):
def
__init__
(
self
):
self
.
msg
=
'Hello World!'
self
.
id
=
0
self
.
mylist
=
[
Dummy
(
0
),
Dummy
(
1
),
Dummy
(
2
)
]
@staticmethod
def
get_semantic_dictionary
():
return
{
'class'
:
{
'this'
:
TestSemanticClassOK
},
'properties'
:
{
'msg'
:
(
str
,
SemanticClass
.
SINGLE_VALUE
)
}}
class
TestSemanticClassB
(
SemanticClass
):
def
__init__
(
self
):
self
.
data
=
[
1
,
2
,
3
,
4
]
self
.
test
=
[
TestSemanticClassOK
(),
TestSemanticClassOK
()
]
@staticmethod
def
get_semantic_dictionary
():
return
{
'class'
:
{
'this'
:
TestSemanticClassB
},
'properties'
:
TestSemanticClassB
.
create_semantic_property_dictionary
(
'data'
,
int
)}
def
get_super
(
self
):
return
inspect
.
getclasstree
([
self
.
__class__
],
unique
=
True
)[
0
][
0
]
class
TestSemanticClassC
(
TestSemanticClassB
):
pass
class
TestSemanticClass
(
unittest
.
TestCase
):
def
test_fail
(
self
):
with
self
.
assertRaises
(
TypeError
):
TestSemanticClassFail
()
def
test_success
(
self
):
test
=
TestSemanticClassOK
()
self
.
assertEqual
(
TestSemanticClassOK
.
get_semantic_dictionary
()[
'properties'
],
{
'msg'
:
(
str
,
1
)
})
test
=
TestSemanticClassB
()
self
.
assertEqual
(
test
.
get_semantic_dictionary
()[
'class'
]
.
get
(
'this'
),
TestSemanticClassB
)
dictionary
=
test
.
return_dictionary_after_updating_super_classes
(
TestSemanticClassB
.
get_semantic_dictionary
())
def
test_get_class_dictionary
(
self
):
test
=
TestSemanticClassC
()
self
.
assertEqual
(
test
.
get_class_dictionary
()
.
get
(
'type'
)
is
not
None
,
True
)
self
.
assertEqual
(
test
.
get_class_dictionary
()
.
get
(
'type'
),
TestSemanticClassB
)
#print(test.create_semantic_property_dictionary('is_true', bool, cardinality=1, name='IsTrue', label='is true', comment='test comment'))
def
test_get_cls_hasPart_objectCls_dictionaries
(
self
):
dictionary
=
SemanticClass
.
get_cls_hasPart_objectCls_dictionaries
(
SemanticClass
,
'asdf/asdf'
)
#print(dictionary)
def
test_get_object_from_list_with_id
(
self
):
test
=
TestSemanticClassOK
()
#mylist = test._get_list_of_type(Dummy)
d_1
=
test
.
get_object_from_list_with_id
(
Dummy
,
1
)
self
.
assertEqual
(
d_1
is
not
None
,
True
)
self
.
assertEqual
(
d_1
.
id
,
1
)
def
test_return_dictionary_after_updating_super_classes
(
self
):
class
TestWord
(
Word
):
RDFS_SUBCLASSOF_LIST
=
[
'http://www.example.com#Test'
]
dictionary
=
TestWord
.
get_semantic_dictionary
()
self
.
assertEqual
(
TestWord
.
SUBCLASS_OF
in
dictionary
[
TestWord
.
CLASS_KEY
]
.
keys
(),
True
)
self
.
assertEqual
(
len
(
dictionary
[
TestWord
.
CLASS_KEY
][
TestWord
.
SUBCLASS_OF
]),
2
)
def
test_repr
(
self
):
word
=
Word
()
#print(word)
if
__name__
==
"__main__"
:
unittest
.
main
()
Event Timeline
Log In to Comment