Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
9.2.2023: Due to updates GitLab will be unavailable for some minutes between 9:00 and 11:00.
Open sidebar
badw-it
DHParser
Commits
92100f9f
Commit
92100f9f
authored
Aug 02, 2018
by
di68kap
Browse files
- tests for transform.collapse_if()
parent
082a5522
Changes
1
Hide whitespace changes
Inline
Side-by-side
test/test_transform.py
View file @
92100f9f
...
...
@@ -203,15 +203,31 @@ class TestConditionalTransformations:
assert
str
(
cst
)
==
"faciterculasim.bona fide"
class
TestComplexTransformations
:
def
test_collapse_if
(
self
):
def
setup
(
self
):
self
.
Text
=
MockParser
(
'Text'
,
TOKEN_PTYPE
)
def
test_collapse_if_plain
(
self
):
xml
=
"<EINZEILER><DEU_WORT>spectat</DEU_WORT><WS> </WS><DEU_WORT>ad</DEU_WORT>"
+
\
"<WS> </WS><DEU_WORT>gravitatem</DEU_WORT><TEIL_SATZZEICHEN>,</TEIL_SATZZEICHEN>"
+
\
"<WS> </WS><DEU_WORT>momentum</DEU_WORT></EINZEILER>"
tree
=
parse_xml
(
xml
)
print
(
tree
.
as_xml
())
Text
=
MockParser
(
'Text'
,
TOKEN_PTYPE
)
collapse_if
([
tree
],
lambda
l
:
True
,
Text
)
print
(
tree
.
as_xml
())
assert
tree
.
as_xml
(
inline_tags
=
{
'EINZEILER'
})
==
xml
collapse_if
([
tree
],
lambda
l
:
True
,
self
.
Text
)
assert
tree
.
as_xml
(
inline_tags
=
{
'EINZEILER'
})
==
\
"<EINZEILER><Text>spectat ad gravitatem, momentum</Text></EINZEILER>"
def
test_collapse_if_structured
(
self
):
xml
=
"""<Stelle>
<DEU_WORT>p.</DEU_WORT>
<SEITENZAHL>26</SEITENZAHL>
<HOCHGESTELLT>b</HOCHGESTELLT>
<TEIL_SATZZEICHEN>,</TEIL_SATZZEICHEN>
<SEITENZAHL>18</SEITENZAHL>
</Stelle>"""
tree
=
parse_xml
(
xml
)
collapse_if
([
tree
],
lambda
context
:
context
[
-
1
].
tag_name
!=
'HOCHGESTELLT'
,
self
.
Text
)
assert
tree
.
as_xml
(
inline_tags
=
{
'Stelle'
})
==
\
"<Stelle><Text>p.26</Text><HOCHGESTELLT>b</HOCHGESTELLT><Text>,18</Text></Stelle>"
if
__name__
==
"__main__"
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment