mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix test iteration
This commit is contained in:
parent
79cfd37e86
commit
32caccc325
@ -60,21 +60,30 @@ def find_tests(which_tests=None):
|
|||||||
tests = unittest.TestSuite(ans)
|
tests = unittest.TestSuite(ans)
|
||||||
return tests
|
return tests
|
||||||
|
|
||||||
|
def itertests(suite):
|
||||||
|
stack = [suite]
|
||||||
|
while stack:
|
||||||
|
suite = stack.pop()
|
||||||
|
for test in suite:
|
||||||
|
if isinstance(test, unittest.TestSuite):
|
||||||
|
stack.append(test)
|
||||||
|
continue
|
||||||
|
if test.__class__.__name__ == 'ModuleImportFailure':
|
||||||
|
raise Exception('Failed to import a test module: %s' % test)
|
||||||
|
yield test
|
||||||
|
|
||||||
def filter_tests(suite, *names):
|
def filter_tests(suite, *names):
|
||||||
names = {x if x.startswith('test_') else 'test_' + x for x in names}
|
names = {x if x.startswith('test_') else 'test_' + x for x in names}
|
||||||
tests = []
|
tests = []
|
||||||
for test in suite._tests:
|
for test in itertests(suite):
|
||||||
if test.__class__.__name__ == 'ModuleImportFailure':
|
if test._testMethodName in names:
|
||||||
raise Exception('Failed to import a test module: %s' % test)
|
tests.append(test)
|
||||||
for s in test:
|
|
||||||
if s._testMethodName in names:
|
|
||||||
tests.append(s)
|
|
||||||
return unittest.TestSuite(tests)
|
return unittest.TestSuite(tests)
|
||||||
|
|
||||||
class Test(Command):
|
class Test(Command):
|
||||||
|
|
||||||
def add_options(self, parser):
|
def add_options(self, parser):
|
||||||
parser.add_option('--test-module', default=[], action='append', type='choice', choices=list(TEST_MODULES),
|
parser.add_option('--test-module', default=[], action='append', type='choice', choices=sorted(map(str, TEST_MODULES)),
|
||||||
help='The test module to run (can be specified more than once for multiple modules). Choices: %s' % ', '.join(sorted(TEST_MODULES)))
|
help='The test module to run (can be specified more than once for multiple modules). Choices: %s' % ', '.join(sorted(TEST_MODULES)))
|
||||||
parser.add_option('--test-verbosity', type=int, default=4, help='Test verbosity (0-4)')
|
parser.add_option('--test-verbosity', type=int, default=4, help='Test verbosity (0-4)')
|
||||||
parser.add_option('--test-name', default=[], action='append',
|
parser.add_option('--test-name', default=[], action='append',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user