From fc2dedcfc649014702577ab89f550a37766bacf2 Mon Sep 17 00:00:00 2001 From: "Yann E. MORIN" Date: Fri, 7 Jun 2024 19:05:44 +0200 Subject: [PATCH] utils/check-package: add option to run the test-suite Currently, how to run the check-package test-suite is thoroughly under- documented. There is one hint in the commit log for commit fc254881e6df (utils/checkpackagelib: add unit tests), and another in commit 242e9d72e7d2 (utils/docker-run: new script); the former is hard to find, and the latter is about an unrelated script, so harder yet to find... Add a new option to check-package, that will make it run its test-suite. Since pytest is only needed for the test-suite, only import it in that case. pytest will be default create a cache of the tests (not sure what it is about, though), so instruct it not to (esp. since the tree can be read-only). Signed-off-by: Yann E. MORIN Cc: Ricardo Martincoski [Arnout: move the code into checkpackagelib.base] Signed-off-by: Arnout Vandecappelle --- utils/check-package | 6 ++++++ utils/checkpackagelib/base.py | 9 +++++++++ utils/checkpackagelib/readme.txt | 1 + 3 files changed, 16 insertions(+) diff --git a/utils/check-package b/utils/check-package index 3741a2ccdc..872e66c126 100755 --- a/utils/check-package +++ b/utils/check-package @@ -85,6 +85,9 @@ def parse_args(): parser.add_argument("--failed-only", action="store_true", help="print only" " the name of the functions that failed (debug)") + parser.add_argument("--test-suite", action="store_true", help="Run the" + " test-suite") + flags = parser.parse_args() flags.ignore_list = get_ignored_parsers_per_file(flags.intree_only, flags.ignore_filename) @@ -288,6 +291,9 @@ def __main__(): global flags flags = parse_args() + if flags.test_suite: + return checkpackagelib.base.run_test_suite() + if flags.intree_only: # change all paths received to be relative to the base dir base_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) diff --git a/utils/checkpackagelib/base.py b/utils/checkpackagelib/base.py index f666e4110b..0ab6eba9f6 100644 --- a/utils/checkpackagelib/base.py +++ b/utils/checkpackagelib/base.py @@ -1,5 +1,6 @@ # See utils/checkpackagelib/readme.txt before editing this file. import re +import os class _CheckFunction(object): @@ -27,3 +28,11 @@ class _Tool(object): def hint(self): return "" + + +def run_test_suite(): + import pytest + return pytest.main( + # Disable writing/loading a cache with: -p no:cacheprovider + ["-v", "-p", "no:cacheprovider", os.path.dirname(__file__)] + ) diff --git a/utils/checkpackagelib/readme.txt b/utils/checkpackagelib/readme.txt index 3bfe289607..b3e8c67100 100644 --- a/utils/checkpackagelib/readme.txt +++ b/utils/checkpackagelib/readme.txt @@ -23,6 +23,7 @@ How the scripts are structured: - lib_type.py contains check functions specific to files of this type. Some hints when changing this code: +- test your changes: utils/check-package --test-suite - prefer O(n) algorithms, where n is the total number of lines in the files processed. - when there is no other reason for ordering, use alphabetical order (e.g. keep