Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92819811
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, Nov 23, 23:11
Size
2 KB
Mime Type
text/x-python
Expires
Mon, Nov 25, 23:11 (1 d, 18 h)
Engine
blob
Format
Raw Data
Handle
22522365
Attached To
rNIETZSCHEPYTHON nietzsche-python
test_class_spec.py
View Options
import
unittest
from
os
import
sep
,
path
import
inspect
from
datatypes.class_spec
import
SemanticClass
from
datatypes.image
import
Image
class
TestSemanticClassFail
(
SemanticClass
):
def
__init__
(
self
):
pass
class
TestSemanticClassOK
(
SemanticClass
):
def
__init__
(
self
):
self
.
msg
=
'Hello World!'
@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'
:
{
'data'
:
(
int
,
SemanticClass
.
LIST
),
'test'
:
(
TestSemanticClassOK
,
SemanticClass
.
LIST
)
}}
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
)
})
#self.assertEqual(test.get_data_dictionary()['body'], { 'msg': 'Hello World!'})
test
=
TestSemanticClassB
()
self
.
assertEqual
(
TestSemanticClassB
.
get_semantic_dictionary
()[
'properties'
],
{
'data'
:
(
int
,
SemanticClass
.
LIST
),
'test'
:
(
TestSemanticClassOK
,
SemanticClass
.
LIST
)
})
self
.
assertEqual
(
test
.
get_semantic_dictionary
()[
'class'
]
.
get
(
'this'
),
TestSemanticClassB
)
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
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Event Timeline
Log In to Comment