Add all mecanism about the blender unit test
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import os
|
||||
import docker
|
||||
import sys
|
||||
|
||||
from pathlib import PurePosixPath, Path
|
||||
|
||||
|
||||
class ErrorTest(Exception):
|
||||
""" Failed to generate the test """
|
||||
|
||||
|
||||
def b3d_launch_blender_test(client: docker = docker.from_env(), test: list = None,
|
||||
tag: str = 'stilobique/blender:latest'):
|
||||
"""Launch blender and a list of Test, you can set a specific test file with his arg."""
|
||||
unit_test_folder = Path(os.getcwd(), "tests", "unit_test")
|
||||
|
||||
if os.environ.get('GITHUB_WORKSPACE'):
|
||||
local_path = os.environ.get('GITHUB_WORKSPACE')
|
||||
else:
|
||||
local_path = os.getcwd()
|
||||
container_folder = '/addon-moderlab'
|
||||
volume = [f'{local_path}:{container_folder}']
|
||||
image_name = tag
|
||||
if test is None:
|
||||
unit_test = os.listdir(unit_test_folder)
|
||||
else:
|
||||
if type(test) is not list:
|
||||
test = [test]
|
||||
unit_test = test
|
||||
|
||||
try:
|
||||
for test in unit_test:
|
||||
print(f'Start this test : {test}')
|
||||
command = [f"/bin/bash",
|
||||
f"{PurePosixPath(container_folder, 'tests', 'launch_test.sh')}",
|
||||
f"{PurePosixPath(container_folder, 'tests', 'unit_test', test)}"]
|
||||
|
||||
docker_test = client.containers.run(image_name, command=command, volumes=volume, privileged=True,
|
||||
detach=True)
|
||||
exit_docker = docker_test.wait()
|
||||
if exit_docker['StatusCode'] != 0:
|
||||
print(f'Container error "{exit_docker["StatusCode"]}".\n\t'
|
||||
f'Show log : \n\t'
|
||||
f'{docker_test.logs()}')
|
||||
raise ErrorTest
|
||||
|
||||
except ErrorTest as exception:
|
||||
print(f'{exception.__doc__}')
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,20 @@
|
||||
import sys
|
||||
import bpy
|
||||
|
||||
# Paste this variable in the blender.py
|
||||
dependency = {
|
||||
# 'moderlab_plugin': ['moderlab_plugin.zip', 'Moderlab-Production/BlenderPlugin'],
|
||||
'moderlab_type': ['moderlab_type.zip', 'Moderlab-Production/BlenderObjectType'],
|
||||
# 'uv-packer': ['uv-packer.zip', 'Moderlab-Production/UvPacker'],
|
||||
}
|
||||
|
||||
|
||||
def b3d_install_addon(addon_path: str):
|
||||
for key, value in dependency.items():
|
||||
bpy.ops.preferences.addon_install(filepath=f'{addon_path}/{value[0]}')
|
||||
bpy.ops.preferences.addon_enable(module=key)
|
||||
bpy.ops.wm.save_userpref()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
b3d_install_addon(sys.argv[-1])
|
||||
@@ -0,0 +1,17 @@
|
||||
import docker
|
||||
|
||||
|
||||
def clear_container_test(tag: str = 'stilobique/blender:latest'):
|
||||
client = docker.from_env()
|
||||
containers = client.containers.list(all=True)
|
||||
|
||||
for container in containers:
|
||||
image_tag = container.image.tags[0]
|
||||
status = container.status
|
||||
if image_tag == tag and status == 'exited':
|
||||
container.remove()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Clear all unused blender container
|
||||
clear_container_test()
|
||||
Reference in New Issue
Block a user