Skip to content

Commit

Permalink
add deep compare
Browse files Browse the repository at this point in the history
  • Loading branch information
markreidvfx committed May 23, 2023
1 parent 48f968b commit d424da5
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/test_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,48 @@
import unittest

import aaf2
from aaf2 import properties
import common




class AAFCopyTests(unittest.TestCase):

def compare_objects(self, a, b):
for key in a.keys():
if a[key].format_name() == "Property":
self.assertEqual(a[key].value, b[key].value)
else:
pa = a[key]
pb = b[key]

if isinstance(pa, (properties.StrongRefSetProperty,
properties.WeakRefArrayProperty)):
for key, item_a in pa.items():
self.assertTrue(key in pb)
item_b = pb[key]
self.compare_objects(item_a, item_b)

elif isinstance(pa, properties.StrongRefVectorProperty):
for item_a, item_b in zip(pa, pb):
self.compare_objects(item_a, item_b)
elif isinstance(pa, (properties.StrongRefProperty,
properties.WeakRefProperty)):
self.compare_objects(pa.value, pb.value)

elif isinstance(pa, properties.StreamProperty):
read_size = a.root.cfb.sector_size
sa = pa.open('r')
sb = pb.open('r')
byte_size = sa.dir.byte_size
self.assertEqual(byte_size, sb.dir.byte_size)
while byte_size > 0:
da = sa.read(read_size)
db = sb.read(read_size)
self.assertEqual(da, db)
byte_size -= len(da)

def test_mob_copy(self):
test_file = os.path.join(common.test_files_dir(),"test_file_01.aaf")
result_file = common.get_test_file('copy_mobs.aaf')
Expand All @@ -28,6 +65,7 @@ def test_mob_copy(self):
for mob in a.content.mobs:
other_mob = a.content.mobs.get(mob.mob_id, None)
self.assertEqual(mob.mob_id, other_mob.mob_id)
self.compare_objects(mob, other_mob)

result_file = common.get_test_file('copy_mobs_fail.aaf')
with aaf2.open(test_file, 'r') as a:
Expand Down

0 comments on commit d424da5

Please sign in to comment.