Start of dependency tracer work.

This commit is contained in:
Sybren A. Stüvel
2018-02-26 18:16:15 +01:00
parent 59c0b6df4c
commit 15cd74cda4
12 changed files with 340 additions and 0 deletions
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 10 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 MiB

+44
View File
@@ -0,0 +1,44 @@
import unittest
from blender_asset_tracer.bpathlib import BlendPath
class BlendPathTest(unittest.TestCase):
def test_string_path(self):
p = BlendPath('//some/file.blend')
self.assertEqual(b'//some/file.blend', p)
p = BlendPath(r'C:\some\file.blend')
self.assertEqual(b'C:\\some\\file.blend', p)
def test_is_absolute(self):
self.assertFalse(BlendPath('//some/file.blend').is_absolute())
self.assertTrue(BlendPath('/some/file.blend').is_absolute())
self.assertTrue(BlendPath('C:/some/file.blend').is_absolute())
self.assertFalse(BlendPath('some/file.blend').is_absolute())
self.assertFalse(BlendPath(b'//some/file.blend').is_absolute())
self.assertTrue(BlendPath(b'/some/file.blend').is_absolute())
self.assertTrue(BlendPath(b'C:/some/file.blend').is_absolute())
self.assertFalse(BlendPath(b'some/file.blend').is_absolute())
def test_is_blendfile_relative(self):
self.assertTrue(BlendPath('//some/file.blend').is_blendfile_relative())
self.assertFalse(BlendPath('/some/file.blend').is_blendfile_relative())
self.assertFalse(BlendPath('C:/some/file.blend').is_blendfile_relative())
self.assertFalse(BlendPath('some/file.blend').is_blendfile_relative())
self.assertTrue(BlendPath(b'//some/file.blend').is_blendfile_relative())
self.assertFalse(BlendPath(b'/some/file.blend').is_blendfile_relative())
self.assertFalse(BlendPath(b'C:/some/file.blend').is_blendfile_relative())
self.assertFalse(BlendPath(b'some/file.blend').is_blendfile_relative())
def test_make_absolute(self):
self.assertEqual(b'/root/to/some/file.blend',
BlendPath(b'//some/file.blend').absolute(b'/root/to'))
self.assertEqual(b'/root/to/some/file.blend',
BlendPath(b'some/file.blend').absolute(b'/root/to'))
self.assertEqual(b'/root/to/../some/file.blend',
BlendPath(b'../some/file.blend').absolute(b'/root/to'))
self.assertEqual(b'/shared/some/file.blend',
BlendPath(b'/shared/some/file.blend').absolute(b'/root/to'))
+66
View File
@@ -0,0 +1,66 @@
import logging
from abstract_test import AbstractBlendFileTest
from blender_asset_tracer import tracer, blendfile
class AbstractTracerTest(AbstractBlendFileTest):
@classmethod
def setUpClass(cls):
super().setUpClass()
logging.basicConfig(level=logging.INFO)
logging.getLogger('blender_asset_tracer.tracer').setLevel(logging.DEBUG)
class AssetHoldingBlocksTest(AbstractTracerTest):
def setUp(self):
self.bf = blendfile.BlendFile(self.blendfiles / 'basic_file.blend')
def test_simple_file(self):
# This file should not depend on external assets.
blocks_seen = 0
seen_scene = seen_ob = False
for block in tracer.asset_holding_blocks(self.bf):
assert isinstance(block, blendfile.BlendFileBlock)
blocks_seen += 1
# The four-letter-code blocks don't refer to assets, so they
# shouldn't be yielded.
self.assertEqual(2, len(block.code))
# Library blocks should not be yielded either.
self.assertNotEqual(b'LI', block.code)
# Do some arbitrary tests that convince us stuff is read well.
if block.code == b'SC':
seen_scene = True
self.assertEqual(b'SCScene', block[b'id', b'name'])
continue
if block.code == b'OB':
seen_ob = True
self.assertEqual('OBümlaut', block.get((b'id', b'name'), as_str=True))
continue
self.assertTrue(seen_scene)
self.assertTrue(seen_ob)
# Many of the data blocks are skipped, because asset_holding_blocks() only
# yields top-level, directly-understandable blocks.
#
# The numbers here are taken from whatever the code does now; I didn't
# count the actual blocks in the actual blend file.
self.assertEqual(965, len(self.bf.blocks))
self.assertEqual(37, blocks_seen)
class DepsTest(AbstractBlendFileTest):
def test_no_deps(self):
for dep in tracer.deps(self.blendfiles / 'basic_file.blend'):
self.fail(dep)
def test_ob_mat_texture(self):
for dep in tracer.deps(self.blendfiles / 'material_textures.blend'):
self.fail(repr(dep))