Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F62405561
test_box.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
Sun, May 12, 23:39
Size
3 KB
Mime Type
text/x-python
Expires
Tue, May 14, 23:39 (2 d)
Engine
blob
Format
Raw Data
Handle
17643398
Attached To
rNIETZSCHEPYTHON nietzsche-python
test_box.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.box
import
Box
from
datatypes.path
import
Path
from
datatypes.transkription_position
import
TranskriptionPosition
from
datatypes.positional_word_part
import
PositionalWordPart
class
TestBox
(
unittest
.
TestCase
):
def
setUp
(
self
):
DATADIR
=
path
.
dirname
(
__file__
)
+
sep
+
'test_data'
self
.
test_file
=
DATADIR
+
sep
+
'N_VII_1_page009.xml'
self
.
pdf_xml
=
DATADIR
+
sep
+
'W_I_8_page125.xml'
self
.
pdf_xml_source
=
DATADIR
+
sep
+
'W_I_8_neu_125-01.svg'
def
test_init
(
self
):
path
=
Box
(
path
=
parse_path
(
'M 0, 0 L 10, 0 L 10, 10 L 0, 10 z'
),
style_class
=
'st10'
)
self
.
assertEqual
(
path
.
tag
,
'box-path'
)
self
.
assertEqual
(
path
.
path
.
isclosed
(),
True
)
def
test_attach_object_to_tree
(
self
):
svg_path
=
parse_path
(
'M 0, 0 L 10, 0 L 10, 10 L 0, 10 z'
)
path
=
Box
(
path
=
svg_path
,
style_class
=
'st10'
)
empty_tree
=
ET
.
ElementTree
(
ET
.
Element
(
'page'
))
path
.
attach_object_to_tree
(
empty_tree
)
self
.
assertEqual
(
path
.
tag
,
Box
.
XML_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(Box.get_semantic_dictionary())
pass
def
test_create_box
(
self
):
box_path_d
=
[
'M 598.11,626.565 L 603.557,626.565 L 603.557,632.565 L 598.11,632.565 L 598.11,626.565'
,
\
'M 557.443,683.44 L 574.182,683.44 L 574.182,694.815 L 557.443,694.815 L 557.443,683.44'
,
\
'M 404.193,659.565 L 407.80699999999996,659.565 L 407.80699999999996,668.94 L 404.193,668.94 L 404.193,659.565'
,
\
'M 587.932,634.065 L 598.318,634.065 L 598.318,643.19 L 587.932,643.19 L 587.932,634.065'
,
\
'M 570.443,221.315 L 576.557,221.315 L 576.557,230.065 L 570.443,230.065 L 570.443,221.315'
]
box_paths
=
sorted
([
Path
(
d_string
=
d_string
,
tag
=
Path
.
BOX_TAG
)
for
d_string
in
box_path_d
],
key
=
lambda
path
:
path
.
get_median_y
())
margin_path_d_strings
=
[
'M 287.711,225.753 L 294.803,225.753'
,
\
'M 289.371,664.353 L 294.803,664.353'
,
\
'M 269.809,690.153 L 294.803,690.153'
,
\
'M 277.068,638.55 L 282.5,638.55'
,
\
'M 288.134,624.79 L 294.803,624.79 L 294.803,634.0899999999999 L 288.134,634.0899999999999 L 288.134,624.79'
]
margin_paths
=
[
Path
(
d_string
=
d_string
)
for
d_string
in
margin_path_d_strings
]
text
=
[
'a'
,
')'
,
','
,
':'
,
'Denn'
]
for
index
in
range
(
0
,
len
(
box_paths
)):
path
=
box_paths
[
index
]
box
=
Box
.
create_box
(
path
,
margin_paths
,
svg_source
=
self
.
pdf_xml_source
)
self
.
assertEqual
(
box
is
not
None
,
True
)
self
.
assertEqual
(
box
.
earlier_text
,
text
[
index
])
if
__name__
==
"__main__"
:
unittest
.
main
()
Event Timeline
Log In to Comment