Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F61563781
test_transformSVG2TranskriptionField.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 7, 11:40
Size
4 KB
Mime Type
text/x-python
Expires
Thu, May 9, 11:40 (2 d)
Engine
blob
Format
Raw Data
Handle
17528770
Attached To
rNIETZSCHEPYTHON nietzsche-python
test_transformSVG2TranskriptionField.py
View Options
import
unittest
import
xml.etree.ElementTree
as
ET
from
xml.parsers.expat
import
ExpatError
import
os
from
os
import
sep
,
path
from
os.path
import
isfile
,
isdir
,
dirname
from
svgpathtools
import
svg_to_paths
import
sys
sys
.
path
.
append
(
'svgscripts'
)
from
datatypes.transkriptionField
import
TranskriptionField
def
createEmptySVGFile
():
""" Creates an empty file and returns the name of this file.
:return: (str) file name
"""
empty_file
=
'empty.svg'
if
not
bool
(
os
.
path
.
exists
(
empty_file
)):
root
=
ET
.
Element
(
'svg'
)
ET
.
SubElement
(
root
,
'g'
)
et
=
ET
.
ElementTree
(
root
)
et
.
write
(
empty_file
)
return
empty_file
def
deleteFile
(
file_name
):
"""Deletes file.
"""
bool
(
os
.
path
.
exists
(
file_name
))
and
os
.
remove
(
file_name
)
class
TestTF
(
unittest
.
TestCase
):
def
setUp
(
self
):
DATADIR
=
dirname
(
__file__
)
+
sep
+
'test_data'
self
.
test_file
=
DATADIR
+
sep
+
'test_ai.svg'
self
.
test_tr
=
TranskriptionField
(
self
.
test_file
)
self
.
empty_file
=
createEmptySVGFile
()
self
.
svg_test_file
=
'python_test.svg'
self
.
test_empty_file
=
DATADIR
+
sep
+
'my_empty_test.svg'
self
.
verso_svg
=
DATADIR
+
sep
+
'W_I_8_neu_125-01.svg'
self
.
recto_svg
=
DATADIR
+
sep
+
'N_VII_1_xp5_4_page6.svg'
self
.
multipage
=
DATADIR
+
sep
+
'multipage_small_above.svg'
def
test_init_tf
(
self
):
""" Tests init function of transformSVG2TranskriptionField.TranskriptionField.
"""
self
.
assertEqual
(
self
.
test_tr
.
transkription_field_found
(),
True
)
with
self
.
assertRaises
(
ExpatError
):
TranskriptionField
(
self
.
test_empty_file
)
multi_tf_above
=
TranskriptionField
(
self
.
multipage
,
multipage_index
=
0
)
self
.
assertEqual
(
multi_tf_above
.
transkription_field_found
(),
True
)
multi_tf_beneath
=
TranskriptionField
(
self
.
multipage
,
multipage_index
=
1
)
self
.
assertEqual
(
multi_tf_beneath
.
transkription_field_found
(),
True
)
self
.
assertTrue
(
multi_tf_beneath
.
second_field
is
None
)
self
.
assertEqual
(
multi_tf_above
.
second_field
.
xmin
,
multi_tf_beneath
.
xmin
)
self
.
assertTrue
(
multi_tf_above
.
ymax
<
multi_tf_beneath
.
ymin
)
def
test_is_shrunk
(
self
):
self
.
assertEqual
(
self
.
test_tr
.
is_shrunk
(),
False
)
self
.
test_tr
.
shrink_svg_to_transkription_field
(
self
.
svg_test_file
)
test_tr
=
TranskriptionField
(
self
.
svg_test_file
)
self
.
assertEqual
(
test_tr
.
is_shrunk
(),
True
)
def
test_getWidth_Height
(
self
):
self
.
assertEqual
(
self
.
test_tr
.
getWidth
(),
835.7
)
self
.
assertEqual
(
self
.
test_tr
.
getHeight
(),
1161.7
)
def
test_init_with_empty_file
(
self
):
"""Tests init function of transformSVG2TranskriptionField.TranskriptionField with empty svg file.
"""
with
self
.
assertRaises
(
Exception
):
TranskriptionField
(
self
.
empty_file
)
def
test_tf_dimensions
(
self
):
"""Tests dimensions of transformSVG2TranskriptionField.TranskriptionField.
"""
self
.
assertEqual
(
self
.
test_tr
.
width
,
493.2
)
self
.
assertEqual
(
self
.
test_tr
.
height
,
623.6999999999999
)
self
.
assertEqual
(
self
.
test_tr
.
xmin
,
190.7
)
self
.
assertEqual
(
self
.
test_tr
.
ymin
,
74.9
)
def
test_to_text_field
(
self
):
text_field
=
self
.
test_tr
.
convert_to_text_field
()
self
.
assertEqual
(
text_field
.
width
,
493.2
)
def
test_tf_shrink_svg_to_transkription_field
(
self
):
"""Tests transformSVG2TranskriptionField.shrink_svg_to_transkription_field.
"""
self
.
assertEqual
(
self
.
test_tr
.
shrink_svg_to_transkription_field
(
self
.
svg_test_file
),
0
)
deleteFile
(
self
.
svg_test_file
)
def
test_tf_shrink_svg_to_transkription_field
(
self
):
"""Tests transformSVG2TranskriptionField.shrink_svg_to_transkription_field with a file that has already been shrunk.
"""
self
.
test_tr
.
shrink_svg_to_transkription_field
(
self
.
svg_test_file
)
test_tr
=
TranskriptionField
(
self
.
svg_test_file
)
self
.
assertEqual
(
test_tr
.
shrink_svg_to_transkription_field
(),
1
)
test_tr
=
TranskriptionField
(
self
.
svg_test_file
)
self
.
assertEqual
(
test_tr
.
transkription_field_found
(),
False
)
deleteFile
(
self
.
svg_test_file
)
def
test_is_page_verso
(
self
):
tf
=
TranskriptionField
(
self
.
verso_svg
)
self
.
assertEqual
(
tf
.
is_page_verso
(),
True
)
tf
=
TranskriptionField
(
self
.
recto_svg
)
self
.
assertEqual
(
tf
.
is_page_verso
(),
False
)
def
test_add_line_number_area_width
(
self
):
tf
=
TranskriptionField
(
self
.
verso_svg
)
tf
.
add_line_number_area_width
(
tf
.
xmin
)
self
.
assertEqual
(
tf
.
line_number_area_width
,
0.0
)
tf
=
TranskriptionField
(
self
.
recto_svg
)
tf
.
add_line_number_area_width
(
tf
.
xmax
)
self
.
assertEqual
(
tf
.
line_number_area_width
,
0.0
)
def
tearDown
(
self
):
deleteFile
(
self
.
empty_file
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Event Timeline
Log In to Comment