patman: Update test_util to run doc tests
At present this function does not run the doctests. Allow the caller to pass these modules in as strings. Update patman to use this. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
ce3e75dc59
commit
1d0f30e936
@ -58,7 +58,7 @@ def run_tests(processes, args):
|
|||||||
test_util.RunTestSuites(
|
test_util.RunTestSuites(
|
||||||
result, debug=True, verbosity=1, test_preserve_dirs=False,
|
result, debug=True, verbosity=1, test_preserve_dirs=False,
|
||||||
processes=processes, test_name=test_name, toolpath=[],
|
processes=processes, test_name=test_name, toolpath=[],
|
||||||
test_class_list=[test_dtoc.TestDtoc,test_src_scan.TestSrcScan])
|
class_and_module_list=[test_dtoc.TestDtoc,test_src_scan.TestSrcScan])
|
||||||
|
|
||||||
return test_util.ReportResult('binman', test_name, result)
|
return test_util.ReportResult('binman', test_name, result)
|
||||||
|
|
||||||
|
@ -134,23 +134,11 @@ if args.cmd == 'test':
|
|||||||
import doctest
|
import doctest
|
||||||
from patman import func_test
|
from patman import func_test
|
||||||
|
|
||||||
sys.argv = [sys.argv[0]]
|
|
||||||
result = unittest.TestResult()
|
result = unittest.TestResult()
|
||||||
suite = unittest.TestSuite()
|
test_util.RunTestSuites(
|
||||||
loader = unittest.TestLoader()
|
result, False, False, False, None, None, None,
|
||||||
for module in (test_checkpatch.TestPatch, func_test.TestFunctional):
|
[test_checkpatch.TestPatch, func_test.TestFunctional,
|
||||||
if args.testname:
|
'gitutil', 'settings', 'terminal'])
|
||||||
try:
|
|
||||||
suite.addTests(loader.loadTestsFromName(args.testname, module))
|
|
||||||
except AttributeError:
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
suite.addTests(loader.loadTestsFromTestCase(module))
|
|
||||||
suite.run(result)
|
|
||||||
|
|
||||||
for module in ['gitutil', 'settings', 'terminal']:
|
|
||||||
suite = doctest.DocTestSuite(module)
|
|
||||||
suite.run(result)
|
|
||||||
|
|
||||||
sys.exit(test_util.ReportResult('patman', args.testname, result))
|
sys.exit(test_util.ReportResult('patman', args.testname, result))
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
import doctest
|
||||||
import glob
|
import glob
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import os
|
import os
|
||||||
@ -139,7 +140,7 @@ def ReportResult(toolname:str, test_name: str, result: unittest.TestResult):
|
|||||||
|
|
||||||
|
|
||||||
def RunTestSuites(result, debug, verbosity, test_preserve_dirs, processes,
|
def RunTestSuites(result, debug, verbosity, test_preserve_dirs, processes,
|
||||||
test_name, toolpath, test_class_list):
|
test_name, toolpath, class_and_module_list):
|
||||||
"""Run a series of test suites and collect the results
|
"""Run a series of test suites and collect the results
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -154,9 +155,11 @@ def RunTestSuites(result, debug, verbosity, test_preserve_dirs, processes,
|
|||||||
processes: Number of processes to use to run tests (None=same as #CPUs)
|
processes: Number of processes to use to run tests (None=same as #CPUs)
|
||||||
test_name: Name of test to run, or None for all
|
test_name: Name of test to run, or None for all
|
||||||
toolpath: List of paths to use for tools
|
toolpath: List of paths to use for tools
|
||||||
test_class_list: List of test classes to run
|
class_and_module_list: List of test classes (type class) and module
|
||||||
|
names (type str) to run
|
||||||
"""
|
"""
|
||||||
for module in []:
|
for module in class_and_module_list:
|
||||||
|
if isinstance(module, str) and (not test_name or test_name == module):
|
||||||
suite = doctest.DocTestSuite(module)
|
suite = doctest.DocTestSuite(module)
|
||||||
suite.run(result)
|
suite.run(result)
|
||||||
|
|
||||||
@ -171,7 +174,9 @@ def RunTestSuites(result, debug, verbosity, test_preserve_dirs, processes,
|
|||||||
|
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
loader = unittest.TestLoader()
|
loader = unittest.TestLoader()
|
||||||
for module in test_class_list:
|
for module in class_and_module_list:
|
||||||
|
if isinstance(module, str):
|
||||||
|
continue
|
||||||
# Test the test module about our arguments, if it is interested
|
# Test the test module about our arguments, if it is interested
|
||||||
if hasattr(module, 'setup_test_args'):
|
if hasattr(module, 'setup_test_args'):
|
||||||
setup_test_args = getattr(module, 'setup_test_args')
|
setup_test_args = getattr(module, 'setup_test_args')
|
||||||
|
Loading…
Reference in New Issue
Block a user