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>
This commit is contained in:
parent
b743a64685
commit
41d42a07bf
|
@ -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,
|
||||
|
|
|
@ -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)"
|
||||
|
|
Loading…
Reference in New Issue