Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F74440347
test_mark_foreign_hands.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
Sat, Jul 27, 20:34
Size
4 KB
Mime Type
text/x-python
Expires
Mon, Jul 29, 20:34 (2 d)
Engine
blob
Format
Raw Data
Handle
19362585
Attached To
rNIETZSCHEPYTHON nietzsche-python
test_mark_foreign_hands.py
View Options
import
unittest
from
os
import
sep
,
path
from
os.path
import
dirname
,
isdir
import
lxml.etree
as
ET
import
sys
sys
.
path
.
append
(
'svgscripts'
)
from
datatypes.matrix
import
Matrix
from
datatypes.transkriptionField
import
TranskriptionField
from
datatypes.transkription_position
import
TranskriptionPosition
from
datatypes.mark_foreign_hands
import
MarkForeignHands
from
datatypes.page
import
Page
from
datatypes.word
import
Word
class
TestMarkForeignHands
(
unittest
.
TestCase
):
def
setUp
(
self
):
DATADIR
=
dirname
(
__file__
)
+
sep
+
'test_data'
self
.
xml_file
=
DATADIR
+
sep
+
'N_VII_1_page008.xml'
self
.
test_content_svg
=
DATADIR
+
sep
+
'N_VII_1_xp5_4_page5.svg'
self
.
test_content_xml
=
DATADIR
+
sep
+
'N_VII_1_page005.xml'
self
.
test_contentB_svg
=
DATADIR
+
sep
+
'N_VII_1_xp5_4_page6.svg'
self
.
test_contentB_xml
=
DATADIR
+
sep
+
'N_VII_1_page006.xml'
mylist
=
{
'text'
:
'*'
,
'id'
:
'0'
,
'line-number'
:
'2'
}
self
.
node
=
ET
.
Element
(
MarkForeignHands
.
XML_TAG
,
attrib
=
mylist
)
word_position
=
TranskriptionPosition
(
x
=
0
,
y
=
1
,
height
=
10
,
width
=
10
,
matrix
=
Matrix
(
'matrix(0.94 0.342 -0.342 0.94 0 0)'
))
self
.
transkription_positions
=
[
word_position
]
word_position
.
attach_object_to_tree
(
self
.
node
)
def
test_create_cls
(
self
):
mark_foreign_hands
=
MarkForeignHands
.
create_cls
(
self
.
node
)
self
.
assertEqual
(
mark_foreign_hands
.
id
,
0
)
self
.
assertEqual
(
mark_foreign_hands
.
transkription_positions
[
0
]
.
bottom
,
11
)
self
.
assertEqual
(
mark_foreign_hands
.
transkription_positions
[
0
]
.
height
,
10
)
self
.
assertEqual
(
mark_foreign_hands
.
transkription_positions
[
0
]
.
top
,
1
)
self
.
assertEqual
(
mark_foreign_hands
.
transkription_positions
[
0
]
.
left
,
0
)
self
.
assertEqual
(
mark_foreign_hands
.
transkription_positions
[
0
]
.
width
,
10
)
self
.
assertEqual
(
mark_foreign_hands
.
text
,
'*'
)
self
.
assertEqual
(
mark_foreign_hands
.
line_number
,
2
)
self
.
assertEqual
(
mark_foreign_hands
.
transkription_positions
[
0
]
.
transform
.
isRotationMatrix
(),
True
)
def
test_attach_word_to_tree
(
self
):
empty_tree
=
ET
.
ElementTree
(
ET
.
Element
(
'page'
))
mark_foreign_hands
=
MarkForeignHands
.
create_cls
(
self
.
node
)
mark_foreign_hands
.
foreign_hands_text
=
'test'
mark_foreign_hands
.
pen
=
'Rotstift'
mark_foreign_hands
.
overwrites_mark
=
MarkForeignHands
.
create_cls
(
self
.
node
)
mark_foreign_hands
.
overwrites_mark
.
foreign_hands_text
=
'test 2'
mark_foreign_hands
.
overwrites_mark
.
pen
=
'Bleistift'
mark_foreign_hands
.
attach_word_to_tree
(
empty_tree
)
#print(ET.dump(empty_tree.getroot()))
for
node
in
empty_tree
.
xpath
(
'./'
+
MarkForeignHands
.
XML_TAG
):
mark
=
MarkForeignHands
.
create_cls
(
node
)
self
.
assertEqual
(
mark
.
pen
,
'Rotstift'
)
self
.
assertEqual
(
mark
.
foreign_hands_text
.
content
,
'test'
)
self
.
assertTrue
(
mark
.
overwrites_mark
is
not
None
)
self
.
assertEqual
(
mark
.
id
,
0
)
self
.
assertEqual
(
mark
.
transkription_positions
[
0
]
.
bottom
,
11
)
self
.
assertEqual
(
mark
.
transkription_positions
[
0
]
.
height
,
10
)
self
.
assertEqual
(
mark
.
transkription_positions
[
0
]
.
top
,
1
)
self
.
assertEqual
(
mark
.
transkription_positions
[
0
]
.
left
,
0
)
self
.
assertEqual
(
mark
.
transkription_positions
[
0
]
.
width
,
10
)
self
.
assertEqual
(
mark
.
text
,
'*'
)
self
.
assertEqual
(
mark
.
line_number
,
2
)
self
.
assertEqual
(
mark
.
transkription_positions
[
0
]
.
transform
.
isRotationMatrix
(),
True
)
#print(empty_tree.xpath('//mark-foreign-hands/content/text()'))
#print(empty_tree.xpath('//mark-foreign-hands/content/@pen'))
def
test_get_semanticAndDataDict
(
self
):
dictionary
=
MarkForeignHands
.
get_semantic_dictionary
()
#print(dictionary)
def
test_find_content
(
self
):
page
=
Page
(
self
.
test_contentB_xml
)
transkription_field
=
TranskriptionField
(
page
.
source
)
svg_tree
=
ET
.
parse
(
page
.
source
)
page
.
update_line_number_area
(
transkription_field
,
svg_tree
=
svg_tree
)
mark_foreign_hands_word
=
[
word
for
word
in
page
.
words
if
word
.
text
==
MarkForeignHands
.
CLASS_MARK
][
0
]
mark_foreign_hands
=
MarkForeignHands
.
create_cls_from_word
(
mark_foreign_hands_word
)
MarkForeignHands
.
find_content
([
mark_foreign_hands
]
,
transkription_field
,
svg_tree
,
style_dict
=
page
.
style_dict
)
self
.
assertEqual
(
mark_foreign_hands
.
foreign_hands_text
,
'W III, 104. (MXXIX, 3)'
)
self
.
assertEqual
(
mark_foreign_hands
.
pen
,
'Bleistift'
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Event Timeline
Log In to Comment