From 41d42a07bf2ad23762dac02b615865efa86adfec Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 1 Oct 2021 20:57:26 -0400 Subject: [PATCH] klippy: Add a build import test tool Add a test case to verify that every optional module successfully loads on both Python2 and Python3. This is intended to catch syntax and module imports that are not compatible between Python versions. Signed-off-by: Kevin O'Connor --- klippy/klippy.py | 19 +++++++++++++++++++ scripts/ci-build.sh | 8 ++++++++ 2 files changed, 27 insertions(+) diff --git a/klippy/klippy.py b/klippy/klippy.py index df8e110c..050a36f2 100644 --- a/klippy/klippy.py +++ b/klippy/klippy.py @@ -256,6 +256,21 @@ class Printer: # Startup ###################################################################### +def import_test(): + # Import all optional modules (used as a build test) + dname = os.path.dirname(__file__) + for mname in ['extras', 'kinematics']: + for fname in os.listdir(os.path.join(dname, mname)): + if fname.endswith('.py') and fname != '__init__.py': + module_name = fname[:-3] + else: + iname = os.path.join(dname, mname, fname, '__init__.py') + if not os.path.exists(iname): + continue + module_name = fname + importlib.import_module(mname + '.' + module_name) + sys.exit(0) + def arg_dictionary(option, opt_str, value, parser): key, fname = "dictionary", value if '=' in value: @@ -284,7 +299,11 @@ def main(): opts.add_option("-d", "--dictionary", dest="dictionary", type="string", action="callback", callback=arg_dictionary, help="file to read for mcu protocol dictionary") + opts.add_option("--import-test", action="store_true", + help="perform an import module test") options, args = opts.parse_args() + if options.import_test: + import_test() if len(args) != 1: opts.error("Incorrect number of arguments") start_args = {'config_file': args[0], 'apiserver': options.apiserver, diff --git a/scripts/ci-build.sh b/scripts/ci-build.sh index 286e4490..9d423964 100755 --- a/scripts/ci-build.sh +++ b/scripts/ci-build.sh @@ -64,6 +64,14 @@ done # Verify klippy host software ###################################################################### +start_test klippy "Test klippy import (Python3)" +$PYTHON klippy/klippy.py --import-test +finish_test klippy "Test klippy import (Python3)" + +start_test klippy "Test klippy import (Python2)" +$PYTHON2 klippy/klippy.py --import-test +finish_test klippy "Test klippy import (Python2)" + start_test klippy "Test invoke klippy (Python3)" $PYTHON scripts/test_klippy.py -d ${DICTDIR} test/klippy/*.test finish_test klippy "Test invoke klippy (Python3)"