Commit 76a0deb2 authored by Mathieu Giraud's avatar Mathieu Giraud

src/should.py: refactor, extract .tests_on_lines() from TestSuite.test()

Prepare things for #36.
parent 865f1057
......@@ -793,6 +793,7 @@ class TestSuite():
def test(self, variables=[], verbose=0, colorize=True, only=None):
self.only = only
self.variables_all = self.variables + variables
if verbose > 1:
print_variables(self.variables_all)
......@@ -856,15 +857,27 @@ class TestSuite():
self.test_lines = open(self.source).readlines() if self.source else self.stdout
for test in self.tests:
self.tests_on_lines(self.tests, self.test_lines, verbose, colorize)
self.elapsed_time = time.time() - start_time
return self.status
def tests_on_lines(self, tests, test_lines, verbose, colorize):
'''
Test all tests in 'tests' on 'test_lines',
taking into accound self modifiers
and gathering statuses in self.status
'''
for test in tests:
# Filter
if only:
if not only(test):
if self.only:
if not self.only(test):
test.status = SKIP
continue
# Test the test
test.test(self.test_lines, variables=self.variables_all, verbose=verbose-1)
test.test(test_lines, variables=self.variables_all, verbose=verbose-1)
self.stats.up(test.status)
self.status = combine_status(self.status, test.status)
......@@ -877,18 +890,16 @@ class TestSuite():
if self.status is False or verbose > 1:
print(LINE)
if len(self.test_lines) <= MAX_DUMP_LINES:
print(''.join(self.test_lines), end='')
if len(test_lines) <= MAX_DUMP_LINES:
print(''.join(test_lines), end='')
else:
print(''.join(self.test_lines[:MAX_HALF_DUMP_LINES]), end='')
print(color(ANSI.MAGENTA, '... %d other lines ...' % (len(self.test_lines) - 2*MAX_HALF_DUMP_LINES), colorize))
print(''.join(self.test_lines[-MAX_HALF_DUMP_LINES:]), end='')
print(''.join(test_lines[:MAX_HALF_DUMP_LINES]), end='')
print(color(ANSI.MAGENTA, '... %d other lines ...' % (len(test_lines) - 2*MAX_HALF_DUMP_LINES), colorize))
print(''.join(test_lines[-MAX_HALF_DUMP_LINES:]), end='')
print(LINE)
self.elapsed_time = time.time() - start_time
return self.status
def str_status(self, colorize=True):
return self.stats.str_status(self.status, colorize)
......
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