Make calibre-debug --run-test a bit smarter

This commit is contained in:
Kovid Goyal 2022-07-04 21:24:35 +05:30
parent 4654742f87
commit cc2d5c23f5
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 15 additions and 3 deletions

View File

@ -103,7 +103,10 @@ Everything after the -- is passed to the script.
'calibre-debug -r "Plugin name" -- file1 --option1\n' 'calibre-debug -r "Plugin name" -- file1 --option1\n'
'Everything after the -- will be passed to the plugin as arguments.')) 'Everything after the -- will be passed to the plugin as arguments.'))
parser.add_option('-t', '--run-test', help=_( parser.add_option('-t', '--run-test', help=_(
'Run the named test(s)')) 'Run the named test(s). Use the special value "all" to run all tests.'
' If the test name starts with a period it is assumed to be a module name.'
' If the test name starts with @ it is assumed to be a category name.'
))
parser.add_option('--diff', action='store_true', default=False, help=_( parser.add_option('--diff', action='store_true', default=False, help=_(
'Run the calibre diff tool. For example:\n' 'Run the calibre diff tool. For example:\n'
'calibre-debug --diff file1 file2')) 'calibre-debug --diff file1 file2'))

View File

@ -302,7 +302,16 @@ def find_tests(which_tests=None, exclude_tests=None):
def run_test(test_name, verbosity=4, buffer=False): def run_test(test_name, verbosity=4, buffer=False):
# calibre-debug -t test_name # calibre-debug -t test_name
tests = find_tests() which_tests = None
if test_name.startswith('@'):
which_tests = test_name[1:],
tests = find_tests(which_tests)
if test_name != 'all':
if test_name.startswith('.'):
tests = filter_tests_by_module(tests, test_name[1:])
elif test_name.startswith('@'):
pass
else:
tests = filter_tests_by_name(tests, test_name) tests = filter_tests_by_name(tests, test_name)
if not tests._tests: if not tests._tests:
raise SystemExit(f'No test named {test_name} found') raise SystemExit(f'No test named {test_name} found')