Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F62649154
test_path.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
Tue, May 14, 14:36
Size
2 KB
Mime Type
text/x-python
Expires
Thu, May 16, 14:36 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
17672799
Attached To
rNIETZSCHEPYTHON nietzsche-python
test_path.py
View Options
import
unittest
from
os
import
sep
,
path
from
os.path
import
isdir
,
dirname
,
basename
import
lxml.etree
as
ET
from
svgpathtools.parser
import
parse_path
import
sys
import
sys
sys
.
path
.
append
(
'svgscripts'
)
from
datatypes.path
import
Path
from
datatypes.transkription_position
import
TranskriptionPosition
from
datatypes.positional_word_part
import
PositionalWordPart
class
TestPath
(
unittest
.
TestCase
):
def
test_init
(
self
):
tag
=
'word-deletion-path'
path
=
Path
(
tag
=
tag
,
path
=
parse_path
(
'M 0, 0 L 10, 0 L 10, 10 L 0, 10 z'
),
style_class
=
'st10'
)
self
.
assertEqual
(
path
.
tag
,
tag
)
self
.
assertEqual
(
path
.
path
.
isclosed
(),
True
)
def
test_attach_object_to_tree
(
self
):
tag
=
'word-deletion-path'
svg_path
=
parse_path
(
'M 0, 0 L 10, 0 L 10, 10 L 0, 10 z'
)
path
=
Path
(
tag
=
tag
,
path
=
svg_path
,
style_class
=
'st10'
)
empty_tree
=
ET
.
ElementTree
(
ET
.
Element
(
'page'
))
path
.
attach_object_to_tree
(
empty_tree
)
self
.
assertEqual
(
path
.
tag
,
tag
)
for
node
in
empty_tree
.
getroot
()
.
xpath
(
'//'
+
path
.
tag
):
self
.
assertEqual
(
node
.
get
(
'id'
),
'0'
)
self
.
assertEqual
(
parse_path
(
node
.
get
(
'd'
)),
svg_path
)
def
test_get_semantic_dict
(
self
):
#print(Path.get_semantic_dictionary())
pass
def
test_create_path_from_transkription_position
(
self
):
pwp
=
PositionalWordPart
(
height
=
10
,
width
=
10
)
tp
=
TranskriptionPosition
(
positional_word_parts
=
[
pwp
])
path
=
Path
.
create_path_from_transkription_position
(
tp
)
xmin
,
xmax
,
ymin
,
ymax
=
path
.
path
.
bbox
()
self
.
assertEqual
(
xmin
,
0
)
self
.
assertEqual
(
xmax
,
10
)
self
.
assertEqual
(
ymin
,
0
)
self
.
assertEqual
(
ymax
,
10
)
def
test_contains_path
(
self
):
pwp1
=
PositionalWordPart
(
height
=
10
,
width
=
10
)
tp1
=
TranskriptionPosition
(
positional_word_parts
=
[
pwp1
])
pwp2
=
PositionalWordPart
(
height
=
8
,
width
=
8
)
tp2
=
TranskriptionPosition
(
positional_word_parts
=
[
pwp2
])
path1
=
Path
.
create_path_from_transkription_position
(
tp1
)
path2
=
Path
.
create_path_from_transkription_position
(
tp2
)
self
.
assertEqual
(
path1
.
contains_path
(
path2
),
True
)
self
.
assertEqual
(
path2
.
contains_path
(
path1
),
False
)
pwp3
=
PositionalWordPart
(
height
=
8
,
width
=
18
)
tp3
=
TranskriptionPosition
(
positional_word_parts
=
[
pwp3
])
path3
=
Path
.
create_path_from_transkription_position
(
tp3
)
self
.
assertEqual
(
path3
.
is_partially_contained_by
(
path1
),
True
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Event Timeline
Log In to Comment