forked from GitHub/gf-rgl
Merge pull request #340 from odanoburu/unittest-forgiving-parser
(unittest.py) more forgiving parser
This commit is contained in:
@@ -77,23 +77,28 @@ def numbered_np(num, noun, plural=None):
|
|||||||
|
|
||||||
def collect_testcases(testlines):
|
def collect_testcases(testlines):
|
||||||
"""Parse the test file and return a list of test cases"""
|
"""Parse the test file and return a list of test cases"""
|
||||||
tests = [[]]
|
tests = []
|
||||||
|
test = []
|
||||||
for linenr, line in enumerate(testlines, 1):
|
for linenr, line in enumerate(testlines, 1):
|
||||||
|
line = line.strip()
|
||||||
if line.startswith('#') or line.startswith('--'):
|
if line.startswith('#') or line.startswith('--'):
|
||||||
# a comment line: do nothing
|
# a comment line: do nothing
|
||||||
pass
|
pass
|
||||||
elif not line.strip():
|
elif not line:
|
||||||
# an empty line: start a new test
|
# an empty line: start a new test
|
||||||
if tests[-1]:
|
if test:
|
||||||
tests.append([])
|
tests.append(test)
|
||||||
|
test = []
|
||||||
elif ':' in line:
|
elif ':' in line:
|
||||||
lang, sentence = stripstrings(line.split(':', 1))
|
lang, sentence = stripstrings(line.split(':', 1))
|
||||||
langfile = importfile(linenr, lang)
|
langfile = importfile(linenr, lang)
|
||||||
is_tree = '/abstract/' in langfile
|
is_tree = '/abstract/' in langfile
|
||||||
tests[-1].append((is_tree, linenr, lang, langfile, sentence))
|
test.append((is_tree, linenr, lang, langfile, sentence))
|
||||||
else:
|
else:
|
||||||
error(linenr, "Ill-formatted line in test file:", line)
|
error(linenr, "Ill-formatted line in test file:", line)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
if test:
|
||||||
|
tests.append(test)
|
||||||
return tests
|
return tests
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user