Make a dedicated entry point in calibre-debug for running tests

Fixes #1677 (One difference: using the new run_test() I see all the debug output …)
This commit is contained in:
Kovid Goyal 2022-07-04 20:37:20 +05:30
parent 8002c9c8bb
commit be43cc25db
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 8 additions and 1 deletions

View File

@ -102,6 +102,8 @@ Everything after the -- is passed to the script.
'Run a plugin that provides a command line interface. For example:\n' 'Run a plugin that provides a command line interface. For example:\n'
'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=_(
'Run the named test(s)'))
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'))
@ -313,6 +315,11 @@ def main(args=sys.argv):
prints(_('No plugin named %s found')%opts.run_plugin) prints(_('No plugin named %s found')%opts.run_plugin)
raise SystemExit(1) raise SystemExit(1)
plugin.cli_main([plugin.name] + args[1:]) plugin.cli_main([plugin.name] + args[1:])
elif opts.run_test:
from calibre.utils.run_tests import run_test
from calibre.constants import debug
debug(False)
run_test(opts.run_test)
elif opts.diff: elif opts.diff:
from calibre.gui2.tweak_book.diff.main import main from calibre.gui2.tweak_book.diff.main import main
main(['calibre-diff'] + args[1:]) main(['calibre-diff'] + args[1:])

View File

@ -301,7 +301,7 @@ 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 -c "from calibre.utils.run_tests import *; import sys; run_test(sys.argv[-1])" some_test_name # calibre-debug -t test_name
tests = find_tests() tests = find_tests()
tests = filter_tests_by_name(tests, test_name) tests = filter_tests_by_name(tests, test_name)
if not tests._tests: if not tests._tests: