The expiration time for new job artifacts in CI/CD pipelines is now 30 days (GitLab default). Previously generated artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

Commit 082a5522 authored by eckhart's avatar eckhart
Browse files

- fixed som test failures (due to refactoring)

parent 9b3d3fcc
......@@ -194,12 +194,14 @@ def flatten_sxpr(sxpr: str) -> str:
def flatten_xml(xml: str) -> str:
"""Returns an XML-tree as a one liner without unnecessary whitespace,
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
# 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))
return re.sub(r'\s+(?=<[\w:])', '', re.sub(r'(?P<closing_tag></:?\w+>)\s+', tag_only, xml))
class Node(collections.abc.Sized):
......
......@@ -10,8 +10,8 @@ if __name__ == "__main__":
# print("Running nosetests:")
# os.system("nosetests test")
# interpreters = ['python ', 'pypy3 ', 'python37 ']
interpreters = [r'C:\Users\di68kap\AppData\Local\Programs\Python\Python37-32\python.exe ']
interpreters = ['python ', 'pypy3 ', 'python37 ']
# interpreters = [r'C:\Users\di68kap\AppData\Local\Programs\Python\Python37-32\python.exe ']
for interpreter in interpreters:
os.system(interpreter + '--version')
......
......@@ -56,8 +56,11 @@ class TestParseXML:
tree = parse_xml('<a>alpha <b>beta</b> gamma</a>')
assert flatten_sxpr(tree.as_sxpr()) == \
'(a (:Token "alpha ") (b "beta") (:Token " gamma"))'
tree = parse_xml(' <a> <b>beta</b> </a> ')
assert flatten_xml(tree.as_xml()) == '<a><b>beta</b></a>'
tree = parse_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):
tree = parse_xml('<alpha>\n <beta>gamma</beta>\n</alpha>')
......
......@@ -30,7 +30,7 @@ from DHParser.syntaxtree import parse_sxpr, flatten_sxpr, TOKEN_PTYPE
from DHParser.transform import traverse, remove_expendables, \
replace_by_single_child, reduce_single_child, flatten
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
CFG_FILE_1 = '''
......@@ -102,7 +102,7 @@ class TestTestfiles:
os.remove('configfile_test_3.ini')
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['ParserA'].keys()) == ['match', 'fail'], str(list(unit['ParserA'].keys()))
assert list(unit['ParserA']['match'].keys()) == ['M1', 'M2', 'M3', 'M4']
......@@ -111,13 +111,13 @@ class TestTestfiles:
lines = testcase.split('\n')
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.split('\n')
for line in txt:
assert line.rstrip()[0:1] != ' '
unit = unit_from_configfile('configfile_test_3.ini')
unit = unit_from_file('configfile_test_3.ini')
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