regrtest: fix --fromfile feature
* Update code for the name regrtest output format. * Enhance also test_regrtest test on --fromfile
This commit is contained in:
parent
923590e397
commit
5de16e80c1
|
@ -168,13 +168,21 @@ class Regrtest:
|
||||||
|
|
||||||
if self.ns.fromfile:
|
if self.ns.fromfile:
|
||||||
self.tests = []
|
self.tests = []
|
||||||
|
# regex to match 'test_builtin' in line:
|
||||||
|
# '0:00:00 [ 4/400] test_builtin -- test_dict took 1 sec'
|
||||||
|
regex = (r'^(?:[0-9]+:[0-9]+:[0-9]+ *)?'
|
||||||
|
r'(?:\[[0-9/ ]+\] *)?'
|
||||||
|
r'(test_[a-zA-Z0-9_]+)')
|
||||||
|
regex = re.compile(regex)
|
||||||
with open(os.path.join(support.SAVEDCWD, self.ns.fromfile)) as fp:
|
with open(os.path.join(support.SAVEDCWD, self.ns.fromfile)) as fp:
|
||||||
count_pat = re.compile(r'\[\s*\d+/\s*\d+\]')
|
|
||||||
for line in fp:
|
for line in fp:
|
||||||
line = count_pat.sub('', line)
|
line = line.strip()
|
||||||
guts = line.split() # assuming no test has whitespace in its name
|
if line.startswith('#'):
|
||||||
if guts and not guts[0].startswith('#'):
|
continue
|
||||||
self.tests.extend(guts)
|
match = regex.match(line)
|
||||||
|
if match is None:
|
||||||
|
continue
|
||||||
|
self.tests.append(match.group(1))
|
||||||
|
|
||||||
removepy(self.tests)
|
removepy(self.tests)
|
||||||
|
|
||||||
|
@ -194,7 +202,10 @@ class Regrtest:
|
||||||
else:
|
else:
|
||||||
alltests = findtests(self.ns.testdir, stdtests, nottests)
|
alltests = findtests(self.ns.testdir, stdtests, nottests)
|
||||||
|
|
||||||
self.selected = self.tests or self.ns.args or alltests
|
if not self.ns.fromfile:
|
||||||
|
self.selected = self.tests or self.ns.args or alltests
|
||||||
|
else:
|
||||||
|
self.selected = self.tests
|
||||||
if self.ns.single:
|
if self.ns.single:
|
||||||
self.selected = self.selected[:1]
|
self.selected = self.selected[:1]
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -628,6 +628,22 @@ class ArgsTestCase(BaseTestCase):
|
||||||
# [2/2] test_2
|
# [2/2] test_2
|
||||||
filename = support.TESTFN
|
filename = support.TESTFN
|
||||||
self.addCleanup(support.unlink, filename)
|
self.addCleanup(support.unlink, filename)
|
||||||
|
|
||||||
|
# test format '0:00:00 [2/7] test_opcodes -- test_grammar took 0 sec'
|
||||||
|
with open(filename, "w") as fp:
|
||||||
|
previous = None
|
||||||
|
for index, name in enumerate(tests, 1):
|
||||||
|
line = ("00:00:%02i [%s/%s] %s"
|
||||||
|
% (index, index, len(tests), name))
|
||||||
|
if previous:
|
||||||
|
line += " -- %s took 0 sec" % previous
|
||||||
|
print(line, file=fp)
|
||||||
|
previous = name
|
||||||
|
|
||||||
|
output = self.run_tests('--fromfile', filename)
|
||||||
|
self.check_executed_tests(output, tests)
|
||||||
|
|
||||||
|
# test format '[2/7] test_opcodes'
|
||||||
with open(filename, "w") as fp:
|
with open(filename, "w") as fp:
|
||||||
for index, name in enumerate(tests, 1):
|
for index, name in enumerate(tests, 1):
|
||||||
print("[%s/%s] %s" % (index, len(tests), name), file=fp)
|
print("[%s/%s] %s" % (index, len(tests), name), file=fp)
|
||||||
|
@ -635,6 +651,14 @@ class ArgsTestCase(BaseTestCase):
|
||||||
output = self.run_tests('--fromfile', filename)
|
output = self.run_tests('--fromfile', filename)
|
||||||
self.check_executed_tests(output, tests)
|
self.check_executed_tests(output, tests)
|
||||||
|
|
||||||
|
# test format 'test_opcodes'
|
||||||
|
with open(filename, "w") as fp:
|
||||||
|
for name in tests:
|
||||||
|
print(name, file=fp)
|
||||||
|
|
||||||
|
output = self.run_tests('--fromfile', filename)
|
||||||
|
self.check_executed_tests(output, tests)
|
||||||
|
|
||||||
def test_interrupted(self):
|
def test_interrupted(self):
|
||||||
code = TEST_INTERRUPTED
|
code = TEST_INTERRUPTED
|
||||||
test = self.create_test("sigint", code=code)
|
test = self.create_test("sigint", code=code)
|
||||||
|
|
Loading…
Reference in New Issue