Add all mecanism about the blender unit test
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# To disable the sdt with each command, add ' > /dev/null 2>&1' to redirect all info
|
||||||
|
# Set all variables
|
||||||
|
MOUNT_FOLDER="/addon-moderlab"
|
||||||
|
INSTALL_ADDON="$MOUNT_FOLDER/tests/utils/blender_addon.py"
|
||||||
|
|
||||||
|
export FOLDER_TEST=$MOUNT_FOLDER
|
||||||
|
|
||||||
|
# ----- ----- ----- -----
|
||||||
|
# From a previous archive generated, install the moderlab plugin
|
||||||
|
/opt/blender/blender --background --python "$INSTALL_ADDON" -- "$MOUNT_FOLDER" > /dev/null 2>&1
|
||||||
|
install_error=$?
|
||||||
|
|
||||||
|
if [ $install_error = 1 ]; then
|
||||||
|
echo Blender Test Error
|
||||||
|
echo Exit code is install_error
|
||||||
|
(exit 1)
|
||||||
|
else
|
||||||
|
# ----- ----- ----- -----
|
||||||
|
# Launch Blender Test
|
||||||
|
/opt/blender/blender --background -noaudio --disable-autoexec --addons moderlab_type --python-exit-code 1 --python "$1" -- --verbose
|
||||||
|
blender_error=$?
|
||||||
|
|
||||||
|
if [ $blender_error = 1 ]; then
|
||||||
|
echo Blender Test Error
|
||||||
|
echo Exit code is $blender_error
|
||||||
|
(exit 1)
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
+7
-3
@@ -7,10 +7,14 @@ from utils.container import clear_container_test
|
|||||||
from utils.misc import ordering_test_file, generate_archive
|
from utils.misc import ordering_test_file, generate_archive
|
||||||
|
|
||||||
|
|
||||||
def launch_unit_test(tag: str, test: list = None):
|
def launch_unit_test(tag: str, test: [str] = None):
|
||||||
"""Start all Unit Test, Blender and Unreal if needed"""
|
"""Start all Unit Test, Blender and Unreal if needed"""
|
||||||
test = ordering_test_file()
|
# Ordering Unit test Blender/Unreal
|
||||||
b3d_launch_blender_test(test=test['blender'], tag=tag)
|
if test is None:
|
||||||
|
test = ordering_test_file()
|
||||||
|
test = test['blender']
|
||||||
|
|
||||||
|
b3d_launch_blender_test(test=test, tag=tag)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import unittest
|
||||||
|
import bpy
|
||||||
|
|
||||||
|
|
||||||
|
class ActivateAddon(unittest.TestCase):
|
||||||
|
"""Activate the Blender addon"""
|
||||||
|
|
||||||
|
def setUp(self) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_activate_addon(self):
|
||||||
|
"""Activate the blender addon 'moderlab_plugin'"""
|
||||||
|
addon = bpy.ops.preferences.addon_enable(module='moderlab_type')
|
||||||
|
self.assertEqual({'FINISHED'}, addon)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import sys
|
||||||
|
sys.argv = [__file__] + (sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else [])
|
||||||
|
unittest.main()
|
||||||
@@ -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