Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F62478043
test_fix_missing_glyphs.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 13, 11:56
Size
3 KB
Mime Type
text/x-python
Expires
Wed, May 15, 11:56 (2 d)
Engine
blob
Format
Raw Data
Handle
17651608
Attached To
rNIETZSCHEPYTHON nietzsche-python
test_fix_missing_glyphs.py
View Options
import
unittest
from
os
import
sep
,
path
,
remove
from
os.path
import
isdir
,
isfile
,
dirname
import
shutil
import
sys
import
lxml.etree
as
ET
import
warnings
import
sys
sys
.
path
.
append
(
'svgscripts'
)
import
fix_missing_glyphs
from
datatypes.page
import
Page
from
datatypes.positional_word_part
import
PositionalWordPart
from
datatypes.transkriptionField
import
TranskriptionField
class
TestMissingGlyphs
(
unittest
.
TestCase
):
def
setUp
(
self
):
fix_missing_glyphs
.
UNITTESTING
=
True
DATADIR
=
path
.
dirname
(
__file__
)
+
sep
+
'test_data'
self
.
manuscript
=
DATADIR
+
sep
+
'pdfsvg'
+
sep
+
'W_II_1.xml'
self
.
manuscript_copy
=
self
.
manuscript
.
replace
(
'.'
,
'_copy.'
)
self
.
svgposfile
=
DATADIR
+
sep
+
'pdfsvg'
+
sep
+
'W_II_1_page015.xml'
self
.
svgposfile_copy
=
DATADIR
+
sep
+
'pdfsvg'
+
sep
+
'W_II_1_page015_copy.xml'
def
test_main
(
self
):
argv_fileNotFound
=
[
'asdf'
]
with
self
.
assertRaises
(
FileNotFoundError
):
fix_missing_glyphs
.
main
(
argv_fileNotFound
)
#shutil.copy(self.manuscript, self.manuscript_copy)
#shutil.copy(self.svgposfile, self.svgposfile_copy)
#self.assertEqual(fix_missing_glyphs.main([self.manuscript_copy]), 0)
#shutil.copy(self.svgposfile_copy, self.svgposfile)
#remove(self.manuscript_copy)
shutil
.
copy
(
self
.
svgposfile
,
self
.
svgposfile_copy
)
self
.
assertEqual
(
fix_missing_glyphs
.
main
([
self
.
svgposfile_copy
]),
0
)
remove
(
self
.
svgposfile_copy
)
def
test_update_word
(
self
):
page
=
Page
(
xml_source_file
=
self
.
svgposfile
)
pwps
=
page
.
words
[
5
]
.
transkription_positions
[
0
]
.
positional_word_parts
new_left
=
10
old_left
=
pwps
[
0
]
.
left
new_width
=
pwps
[
0
]
.
width
+
old_left
-
new_left
pwps
[
0
]
.
left
=
new_left
pwps
[
0
]
.
width
=
new_width
pwps
[
0
]
.
text
=
'X'
+
pwps
[
0
]
.
text
original_text
=
page
.
words
[
5
]
.
text
pwp_node
=
page
.
page_tree
.
xpath
(
'//word[@id="5"]/transkription-position[@id="0"]/'
+
PositionalWordPart
.
XML_TAG
+
'[@id="0"]'
)[
0
]
#print(ET.dump(pwp_node))
fix_missing_glyphs
.
update_word
(
page
,
pwp_node
,
[
pwps
[
0
]
])
pwp_node
=
page
.
page_tree
.
xpath
(
'//word[@id="5"]/transkription-position[@id="0"]/'
+
PositionalWordPart
.
XML_TAG
+
'[@id="0"]'
)[
0
]
#print(ET.dump(pwp_node.getparent().getparent()))
self
.
assertEqual
(
float
(
pwp_node
.
get
(
'width'
)),
new_width
)
self
.
assertEqual
(
pwp_node
.
getparent
()
.
getparent
()
.
get
(
'text'
),
'X'
+
original_text
)
def
test_find_missing_glyph_for_pwp
(
self
):
page
=
Page
(
xml_source_file
=
self
.
svgposfile
)
transkription_field
=
TranskriptionField
(
page
.
svg_file
)
svg_path_tree
=
ET
.
parse
(
page
.
svg_file
)
namespaces
=
{
k
if
k
is
not
None
else
'ns'
:
v
for
k
,
v
in
svg_path_tree
.
getroot
()
.
nsmap
.
items
()
}
positional_word_part_node
=
page
.
page_tree
.
xpath
(
'//'
+
PositionalWordPart
.
XML_TAG
+
'[not(@symbol-id)]'
)[
0
]
\
if
len
(
page
.
page_tree
.
xpath
(
'//'
+
PositionalWordPart
.
XML_TAG
+
'[not(@symbol-id)]'
))
>
0
else
None
pwps
=
fix_missing_glyphs
.
find_missing_glyph_for_pwp
(
positional_word_part_node
,
svg_path_tree
,
namespaces
,
xmin
=
transkription_field
.
xmin
,
ymin
=
transkription_field
.
ymin
)
self
.
assertEqual
(
len
(
pwps
),
2
)
def
test_get_filelist_and_manuscript_file
(
self
):
file_list
,
manuscript_file
=
fix_missing_glyphs
.
get_filelist_and_manuscript_file
(
self
.
manuscript
,
self
.
svgposfile
)
self
.
assertEqual
(
len
(
file_list
),
1
)
self
.
assertEqual
(
file_list
[
0
],
self
.
svgposfile
)
self
.
assertEqual
(
manuscript_file
,
self
.
manuscript
)
file_list
,
manuscript_file
=
fix_missing_glyphs
.
get_filelist_and_manuscript_file
(
self
.
svgposfile
,
self
.
manuscript
)
self
.
assertEqual
(
len
(
file_list
),
1
)
self
.
assertEqual
(
file_list
[
0
],
self
.
svgposfile
)
self
.
assertEqual
(
manuscript_file
,
self
.
manuscript
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Event Timeline
Log In to Comment