Ported iteration over properties

This commit is contained in:
Sybren A. Stüvel
2018-02-22 17:44:50 +01:00
parent 6175f6c592
commit 63c7e4fcef
5 changed files with 104 additions and 35 deletions
+79 -10
View File
@@ -12,18 +12,16 @@ class BlendFileBlockTest(unittest.TestCase):
cls.blendfiles = pathlib.Path(__file__).with_name('blendfiles')
def setUp(self):
self.bf = None
self.bf = blendfile.BlendFile(self.blendfiles / 'basic_file.blend')
def tearDown(self):
if self.bf:
self.bf.close()
def test_loading(self):
self.bf = blendfile.BlendFile(self.blendfiles / 'basic_file.blend')
self.assertFalse(self.bf.is_compressed)
def test_some_properties(self):
self.bf = blendfile.BlendFile(self.blendfiles / 'basic_file.blend')
ob = self.bf.code_index[b'OB'][0]
self.assertEqual('Object', ob.dna_type_name)
@@ -55,7 +53,6 @@ class BlendFileBlockTest(unittest.TestCase):
self.assertEqual('MECube³', mname)
def test_get_recursive_iter(self):
self.bf = blendfile.BlendFile(self.blendfiles / 'basic_file.blend')
ob = self.bf.code_index[b'OB'][0]
assert isinstance(ob, blendfile.BlendFileBlock)
@@ -72,10 +69,82 @@ class BlendFileBlockTest(unittest.TestCase):
((b'id', b'lib'), 0),
((b'id', b'name'), 'OBümlaut'),
((b'id', b'flag'), 0),
((b'id', b'tag'), 1024),
((b'id', b'us'), 1),
((b'id', b'icon_id'), 0),
((b'id', b'recalc'), 0),
((b'id', b'pad'), 0),
],
list(gen)[:-2]) # the last 2 properties are pointers and change when saving.
list(gen)[:6])
def test_iter_recursive(self):
ob = self.bf.code_index[b'OB'][0]
assert isinstance(ob, blendfile.BlendFileBlock)
# We can't test all of them in a reliable way, but it shouldn't crash.
all_items = list(ob.items_recursive())
# And we can check the first few items.
self.assertEqual(
[((b'id', b'next'), 0),
((b'id', b'prev'), 0),
((b'id', b'newid'), 0),
((b'id', b'lib'), 0),
((b'id', b'name'),
b'OB\xc3\xbcmlaut'),
((b'id', b'flag'), 0),
], all_items[:6])
def test_items(self):
ma = self.bf.code_index[b'MA'][0]
assert isinstance(ma, blendfile.BlendFileBlock)
# We can't test all of them in a reliable way, but it shouldn't crash.
all_items = list(ma.items())
# And we can check the first few items.
self.assertEqual(
[(b'id', '<ID>'), # not recursed into.
(b'adt', 0),
(b'material_type', 0),
(b'flag', 0),
(b'r', 0.8000000715255737),
(b'g', 0.03218378871679306),
(b'b', 0.36836329102516174),
(b'specr', 1.0)],
all_items[:8])
def test_keys(self):
ma = self.bf.code_index[b'MA'][0]
assert isinstance(ma, blendfile.BlendFileBlock)
# We can't test all of them in a reliable way, but it shouldn't crash.
all_keys = list(ma.keys())
# And we can check the first few items.
self.assertEqual(
[b'id', b'adt', b'material_type', b'flag', b'r', b'g', b'b', b'specr'],
all_keys[:8])
def test_values(self):
ma = self.bf.code_index[b'MA'][0]
assert isinstance(ma, blendfile.BlendFileBlock)
# We can't test all of them in a reliable way, but it shouldn't crash.
all_values = list(ma.values())
# And we can check the first few items.
self.assertEqual(
['<ID>',
0,
0,
0,
0.8000000715255737,
0.03218378871679306,
0.36836329102516174,
1.0],
all_values[:8])
def test_get_via_dict_interface(self):
ma = self.bf.code_index[b'MA'][0]
assert isinstance(ma, blendfile.BlendFileBlock)
self.assertEqual(0.8000000715255737, ma[b'r'])
ob = self.bf.code_index[b'OB'][0]
assert isinstance(ob, blendfile.BlendFileBlock)
self.assertEqual('OBümlaut', ob[b'id', b'name'].decode())