refactor: fix tests

This commit is contained in:
Swann 2021-05-19 15:12:11 +02:00
parent 28e83a38e6
commit f0b03c50f2
No known key found for this signature in database
GPG Key ID: E1D3641A7C43AACB
22 changed files with 80 additions and 88 deletions

View File

@ -57,7 +57,7 @@ def resolve_from_root(data: dict, root: str, construct = True):
if construct and not datablock_ref:
name = self.data.get('name')
logging.debug(f"Constructing {name}")
datablock_ref = self._construct(data=self.data)
datablock_ref = self.construct(data=self.data)
if datablock_ref is not None:
setattr(datablock_ref, 'uuid', self.uuid)

View File

@ -63,9 +63,7 @@ class BlMesh(ReplicatedDatablock):
@staticmethod
def construct(data: dict) -> object:
instance = bpy.data.meshes.new(data.get("name"))
instance.uuid = data.get("uuid")
return instance
return bpy.data.meshes.new(data.get("name"))
@staticmethod
def load(data: dict, datablock: object):

View File

@ -469,10 +469,7 @@ class BlObject(ReplicatedDatablock):
if data_type != 'EMPTY' and object_data is None:
raise Exception(f"Fail to load object {data['name']})")
instance = bpy.data.objects.new(object_name, object_data)
instance.uuid = data.get("uuid")
return instance
return bpy.data.objects.new(object_name, object_data)
@staticmethod
def load(data: dict, datablock: object):

View File

@ -381,10 +381,7 @@ class BlScene(ReplicatedDatablock):
@staticmethod
def construct(data: dict) -> object:
instance = bpy.data.scenes.new(data["name"])
instance.uuid = data.get('uuid')
return instance
return bpy.data.scenes.new(data["name"])
@staticmethod
def load(data: dict, datablock: object):

View File

@ -32,11 +32,11 @@ def test_action(clear_blend):
# Test
implementation = BlAction()
expected = implementation._dump(datablock)
expected = implementation.dump(datablock)
bpy.data.actions.remove(datablock)
test = implementation._construct(expected)
implementation._load(expected, test)
result = implementation._dump(test)
test = implementation.construct(expected)
implementation.load(expected, test)
result = implementation.dump(test)
assert not DeepDiff(expected, result)

View File

@ -12,11 +12,11 @@ def test_armature(clear_blend):
datablock = bpy.data.armatures[0]
implementation = BlArmature()
expected = implementation._dump(datablock)
expected = implementation.dump(datablock)
bpy.data.armatures.remove(datablock)
test = implementation._construct(expected)
implementation._load(expected, test)
result = implementation._dump(test)
test = implementation.construct(expected)
implementation.load(expected, test)
result = implementation.dump(test)
assert not DeepDiff(expected, result)

View File

@ -15,11 +15,11 @@ def test_camera(clear_blend, camera_type):
datablock.type = camera_type
camera_dumper = BlCamera()
expected = camera_dumper._dump(datablock)
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)
test = camera_dumper.construct(expected)
camera_dumper.load(expected, test)
result = camera_dumper.dump(test)
assert not DeepDiff(expected, result)

View File

@ -23,11 +23,11 @@ def test_collection(clear_blend):
# Test
implementation = BlCollection()
expected = implementation._dump(datablock)
expected = implementation.dump(datablock)
bpy.data.collections.remove(datablock)
test = implementation._construct(expected)
implementation._load(expected, test)
result = implementation._dump(test)
test = implementation.construct(expected)
implementation.load(expected, test)
result = implementation.dump(test)
assert not DeepDiff(expected, result)

View File

@ -19,11 +19,11 @@ def test_curve(clear_blend, curve_type):
datablock = bpy.data.curves[0]
implementation = BlCurve()
expected = implementation._dump(datablock)
expected = implementation.dump(datablock)
bpy.data.curves.remove(datablock)
test = implementation._construct(expected)
implementation._load(expected, test)
result = implementation._dump(test)
test = implementation.construct(expected)
implementation.load(expected, test)
result = implementation.dump(test)
assert not DeepDiff(expected, result)

View File

@ -13,11 +13,11 @@ def test_gpencil(clear_blend):
datablock = bpy.data.grease_pencils[0]
implementation = BlGpencil()
expected = implementation._dump(datablock)
expected = implementation.dump(datablock)
bpy.data.grease_pencils.remove(datablock)
test = implementation._construct(expected)
implementation._load(expected, test)
result = implementation._dump(test)
test = implementation.construct(expected)
implementation.load(expected, test)
result = implementation.dump(test)
assert not DeepDiff(expected, result)

View File

@ -13,11 +13,11 @@ def test_lattice(clear_blend):
datablock = bpy.data.lattices[0]
implementation = BlLattice()
expected = implementation._dump(datablock)
expected = implementation.dump(datablock)
bpy.data.lattices.remove(datablock)
test = implementation._construct(expected)
implementation._load(expected, test)
result = implementation._dump(test)
test = implementation.construct(expected)
implementation.load(expected, test)
result = implementation.dump(test)
assert not DeepDiff(expected, result)

View File

@ -14,11 +14,11 @@ def test_lightprobes(clear_blend, lightprobe_type):
blender_light = bpy.data.lightprobes[0]
lightprobe_dumper = BlLightprobe()
expected = lightprobe_dumper._dump(blender_light)
expected = lightprobe_dumper.dump(blender_light)
bpy.data.lightprobes.remove(blender_light)
test = lightprobe_dumper._construct(expected)
lightprobe_dumper._load(expected, test)
result = lightprobe_dumper._dump(test)
test = lightprobe_dumper.construct(expected)
lightprobe_dumper.load(expected, test)
result = lightprobe_dumper.dump(test)
assert not DeepDiff(expected, result)

View File

@ -13,11 +13,11 @@ def test_light(clear_blend, light_type):
blender_light = bpy.data.lights[0]
light_dumper = BlLight()
expected = light_dumper._dump(blender_light)
expected = light_dumper.dump(blender_light)
bpy.data.lights.remove(blender_light)
test = light_dumper._construct(expected)
light_dumper._load(expected, test)
result = light_dumper._dump(test)
test = light_dumper.construct(expected)
light_dumper.load(expected, test)
result = light_dumper.dump(test)
assert not DeepDiff(expected, result)

View File

@ -17,12 +17,12 @@ def test_material_nodes(clear_blend):
datablock.node_tree.nodes.new(ntype)
implementation = BlMaterial()
expected = implementation._dump(datablock)
expected = implementation.dump(datablock)
bpy.data.materials.remove(datablock)
test = implementation._construct(expected)
implementation._load(expected, test)
result = implementation._dump(test)
test = implementation.construct(expected)
implementation.load(expected, test)
result = implementation.dump(test)
assert not DeepDiff(expected, result)
@ -32,11 +32,11 @@ def test_material_gpencil(clear_blend):
bpy.data.materials.create_gpencil_data(datablock)
implementation = BlMaterial()
expected = implementation._dump(datablock)
expected = implementation.dump(datablock)
bpy.data.materials.remove(datablock)
test = implementation._construct(expected)
implementation._load(expected, test)
result = implementation._dump(test)
test = implementation.construct(expected)
implementation.load(expected, test)
result = implementation.dump(test)
assert not DeepDiff(expected, result)

View File

@ -18,11 +18,11 @@ def test_mesh(clear_blend, mesh_type):
# Test
implementation = BlMesh()
expected = implementation._dump(datablock)
expected = implementation.dump(datablock)
bpy.data.meshes.remove(datablock)
test = implementation._construct(expected)
implementation._load(expected, test)
result = implementation._dump(test)
test = implementation.construct(expected)
implementation.load(expected, test)
result = implementation.dump(test)
assert not DeepDiff(expected, result)

View File

@ -13,11 +13,11 @@ def test_metaball(clear_blend, metaballs_type):
datablock = bpy.data.metaballs[0]
dumper = BlMetaball()
expected = dumper._dump(datablock)
expected = dumper.dump(datablock)
bpy.data.metaballs.remove(datablock)
test = dumper._construct(expected)
dumper._load(expected, test)
result = dumper._dump(test)
test = dumper.construct(expected)
dumper.load(expected, test)
result = dumper.dump(test)
assert not DeepDiff(expected, result)

View File

@ -65,11 +65,11 @@ def test_object(clear_blend):
datablock.shape_key_add(name='shape2')
implementation = BlObject()
expected = implementation._dump(datablock)
expected = implementation.dump(datablock)
bpy.data.objects.remove(datablock)
test = implementation._construct(expected)
implementation._load(expected, test)
result = implementation._dump(test)
test = implementation.construct(expected)
implementation.load(expected, test)
result = implementation.dump(test)
print(DeepDiff(expected, result))
assert not DeepDiff(expected, result)

View File

@ -15,11 +15,11 @@ def test_scene(clear_blend):
datablock.view_settings.use_curve_mapping = True
# Test
implementation = BlScene()
expected = implementation._dump(datablock)
expected = implementation.dump(datablock)
bpy.data.scenes.remove(datablock)
test = implementation._construct(expected)
implementation._load(expected, test)
result = implementation._dump(test)
test = implementation.construct(expected)
implementation.load(expected, test)
result = implementation.dump(test)
assert not DeepDiff(expected, result)

View File

@ -12,11 +12,11 @@ def test_speaker(clear_blend):
datablock = bpy.data.speakers[0]
implementation = BlSpeaker()
expected = implementation._dump(datablock)
expected = implementation.dump(datablock)
bpy.data.speakers.remove(datablock)
test = implementation._construct(expected)
implementation._load(expected, test)
result = implementation._dump(test)
test = implementation.construct(expected)
implementation.load(expected, test)
result = implementation.dump(test)
assert not DeepDiff(expected, result)

View File

@ -14,11 +14,11 @@ def test_texture(clear_blend, texture_type):
datablock = bpy.data.textures.new('test', texture_type)
implementation = BlTexture()
expected = implementation._dump(datablock)
expected = implementation.dump(datablock)
bpy.data.textures.remove(datablock)
test = implementation._construct(expected)
implementation._load(expected, test)
result = implementation._dump(test)
test = implementation.construct(expected)
implementation.load(expected, test)
result = implementation.dump(test)
assert not DeepDiff(expected, result)

View File

@ -11,11 +11,11 @@ def test_volume(clear_blend):
datablock = bpy.data.volumes.new("Test")
implementation = BlVolume()
expected = implementation._dump(datablock)
expected = implementation.dump(datablock)
bpy.data.volumes.remove(datablock)
test = implementation._construct(expected)
implementation._load(expected, test)
result = implementation._dump(test)
test = implementation.construct(expected)
implementation.load(expected, test)
result = implementation.dump(test)
assert not DeepDiff(expected, result)

View File

@ -12,11 +12,11 @@ def test_world(clear_blend):
datablock.use_nodes = True
implementation = BlWorld()
expected = implementation._dump(datablock)
expected = implementation.dump(datablock)
bpy.data.worlds.remove(datablock)
test = implementation._construct(expected)
implementation._load(expected, test)
result = implementation._dump(test)
test = implementation.construct(expected)
implementation.load(expected, test)
result = implementation.dump(test)
assert not DeepDiff(expected, result)