Normalize unused paths in packed linked blends

This commit is contained in:
2026-09-10 15:36:30 +02:00
parent 89bcad5cdc
commit 8bc8165642
3 changed files with 126 additions and 2 deletions
+44
View File
@@ -10,6 +10,7 @@ from unittest import mock
from blender_asset_tracer import blendfile, pack, bpathlib
from blender_asset_tracer.pack import progress
from blender_asset_tracer.trace import result
from tests.abstract_test import AbstractBlendFileTest
@@ -151,6 +152,49 @@ class PackTest(AbstractPackTest):
self.assertEqual(b"LILib.002", rw_dbllink[1].block_name)
self.assertEqual(b"//../material_textures.blend", rw_dbllink[1].asset_path)
def test_normalises_unused_path_without_packing_asset(self):
infile = self.blendfiles / "doubly_linked.blend"
linked_file = self.blendfiles / "linked_cube.blend"
uncopied_asset = self.blendfiles / "uncopied.blend"
linked_bfile = blendfile.open_cached(linked_file)
library_block = linked_bfile.code_index[b"LI"][0]
_, path_field = library_block.get(b"name", return_field=True)
unused_usage = result.BlockUsage(
library_block,
bpathlib.BlendPath(str(uncopied_asset).encode()),
path_full_field=path_field,
)
def local_deps(path):
if path == linked_file:
return iter([unused_usage])
return iter(())
with mock.patch(
"blender_asset_tracer.pack.trace.local_deps", side_effect=local_deps
):
with pack.Packer(infile, self.blendfiles, self.tpath) as packer:
packer.strategise()
self.assertNotIn(uncopied_asset, packer._actions)
self.assertIn(
unused_usage, packer._actions[linked_file].rewrites
)
self.assertEqual(
self.tpath / "uncopied.blend",
packer._rewrite_targets[id(unused_usage)],
)
packer.execute()
packed_linked = blendfile.open_cached(
self.tpath / "linked_cube.blend", assert_cached=False
)
packed_library = packed_linked.code_index[b"LI"][0]
self.assertEqual(b"//uncopied.blend", packed_library[b"name"])
self.assertFalse((self.tpath / "uncopied.blend").exists())
def test_strategise_relative_only(self):
infile = self.blendfiles / "absolute_path.blend"