diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2021-10-01 20:57:26 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2021-10-04 14:36:08 -0400 |
commit | 41d42a07bf2ad23762dac02b615865efa86adfec (patch) | |
tree | 0ec2920a2e0ba782e51a45898744bde423cb03fd /klippy | |
parent | b743a646857f54342704b3115ba1ad474e21c158 (diff) | |
download | kutter-41d42a07bf2ad23762dac02b615865efa86adfec.tar.gz kutter-41d42a07bf2ad23762dac02b615865efa86adfec.tar.xz kutter-41d42a07bf2ad23762dac02b615865efa86adfec.zip |
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 <kevin@koconnor.net>
Diffstat (limited to 'klippy')
-rw-r--r-- | klippy/klippy.py | 19 |
1 files changed, 19 insertions, 0 deletions
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, |