From 68b931d3d8b191c9b2f931edf5510963a4ea2f8c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 20 May 2023 13:10:01 +0530 Subject: [PATCH] Allow running test_rs with libasan preloaded --- setup/test.py | 52 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/setup/test.py b/setup/test.py index 7a142f94d5..48a9fc1147 100644 --- a/setup/test.py +++ b/setup/test.py @@ -10,25 +10,7 @@ from setup import Command, ismacos, is_ci TEST_MODULES = frozenset('srv db polish opf css docx cfi matcher icu smartypants build misc dbcli ebooks'.split()) -class Test(Command): - - description = 'Run the calibre test suite' - - def add_options(self, parser): - parser.add_option('--test-verbosity', type=int, default=4, help='Test verbosity (0-4)') - parser.add_option('--test-module', '--test-group', 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))) - parser.add_option('--test-name', '-n', default=[], action='append', - help='The name of an individual test to run. Can be specified more than once for multiple tests. The name of the' - ' test is the name of the test function without the leading test_. For example, the function test_something()' - ' can be run by specifying the name "something".') - parser.add_option('--exclude-test-module', default=[], action='append', type='choice', choices=sorted(map(str, TEST_MODULES)), - help='A test module to be excluded from the test run (can be specified more than once for multiple modules).' - ' Choices: %s' % ', '.join(sorted(TEST_MODULES))) - parser.add_option('--exclude-test-name', default=[], action='append', - help='The name of an individual test to be excluded from the test run. Can be specified more than once for multiple tests.') - parser.add_option('--under-sanitize', default=False, action='store_true', - help='Run the test suite with the sanitizer preloaded') +class BaseTest(Command): def run(self, opts): if opts.under_sanitize and 'CALIBRE_EXECED_UNDER_SANITIZE' not in os.environ: @@ -41,6 +23,32 @@ class Test(Command): sys.stdout.flush() os.execl('setup.py', *sys.argv) + def add_options(self, parser): + parser.add_option('--under-sanitize', default=False, action='store_true', + help='Run the test suite with the sanitizer preloaded') + + +class Test(BaseTest): + + description = 'Run the calibre test suite' + + def add_options(self, parser): + super().add_options(parser) + parser.add_option('--test-verbosity', type=int, default=4, help='Test verbosity (0-4)') + parser.add_option('--test-module', '--test-group', 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))) + parser.add_option('--test-name', '-n', default=[], action='append', + help='The name of an individual test to run. Can be specified more than once for multiple tests. The name of the' + ' test is the name of the test function without the leading test_. For example, the function test_something()' + ' can be run by specifying the name "something".') + parser.add_option('--exclude-test-module', default=[], action='append', type='choice', choices=sorted(map(str, TEST_MODULES)), + help='A test module to be excluded from the test run (can be specified more than once for multiple modules).' + ' Choices: %s' % ', '.join(sorted(TEST_MODULES))) + parser.add_option('--exclude-test-name', default=[], action='append', + help='The name of an individual test to be excluded from the test run. Can be specified more than once for multiple tests.') + + def run(self, opts): + super().run(opts) # cgi is used by feedparser and possibly other dependencies import warnings warnings.filterwarnings('ignore', message="'cgi' is deprecated and slated for removal in Python 3.13") @@ -62,10 +70,14 @@ class Test(Command): run_cli(tests, verbosity=opts.test_verbosity, buffer=not opts.test_name) -class TestRS(Command): +class TestRS(BaseTest): description = 'Run tests for RapydScript code' + def add_options(self, parser): + super().add_options(parser) + def run(self, opts): + super().run(opts) from calibre.utils.rapydscript import run_rapydscript_tests run_rapydscript_tests()