blender-asset-tracer/tests/test_tracer_file2blocks.py
Sybren A. Stüvel 8009ff1e47 Added block expansion
The expansion process follows pointers and library links to construct
the full set of actually-used data blocks. This set consists of all data
blocks in the initial blend file, and all *actually linked-to* data
blocks in linked blend files.

I've also removed non-recursive dependency listing.
2018-03-02 15:44:07 +01:00

37 lines
1.3 KiB
Python

from blender_asset_tracer import blendfile
from blender_asset_tracer.tracer import file2blocks
from test_tracer import AbstractTracerTest
class File2BlocksTest(AbstractTracerTest):
def test_id_blocks(self):
self.bf = blendfile.BlendFile(self.blendfiles / 'doubly_linked.blend')
foreign_blocks = {}
for block in file2blocks.iter_blocks(self.bf):
# Only register blocks from libraries.
if block.bfile == self.bf:
continue
foreign_blocks[block.id_name] = block
self.assertNotEqual({}, foreign_blocks)
# It should find directly linked blocks (GRCubes and MABrick) as well
# as indirectly linked (MECube³).
self.assertIn(b'GRCubes', foreign_blocks)
self.assertIn(b'MABrick', foreign_blocks)
self.assertIn('MECube³'.encode(), foreign_blocks)
self.assertIn('OBümlaut'.encode(), foreign_blocks)
def test_circular_files(self):
self.bf = blendfile.BlendFile(self.blendfiles / 'recursive_dependency_1.blend')
blocks = {}
for block in file2blocks.iter_blocks(self.bf):
blocks[block.id_name] = block
self.assertNotEqual({}, blocks)
self.assertIn(b'MAMaterial', blocks)
self.assertIn(b'OBCube', blocks)
self.assertIn(b'MECube', blocks)