Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F61473988
test_fix_boxes.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, May 6, 22:04
Size
2 KB
Mime Type
text/x-python
Expires
Wed, May 8, 22:04 (2 d)
Engine
blob
Format
Raw Data
Handle
17517050
Attached To
rNIETZSCHEPYTHON nietzsche-python
test_fix_boxes.py
View Options
import
lxml.etree
as
ET
from
os
import
sep
,
path
,
remove
from
os.path
import
isdir
,
isfile
,
dirname
,
basename
import
shutil
import
sys
import
tempfile
import
unittest
import
warnings
import
fix_boxes
sys
.
path
.
append
(
'svgscripts'
)
from
datatypes.faksimile
import
FaksimilePage
from
datatypes.mark_foreign_hands
import
MarkForeignHands
from
datatypes.box
import
Box
from
datatypes.page
import
Page
from
datatypes.path
import
Path
from
datatypes.positional_word_part
import
PositionalWordPart
from
datatypes.text_connection_mark
import
TextConnectionMark
from
datatypes.transkriptionField
import
TranskriptionField
from
datatypes.word
import
Word
from
datatypes.word_position
import
WordPosition
from
process_words_post_merging
import
MERGED_DIR
class
TestFixBoxes
(
unittest
.
TestCase
):
def
setUp
(
self
):
fix_boxes
.
UNITTESTING
=
True
DATADIR
=
path
.
dirname
(
__file__
)
+
sep
+
'test_data'
self
.
fix_boxes
=
DATADIR
+
sep
+
'Mp_XIV_page416.xml'
self
.
fix_boxes_src
=
DATADIR
+
sep
+
'03.svg'
def
test_fix_boxes
(
self
):
page
=
Page
(
self
.
fix_boxes
)
page
.
source
=
self
.
fix_boxes_src
fixed_word_ids
=
sorted
([
int
(
id
)
for
id
in
set
([
node
.
getparent
()
.
get
(
'id'
)
for
node
in
page
.
page_tree
.
xpath
(
'//'
+
Word
.
XML_TAG
+
f
'/debug[@msg="{fix_boxes.DEBUG_MSG}"]'
)])])
self
.
assertEqual
(
len
(
fixed_word_ids
),
2
)
self
.
assertEqual
(
fix_boxes
.
fix_boxes
(
page
),
0
)
self
.
assertEqual
(
page
.
words
[
fixed_word_ids
[
0
]]
.
earlier_version
.
text
,
'Wink.'
)
self
.
assertEqual
(
page
.
words
[
fixed_word_ids
[
1
]]
.
overwrites_word
.
text
,
'ist'
)
def
test_init_word_with_box
(
self
):
page
=
Page
(
self
.
fix_boxes
)
word_node
=
[
node
.
getparent
()
for
node
in
page
.
page_tree
.
xpath
(
'//'
+
Word
.
XML_TAG
+
f
'/debug[@msg="{fix_boxes.DEBUG_MSG}"]'
)][
0
]
word
=
fix_boxes
.
WordWithBoxes
.
create_cls
(
word_node
)
self
.
assertEqual
(
word
.
word_parts
[
1
]
.
text
,
'endung'
)
self
.
assertTrue
(
word
.
word_parts
[
1
]
.
word_box
is
not
None
)
self
.
assertEqual
(
word
.
word_parts
[
2
]
.
text
,
','
)
self
.
assertTrue
(
word
.
word_parts
[
2
]
.
word_box
is
not
None
)
word_node
=
[
node
.
getparent
()
for
node
in
page
.
page_tree
.
xpath
(
'//'
+
Word
.
XML_TAG
+
f
'/debug[@msg="{fix_boxes.DEBUG_MSG}"]'
)][
2
]
word
=
fix_boxes
.
WordWithBoxes
.
create_cls
(
word_node
)
self
.
assertEqual
(
len
(
word
.
word_parts
),
0
)
"""
tree = ET.Element('page')
word.attach_word_to_tree(tree)
print(ET.dump(tree))
"""
def
test_split_and_attach
(
self
):
page
=
Page
(
self
.
fix_boxes
)
word
=
[
word
for
word
in
page
.
words
if
word
.
text
==
'Wendung,'
][
0
]
fix_boxes
.
split_into_parts_and_attach_box
(
word
,
0
,
'ink'
,
True
,
'endung'
)
self
.
assertEqual
(
word
.
word_parts
[
1
]
.
text
,
'endung'
)
self
.
assertTrue
(
word
.
word_parts
[
1
]
.
word_box
is
not
None
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Event Timeline
Log In to Comment