From 90d9658b7125c762d8d1e621ed772f8718901892 Mon Sep 17 00:00:00 2001 From: Alex Huszagh Date: Sun, 1 May 2022 10:23:30 -0500 Subject: [PATCH] Added utility to print available tests. --- README.md | 9 +++++++++ test/ui.py | 19 ++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3ecc84f..7f53e04 100644 --- a/README.md +++ b/README.md @@ -480,6 +480,15 @@ options: --scale SCALE scale factor for the UI --pyqt6 use PyQt6 rather than PyQt5. --use-x11 force the use of x11 on compatible systems + --print-tests print all available tests (widget names). +# Get a complete list of available tests. +$ python test/ui.py --print-tests +aero_wizard +all_focus_tree +alpha_colordialog +... +wizard +yes_button ``` To see the complete list of Qt widgets covered by the unittests, see [Test Coverage](Test%20Coverage.md). diff --git a/test/ui.py b/test/ui.py index c295c3d..7c301a0 100644 --- a/test/ui.py +++ b/test/ui.py @@ -107,6 +107,11 @@ parser.add_argument( help='force the use of x11 on compatible systems.', action='store_true' ) +parser.add_argument( + '--print-tests', + help='print all available tests (widget names).', + action='store_true' +) args, unknown = parser.parse_known_args() if args.pyqt6: @@ -2519,13 +2524,21 @@ def test(args, qtargv, test_widget): def main(): 'Application entry point' + def test_names(): + return [i for i in globals().keys() if i.startswith('test_')] + + def widget_names(): + return [i[len('test_'):] for i in test_names()] + + if args.print_tests: + print('\n'.join(sorted(widget_names()))) + return 0 + # Disable garbage collection to avoid runtime errors. gc.disable() os.environ['QT_SCALE_FACTOR'] = str(args.scale) if args.widget == 'all': - all_tests = [i for i in globals().keys() if i.startswith('test_')] - all_widgets = [i[len('test_'):] for i in all_tests] - for widget in all_widgets: + for widget in widget_names(): test(args, sys.argv[:1] + unknown, widget) gc.collect() else: