Adding a security to check if the folder call exist

This commit is contained in:
Aurelien Vaillant
2022-01-24 16:45:26 +01:00
parent 6eaf4e2c53
commit 5b16883077
3 changed files with 99 additions and 0 deletions
+44
View File
@@ -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))
+8
View File
@@ -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}".'
+47
View File
@@ -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}