diff options
Diffstat (limited to 'qa/test_import.py')
-rw-r--r-- | qa/test_import.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/qa/test_import.py b/qa/test_import.py new file mode 100644 index 000000000..4ee59b565 --- /dev/null +++ b/qa/test_import.py @@ -0,0 +1,38 @@ +# try to import all .py files from a given directory + +import glob +import os +import importlib +import importlib.util +import pytest + +def _module_name(path): + task = os.path.splitext(path)[0] + parts = task.split(os.path.sep) + package = parts[0] + name = ''.join('.' + c for c in parts[1:]) + return package, name + +def _import_file(path): + package, mod_name = _module_name(path) + line = f'Importing {package}{mod_name} from {path}' + print(f'{line:<80}', end='') + mod_spec = importlib.util.find_spec(mod_name, package) + mod = mod_spec.loader.load_module(f'{package}{mod_name}') + if mod is None: + result = 'FAIL' + else: + result = 'DONE' + print(f'{result:>6}') + mod_spec.loader.exec_module(mod) + return result + +def get_paths(): + for g in ['tasks/**/*.py']: + for p in glob.glob(g, recursive=True): + yield p + +@pytest.mark.parametrize("path", list(sorted(get_paths()))) +def test_import(path): + assert _import_file(path) == 'DONE' + |