From 9ca6dc8cb21ec673c398d49d18f0d7dc307637c6 Mon Sep 17 00:00:00 2001 From: odanoburu Date: Wed, 3 Jun 2020 22:19:19 -0300 Subject: [PATCH] * unittest.py: more forgiving parser - accepts whitespace before comment starts - accepts blank lines after last test case, or more than one of them between test cases --- unittest/unittest.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/unittest/unittest.py b/unittest/unittest.py index fa01d6b10..b7e8e4784 100644 --- a/unittest/unittest.py +++ b/unittest/unittest.py @@ -77,23 +77,28 @@ def numbered_np(num, noun, plural=None): def collect_testcases(testlines): """Parse the test file and return a list of test cases""" - tests = [[]] + tests = [] + test = [] for linenr, line in enumerate(testlines, 1): + line = line.strip() if line.startswith('#') or line.startswith('--'): # a comment line: do nothing pass - elif not line.strip(): + elif not line: # an empty line: start a new test - if tests[-1]: - tests.append([]) + if test: + tests.append(test) + test = [] elif ':' in line: lang, sentence = stripstrings(line.split(':', 1)) langfile = importfile(linenr, lang) is_tree = '/abstract/' in langfile - tests[-1].append((is_tree, linenr, lang, langfile, sentence)) + test.append((is_tree, linenr, lang, langfile, sentence)) else: error(linenr, "Ill-formatted line in test file:", line) exit(1) + if test: + tests.append(test) return tests