Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
badw-it
DHParser
Commits
9c16b2a8
Commit
9c16b2a8
authored
Jul 02, 2018
by
di68kap
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- syntaxtree.flatten_xml: now compatible with 're', not just 'regex'
- test/run.py works now without nose being installed
parent
37f225a0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
7 deletions
+28
-7
DHParser/syntaxtree.py
DHParser/syntaxtree.py
+6
-2
test/run.py
test/run.py
+16
-4
test/test_ebnf.py
test/test_ebnf.py
+1
-1
test/test_syntaxtree.py
test/test_syntaxtree.py
+5
-0
No files found.
DHParser/syntaxtree.py
View file @
9c16b2a8
...
...
@@ -191,10 +191,14 @@ def flatten_sxpr(sxpr: str) -> str:
def
flatten_xml
(
xml
:
str
)
->
str
:
"""Returns an XML-tree as a one lin
t
er without unnecessary whitespace,
"""Returns an XML-tree as a one liner without unnecessary whitespace,
i.e. only whitespace within leaf-nodes is preserved.
"""
return
re
.
sub
(
r
'\s+(?=<\w)'
,
''
,
re
.
sub
(
r
'(?<=</\w+>)\s+'
,
''
,
xml
))
# works only with regex
# return re.sub(r'\s+(?=<\w)', '', re.sub(r'(?<=</\w+>)\s+', '', xml))
def
tag_only
(
m
):
return
m
.
groupdict
()[
'closing_tag'
]
return
re
.
sub
(
r
'\s+(?=<\w)'
,
''
,
re
.
sub
(
r
'(?P<closing_tag></\w+>)\s+'
,
tag_only
,
xml
))
class
Node
(
collections
.
abc
.
Sized
):
...
...
test/run.py
View file @
9c16b2a8
...
...
@@ -3,7 +3,19 @@
if
__name__
==
"__main__"
:
import
os
if
os
.
getcwd
().
endswith
(
'test'
):
os
.
chdir
(
'..'
)
print
(
"Running nosetests:"
)
os
.
system
(
"nosetests test"
)
# if os.getcwd().endswith('test'):
# os.chdir('..')
# print("Running nosetests:")
# os.system("nosetests test")
interpreter
=
'python '
# interpreter = r'C:\Users\di68kap\AppData\Local\Programs\Python\Python37-32\python.exe '
os
.
system
(
interpreter
+
'--version'
)
assert
os
.
getcwd
().
endswith
(
'test'
)
files
=
os
.
listdir
()
for
filename
in
files
:
if
filename
.
startswith
(
'test_'
):
print
(
'
\n
TEST '
+
filename
)
os
.
system
(
interpreter
+
filename
)
test/test_ebnf.py
View file @
9c16b2a8
...
...
@@ -451,4 +451,4 @@ class TestAllSome:
if
__name__
==
"__main__"
:
from
DHParser.testing
import
runner
runner
(
"
TestTermBug
"
,
globals
())
runner
(
""
,
globals
())
test/test_syntaxtree.py
View file @
9c16b2a8
...
...
@@ -59,6 +59,11 @@ class TestParseXML:
tree
=
parse_xml
(
' <a> <b>beta</b> </a> '
)
assert
flatten_xml
(
tree
.
as_xml
())
==
'<a><b>beta</b></a>'
def
test_flatten_xml
(
self
):
tree
=
parse_xml
(
'<alpha>
\n
<beta>gamma</beta>
\n
</alpha>'
)
flat_xml
=
flatten_xml
(
tree
.
as_xml
())
assert
flat_xml
==
'<alpha><beta>gamma</beta></alpha>'
,
flat_xml
class
TestNode
:
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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