def _find_referrer(obj, refattrs): refs = [] igt = obj.igt if hasattr(obj, 'igt') else obj refd = ref.referrers(igt, obj.id, refattrs=refattrs) # sort for now because ref.referents doesn't return document order for ra, ids in sorted(refd.items()): refs.extend(igt.get_any(_id) for _id in ids) return refs
def referrers(self, id, refattrs=None): if refattrs is None: return self._referrer_cache.get(id, {}) else: return ref.referrers(self, id, refattrs=refattrs)
def test_referrers(self): assert ref.referrers(self.xc1[0], 'p', refattrs=('alignment',)) == {'alignment': []} assert ref.referrers(self.xc1[0], 'p1', refattrs=('alignment',)) == {'alignment': []} assert ref.referrers(self.xc2[0], 'p', refattrs=('alignment',)) == {'alignment': ['t']} assert ref.referrers(self.xc2[0], 'p1', refattrs=('alignment',)) == {'alignment': ['t1']} assert ref.referrers(self.xc3[0], 'p', refattrs=('alignment', 'segmentation')) == {'alignment': ['t'], 'segmentation': ['w']} assert ref.referrers(self.xc3[0], 'p') == {'alignment': ['t'], 'segmentation': ['w'], 'content': []} assert ref.referrers(self.xc3[0], 'w') == {'alignment': ['x'], 'segmentation': ['m'], 'content': []} assert ref.referrers(self.xc3[0], 'm') == {'alignment': ['g'], 'segmentation': [], 'content': []} assert ref.referrers(self.xc3[0], 'x') == {'alignment': [], 'segmentation': [], 'content': []} assert ref.referrers(self.xc3[0], 'x', refattrs=('alignment', 'children')) == {'alignment': [], 'children': ['x']} assert ref.referrers(self.xc3[0], 'x1', refattrs=('alignment', 'children')) == {'alignment': [], 'children': ['x4']}