In January 2021 we will introduce a 10 GB quota for project repositories. Higher limits for individual projects will be available on request. Please see https://doku.lrz.de/display/PUBLIC/GitLab for more information.

Commit 082a5522 authored by eckhart's avatar eckhart

- fixed som test failures (due to refactoring)

parent 9b3d3fcc
...@@ -194,12 +194,14 @@ def flatten_sxpr(sxpr: str) -> str: ...@@ -194,12 +194,14 @@ def flatten_sxpr(sxpr: str) -> str:
def flatten_xml(xml: str) -> str: def flatten_xml(xml: str) -> str:
"""Returns an XML-tree as a one liner without unnecessary whitespace, """Returns an XML-tree as a one liner without unnecessary whitespace,
i.e. only whitespace within leaf-nodes is preserved. i.e. only whitespace within leaf-nodes is preserved.
A more precise alternative to `flatten_xml` is to use Node.as_xml()
ans passing a set containing the top level tag to parameter `inline_tags`.
""" """
# works only with regex # works only with regex
# return re.sub(r'\s+(?=<\w)', '', re.sub(r'(?<=</\w+>)\s+', '', xml)) # return re.sub(r'\s+(?=<\w)', '', re.sub(r'(?<=</\w+>)\s+', '', xml))
def tag_only(m): def tag_only(m):
return m.groupdict()['closing_tag'] return m.groupdict()['closing_tag']
return re.sub(r'\s+(?=<\w)', '', re.sub(r'(?P<closing_tag></\w+>)\s+', tag_only, xml)) return re.sub(r'\s+(?=<[\w:])', '', re.sub(r'(?P<closing_tag></:?\w+>)\s+', tag_only, xml))
class Node(collections.abc.Sized): class Node(collections.abc.Sized):
......
...@@ -10,8 +10,8 @@ if __name__ == "__main__": ...@@ -10,8 +10,8 @@ if __name__ == "__main__":
# print("Running nosetests:") # print("Running nosetests:")
# os.system("nosetests test") # os.system("nosetests test")
# interpreters = ['python ', 'pypy3 ', 'python37 '] interpreters = ['python ', 'pypy3 ', 'python37 ']
interpreters = [r'C:\Users\di68kap\AppData\Local\Programs\Python\Python37-32\python.exe '] # interpreters = [r'C:\Users\di68kap\AppData\Local\Programs\Python\Python37-32\python.exe ']
for interpreter in interpreters: for interpreter in interpreters:
os.system(interpreter + '--version') os.system(interpreter + '--version')
......
...@@ -56,8 +56,11 @@ class TestParseXML: ...@@ -56,8 +56,11 @@ class TestParseXML:
tree = parse_xml('<a>alpha <b>beta</b> gamma</a>') tree = parse_xml('<a>alpha <b>beta</b> gamma</a>')
assert flatten_sxpr(tree.as_sxpr()) == \ assert flatten_sxpr(tree.as_sxpr()) == \
'(a (:Token "alpha ") (b "beta") (:Token " gamma"))' '(a (:Token "alpha ") (b "beta") (:Token " gamma"))'
tree = parse_xml(' <a> <b>beta</b> </a> ') tree = parse_xml(' <a> <b>beta</b> </a> ')
assert flatten_xml(tree.as_xml()) == '<a><b>beta</b></a>' assert flatten_xml(tree.as_xml()) == '<a><:Token> </:Token><b>beta</b><:Token> </:Token></a>'
assert tree.as_xml(inline_tags={'a'}, omit_tags={':Token'}) == '<a> <b>beta</b> </a>'
tree = parse_xml(' <a>\n <b>beta</b>\n</a> ')
assert tree.as_xml(inline_tags={'a'}) == '<a><b>beta</b></a>'
def test_flatten_xml(self): def test_flatten_xml(self):
tree = parse_xml('<alpha>\n <beta>gamma</beta>\n</alpha>') tree = parse_xml('<alpha>\n <beta>gamma</beta>\n</alpha>')
......
...@@ -30,7 +30,7 @@ from DHParser.syntaxtree import parse_sxpr, flatten_sxpr, TOKEN_PTYPE ...@@ -30,7 +30,7 @@ from DHParser.syntaxtree import parse_sxpr, flatten_sxpr, TOKEN_PTYPE
from DHParser.transform import traverse, remove_expendables, \ from DHParser.transform import traverse, remove_expendables, \
replace_by_single_child, reduce_single_child, flatten replace_by_single_child, reduce_single_child, flatten
from DHParser.dsl import grammar_provider from DHParser.dsl import grammar_provider
from DHParser.testing import get_report, grammar_unit, unit_from_configfile, \ from DHParser.testing import get_report, grammar_unit, unit_from_file, \
reset_unit reset_unit
CFG_FILE_1 = ''' CFG_FILE_1 = '''
...@@ -102,7 +102,7 @@ class TestTestfiles: ...@@ -102,7 +102,7 @@ class TestTestfiles:
os.remove('configfile_test_3.ini') os.remove('configfile_test_3.ini')
def test_unit_from_config_file(self): def test_unit_from_config_file(self):
unit = unit_from_configfile('configfile_test_1.ini') unit = unit_from_file('configfile_test_1.ini')
assert list(unit.keys()) == ['ParserA'] assert list(unit.keys()) == ['ParserA']
assert list(unit['ParserA'].keys()) == ['match', 'fail'], str(list(unit['ParserA'].keys())) assert list(unit['ParserA'].keys()) == ['match', 'fail'], str(list(unit['ParserA'].keys()))
assert list(unit['ParserA']['match'].keys()) == ['M1', 'M2', 'M3', 'M4'] assert list(unit['ParserA']['match'].keys()) == ['M1', 'M2', 'M3', 'M4']
...@@ -111,13 +111,13 @@ class TestTestfiles: ...@@ -111,13 +111,13 @@ class TestTestfiles:
lines = testcase.split('\n') lines = testcase.split('\n')
assert len(lines[2]) - len(lines[2].lstrip()) == 4 assert len(lines[2]) - len(lines[2].lstrip()) == 4
unit = unit_from_configfile('configfile_test_2.ini') unit = unit_from_file('configfile_test_2.ini')
txt = unit['BedeutungsPosition']['match']['M1'] txt = unit['BedeutungsPosition']['match']['M1']
txt.split('\n') txt.split('\n')
for line in txt: for line in txt:
assert line.rstrip()[0:1] != ' ' assert line.rstrip()[0:1] != ' '
unit = unit_from_configfile('configfile_test_3.ini') unit = unit_from_file('configfile_test_3.ini')
ARITHMETIC_EBNF = """ ARITHMETIC_EBNF = """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment