Allow Packer to be used as context manager + test for rewriting img seqs

This commit is contained in:
Sybren A. Stüvel 2018-03-14 12:50:27 +01:00
parent d2ac0fa919
commit 0e9de7753c
4 changed files with 27 additions and 1 deletions

View File

@ -83,6 +83,12 @@ class Packer:
"""Clean up any temporary files.""" """Clean up any temporary files."""
self._tmpdir.cleanup() self._tmpdir.cleanup()
def __enter__(self) -> 'Packer':
return self
def __exit__(self, exc_type, exc_val, exc_tb) -> None:
self.close()
def strategise(self) -> None: def strategise(self) -> None:
"""Determine what to do with the assets. """Determine what to do with the assets.

Binary file not shown.

View File

@ -184,7 +184,6 @@ class PointerTest(AbstractBlendFileTest):
seq = ed.get_pointer((b'seqbase', b'first')) seq = ed.get_pointer((b'seqbase', b'first'))
# This is very clear to me:
seq.refine_type(b'Sequence') seq.refine_type(b'Sequence')
self.assertEqual(b'SQBlack', seq[b'name']) self.assertEqual(b'SQBlack', seq[b'name'])
self.assertEqual(28, seq[b'type']) self.assertEqual(28, seq[b'type'])

View File

@ -167,6 +167,27 @@ class PackTest(AbstractPackTest):
return infile, packer return infile, packer
def test_rewrite_sequence(self):
ppath = self.blendfiles / 'subdir'
infile = ppath / 'image_sequence_dir_up.blend'
with pack.Packer(infile, ppath, self.tpath) as packer:
packer.strategise()
packer.execute()
bf = blendfile.open_cached(self.tpath / infile.name, assert_cached=False)
scene = bf.code_index[b'SC'][0]
ed = scene.get_pointer(b'ed')
seq = ed.get_pointer((b'seqbase', b'first'))
seq_strip = seq.get_pointer(b'strip')
as_bytes = str((self.blendfiles / 'imgseq').absolute()).encode()
relpath = b'//_outside_project%b' % as_bytes
# The image sequence base path should be rewritten.
self.assertEqual(b'SQ000210.png', seq[b'name'])
self.assertEqual(relpath, seq_strip[b'dir'])
def test_noop(self): def test_noop(self):
ppath = self.blendfiles / 'subdir' ppath = self.blendfiles / 'subdir'
infile = ppath / 'doubly_linked_up.blend' infile = ppath / 'doubly_linked_up.blend'