feat: more tests

This commit is contained in:
Swann 2020-04-07 18:19:17 +02:00
parent fc15478dfa
commit 673a9dd669
No known key found for this signature in database
GPG Key ID: B880407E0F5F413E
13 changed files with 171 additions and 27 deletions

View File

@ -1,2 +1,3 @@
include:
- local: .gitlab/ci/test.gitlab-ci.yml
- local: .gitlab/ci/build.gitlab-ci.yml

View File

@ -0,0 +1,9 @@
image: python:latest
test:
script:
- git submodule init
- git submodule update
- pip install pytest, blender-addon-tester
- python scripts\test_addon.py multi_user $BLENDER_VERSIONS

View File

@ -46,7 +46,8 @@ from . import environment, utils
# TODO: remove dependency as soon as replication will be installed as a module
DEPENDENCIES = {
("zmq","zmq"),
("jsondiff","jsondiff")
("jsondiff","jsondiff"),
("deepdiff", "deepdiff")
}

View File

@ -139,7 +139,7 @@ class BlAction(BlDatablock):
def _construct(self, data):
return bpy.data.actions.new(data["name"])
def _load(self, data, target):
def _load_implementation(self, data, target):
for dumped_fcurve in data["fcurves"]:
dumped_data_path = dumped_fcurve["data_path"]
dumped_array_index = dumped_fcurve["dumped_array_index"]
@ -154,8 +154,7 @@ class BlAction(BlDatablock):
load_fcurve(dumped_fcurve, fcurve)
target.id_root = data['id_root']
def _dump(self, instance=None):
assert(instance)
def _dump_implementation(self, data, instance=None):
dumper = Dumper()
dumper.exclude_filter = [
'name_full',
@ -174,7 +173,7 @@ class BlAction(BlDatablock):
data["fcurves"] = []
for fcurve in self.instance.fcurves:
for fcurve in instance.fcurves:
data["fcurves"].append(dump_fcurve(fcurve, use_numpy=True))
return data

View File

@ -153,7 +153,7 @@ def dump_layer(layer):
'opacity',
'channel_color',
'color',
'thickness',
# 'thickness', #TODO: enabling only for annotation
'tint_color',
'tint_factor',
'vertex_paint_opacity',

View File

@ -1,4 +0,0 @@
from . import *
def dump(datablock):
pass

View File

@ -0,0 +1,25 @@
import os
import pytest
import bpy
@pytest.fixture
def clear_blend():
""" Remove all datablocks of a blend
"""
for type_name in dir(bpy.data):
try:
type_collection = getattr(bpy.data, type_name)
for item in type_collection:
type_collection.remove(item)
except Exception:
continue
@pytest.fixture
def load_blendfile(blendname):
print(f"loading {blendname}")
dir_path = os.path.dirname(os.path.realpath(__file__))
bpy.ops.wm.open_mainfile(filepath=os.path.join(dir_path, blendname))

Binary file not shown.

View File

@ -0,0 +1,38 @@
import os
import pytest
from deepdiff import DeepDiff
import bpy
import random
from multi_user.bl_types.bl_action import BlAction
INTERPOLATION = ['CONSTANT', 'LINEAR', 'BEZIER', 'SINE', 'QUAD', 'CUBIC', 'QUART', 'QUINT', 'EXPO', 'CIRC', 'BACK', 'BOUNCE', 'ELASTIC']
# @pytest.mark.parametrize('blendname', ['test_action.blend'])
def test_action(clear_blend):
# Generate a random action
datablock = bpy.data.actions.new("sdsad")
fcurve_sample = datablock.fcurves.new('location')
fcurve_sample.keyframe_points.add(100)
datablock.id_root = 'MESH'
for i, point in enumerate(fcurve_sample.keyframe_points):
point.co[0] = i
point.co[1] = random.randint(-10,10)
point.interpolation = INTERPOLATION[random.randint(0, len(INTERPOLATION)-1)]
bpy.ops.mesh.primitive_plane_add()
bpy.data.objects[0].animation_data_create()
bpy.data.objects[0].animation_data.action = datablock
# Test
implementation = BlAction()
expected = implementation._dump(datablock)
bpy.data.actions.remove(datablock)
test = implementation._construct(expected)
implementation._load(expected, test)
result = implementation._dump(test)
assert not DeepDiff(expected, result)

View File

@ -0,0 +1,25 @@
import os
import pytest
from deepdiff import DeepDiff
import bpy
from multi_user.bl_types.bl_camera import BlCamera
@pytest.mark.parametrize('camera_type', ['PANO','PERSP','ORTHO'])
def test_camera(clear_blend, camera_type):
bpy.ops.object.camera_add()
datablock = bpy.data.cameras[0]
datablock.type = camera_type
camera_dumper = BlCamera()
expected = camera_dumper._dump(datablock)
bpy.data.cameras.remove(datablock)
test = camera_dumper._construct(expected)
camera_dumper._load(expected, test)
result = camera_dumper._dump(test)
assert not DeepDiff(expected, result)

View File

@ -0,0 +1,23 @@
import os
import pytest
from deepdiff import DeepDiff
import bpy
from multi_user.bl_types.bl_gpencil import BlGpencil
def test_gpencil(clear_blend):
bpy.ops.object.gpencil_add(type='MONKEY')
datablock = bpy.data.grease_pencils[0]
implementation = BlGpencil()
expected = implementation._dump(datablock)
bpy.data.grease_pencils.remove(datablock)
test = implementation._construct(expected)
implementation._load(expected, test)
result = implementation._dump(test)
assert not DeepDiff(expected, result)

View File

@ -1,24 +1,23 @@
import pytest
import os
# from deepdiff import DeepDiff
from multi_user.bl_types.bl_light import BlLight
import pytest
from deepdiff import DeepDiff
import bpy
@pytest.fixture
def load_test_file():
dir_path = os.path.dirname(os.path.realpath(__file__))
bpy.ops.wm.open_mainfile(filepath=os.path.join(dir_path,"light.blend"))
from multi_user.bl_types.bl_light import BlLight
def test_light(load_test_file):
from jsondiff import diff
blender_light = bpy.data.lights['point']
light_dumper = BlLight(owner='None')
sample_data = light_dumper._dump(blender_light)
@pytest.mark.parametrize('light_type', ['SPOT','SUN','POINT','AREA'])
def test_light(clear_blend, light_type):
bpy.ops.object.light_add(type=light_type)
blender_light = bpy.data.lights[0]
light_dumper = BlLight()
expected = light_dumper._dump(blender_light)
bpy.data.lights.remove(blender_light)
test = light_dumper._construct(sample_data)
light_dumper._load(sample_data, test)
sample_2 = light_dumper._dump(test)
assert diff(sample_data,test), False
test = light_dumper._construct(expected)
light_dumper._load(expected, test)
result = light_dumper._dump(test)
assert not DeepDiff(expected, result)

View File

@ -0,0 +1,28 @@
import os
import pytest
from deepdiff import DeepDiff
import bpy
from multi_user.bl_types.bl_material import BlMaterial
def test_material(clear_blend):
nodes_types = [node.bl_rna.identifier for node in bpy.types.ShaderNode.__subclasses__()]
datablock = bpy.data.materials.new("test")
datablock.use_nodes = True
bpy.data.materials.create_gpencil_data(datablock)
for ntype in nodes_types:
datablock.node_tree.nodes.new(ntype)
implementation = BlMaterial()
expected = implementation._dump(datablock)
bpy.data.materials.remove(datablock)
test = implementation._construct(expected)
implementation._load(expected, test)
result = implementation._dump(test)
assert not DeepDiff(expected, result)