Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F66444969
test_attachable_object.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
Mon, Jun 10, 14:08
Size
1 KB
Mime Type
text/x-python
Expires
Wed, Jun 12, 14:08 (2 d)
Engine
blob
Format
Raw Data
Handle
18223343
Attached To
rNIETZSCHEPYTHON nietzsche-python
test_attachable_object.py
View Options
import
unittest
from
os
import
sep
,
path
import
lxml.etree
as
ET
import
sys
sys
.
path
.
append
(
'svgscripts'
)
from
datatypes.attachable_object
import
AttachableObject
class
TestObjectFail
(
AttachableObject
):
def
__init__
(
self
):
pass
class
TestObjectOK
(
AttachableObject
):
def
__init__
(
self
):
self
.
id
=
1
def
attach_object_to_tree
(
self
,
target_tree
):
return
True
class
TestPositionalObject
(
unittest
.
TestCase
):
def
test_fail
(
self
):
with
self
.
assertRaises
(
TypeError
):
TestObjectFail
()
def
test_success
(
self
):
test
=
TestObjectOK
()
self
.
assertEqual
(
test
.
attach_object_to_tree
(
ET
.
ElementTree
(
ET
.
Element
(
'asdf'
))),
True
)
def
test_get_or_create_node
(
self
):
test
=
TestObjectOK
()
tree
=
ET
.
ElementTree
(
ET
.
Element
(
'asdf'
))
node
=
test
.
get_or_create_node
(
tree
)
self
.
assertEqual
(
node
.
tag
,
test
.
XML_TAG
)
tree
=
ET
.
Element
(
'asdf'
)
node
=
test
.
get_or_create_node
(
tree
)
self
.
assertEqual
(
node
.
tag
,
test
.
XML_TAG
)
tree
=
ET
.
Element
(
'asdf'
)
node
=
test
.
get_or_create_node_with_id
(
tree
)
self
.
assertEqual
(
node
.
tag
,
test
.
XML_TAG
)
test
.
id
=
2
node
=
test
.
get_or_create_node_with_id
(
tree
)
node
=
test
.
get_or_create_node_with_id
(
tree
)
#print(ET.dump(tree))
self
.
assertEqual
(
len
(
tree
.
xpath
(
test
.
XML_TAG
)),
2
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Event Timeline
Log In to Comment