diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /qa/test_import.py | |
parent | Initial commit. (diff) | |
download | ceph-6d07fdb6bb33b1af39833b850bb6cf8af79fe293.tar.xz ceph-6d07fdb6bb33b1af39833b850bb6cf8af79fe293.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'qa/test_import.py')
-rw-r--r-- | qa/test_import.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/qa/test_import.py b/qa/test_import.py new file mode 100644 index 000000000..fe70a1c49 --- /dev/null +++ b/qa/test_import.py @@ -0,0 +1,43 @@ +# try to import all .py files from a given directory + +import argparse +import glob +import os +import importlib +import importlib.util + + +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() + if mod is None: + result = 'FAIL' + else: + result = 'DONE' + print(f'{result:>6}') + mod_spec.loader.exec_module(mod) + +def _parser(): + parser = argparse.ArgumentParser( + description='Try to import a file', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser.add_argument('path', nargs='+', help='Glob to select files') + return parser + + +if __name__ == '__main__': + parser = _parser() + args = parser.parse_args() + for g in args.path: + for p in glob.glob(g, recursive=True): + _import_file(p) |