From 5b1688307718738a037d0013bfb781cdaf93226c Mon Sep 17 00:00:00 2001 From: Aurelien Vaillant Date: Mon, 24 Jan 2022 16:45:26 +0100 Subject: [PATCH] Adding a security to check if the folder call exist --- tests/main.py | 44 +++++++++++++++++++++++++++++++++++++++++ tests/utils/issue.py | 8 ++++++++ tests/utils/misc.py | 47 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 tests/main.py create mode 100644 tests/utils/issue.py create mode 100644 tests/utils/misc.py diff --git a/tests/main.py b/tests/main.py new file mode 100644 index 0000000..15e81af --- /dev/null +++ b/tests/main.py @@ -0,0 +1,44 @@ +import sys +import os + +from pathlib import Path +from utils.blender import b3d_launch_blender_test +from utils.container import clear_container_test +from utils.misc import ordering_test_file, generate_archive + + +def launch_unit_test(tag: str, test: list = None): + """Start all Unit Test, Blender and Unreal if needed""" + test = ordering_test_file() + b3d_launch_blender_test(test=test['blender'], tag=tag) + + +if __name__ == '__main__': + # Initialize Variable and module request + archives = [] + docker_tag = 'stilobique/blender:latest' + + # Clear blender container + clear_container_test(tag=docker_tag) + + # Prepare Blender and Unreal dependency + generate_archive(archives, 'blender-folder') + + # Generate Unit Test, a specific call or execute all Unit Test + test_list = None + if sys.argv: + for arg in sys.argv: + if '--test=' in arg: + test_list = [] + items = arg.replace('--test=', '').split(',') + for item in items: + print('Launch this test : ', item) + test_list.append(item) + + # Launch Unit Test + launch_unit_test(test=test_list, tag=docker_tag) + + # Clear archive file and container + clear_container_test(tag=docker_tag) + for archive in archives: + os.remove(Path(os.getcwd(), archive)) diff --git a/tests/utils/issue.py b/tests/utils/issue.py new file mode 100644 index 0000000..1106ce9 --- /dev/null +++ b/tests/utils/issue.py @@ -0,0 +1,8 @@ +class Archive(Exception): + def __init__(self, source): + self.source = source + + +class ArchiveFolderSourceNotFound(Archive): + def __str__(self): + return f'Can\'t find the folder source "{self.source}".' diff --git a/tests/utils/misc.py b/tests/utils/misc.py new file mode 100644 index 0000000..fd7ba70 --- /dev/null +++ b/tests/utils/misc.py @@ -0,0 +1,47 @@ +import os +import pathlib +import sys +import zipfile + +from .issue import ArchiveFolderSourceNotFound + + +def generate_archive(list_clean: list, name: str): + """From the plugin folder, generate an archive to test his code""" + archive_path_source = pathlib.Path(os.getcwd(), name) + archive_filename = pathlib.Path(os.getcwd(), f"{name}.zip") + archive_file_generate = zipfile.ZipFile(archive_filename, 'w') + + try: + # Check if all default folder are present. + if not archive_path_source.exists(): + raise ArchiveFolderSourceNotFound(source=name) + + for directory, subdir, files in os.walk(archive_path_source): + if '__pycache__' not in directory: + for file in files: + append_file = pathlib.Path(directory, file) + included_file = pathlib.Path(os.path.relpath(append_file)) + archive_file_generate.write(append_file, included_file) + + archive_file_generate.close() + list_clean.append(archive_filename) + + except BaseException as e: + print(f'Generate Archive error : \n\t{e}') + sys.exit(1) + + +def ordering_test_file(): + unit_test_folder = pathlib.Path(os.getcwd(), "tests", "unit_test") + unit_test = os.listdir(unit_test_folder) + unit_test_b3d = [] + unit_test_ue = [] + + for test in unit_test: + if '_ue_' in test: + unit_test_ue.append(test) + elif '_b3d_' in test: + unit_test_b3d.append(test) + + return {'blender': unit_test_b3d, 'unreal': unit_test_ue}