def test_find_connected_with_deps(self): member = _make_test_entity_member() dep_grph = \ build_resource_dependency_graph(self._interfaces, include_backrefs=True) coll_map = find_connected_resources(member, dependency_graph=dep_grph) # Backrefs should not make a difference since we check for duplicates. for coll in coll_map.itervalues(): self.assert_equal(len(coll), 1)
def test_find_connected_with_custom_deps(self): member = _make_test_entity_member() ent = member.get_entity() # Point grandchild's parent to new child. new_child = MyEntityChild(id=1, parent=ent) ent.children[0].children[0].parent = new_child # When backrefs are excluded, we should not pick up the new parent # of the grandchild; when backrefs are included, we should. dep_grph = build_resource_dependency_graph(self._interfaces) self.assert_false(dep_grph.has_edge((MyEntityGrandchildMember, MyEntityChildMember))) coll_map = find_connected_resources(member) self.assert_equal(len(coll_map[MyEntityChildMember]), 1) dep_grph = \ build_resource_dependency_graph(self._interfaces, include_backrefs=True) self.assert_true(dep_grph.has_edge((MyEntityGrandchildMember, MyEntityChildMember))) coll_map = find_connected_resources(member, dependency_graph=dep_grph) self.assert_equal(len(coll_map[MyEntityChildMember]), 2)
def test_dependency_graph(self): grph = build_resource_dependency_graph(self._interfaces) self.assert_equal(len(grph.nodes()), 4) entity_mb_cls = get_member_class(IMyEntity) entity_parent_mb_cls = get_member_class(IMyEntityParent) entity_child_mb_cls = get_member_class(IMyEntityChild) entity_grandchild_mb_cls = get_member_class(IMyEntityGrandchild) # Entity Parent resource deps should be empty. self.assert_equal(grph.neighbors(entity_parent_mb_cls), []) # Entity Child has Grandchild. self.assert_equal(grph.neighbors(entity_child_mb_cls), [entity_grandchild_mb_cls]) # Entity Grandchild has Child, but we ignore backreferences. self.assert_equal(grph.neighbors(entity_grandchild_mb_cls), []) # Entity has Parent and Child. self.assert_equal(set(grph.neighbors(entity_mb_cls)), set([entity_parent_mb_cls, entity_child_mb_cls]))
def test_dependency_graph(self): grph = build_resource_dependency_graph(self._interfaces) self.assert_equal(len(grph.nodes()), 4) entity_mb_cls = get_member_class(IMyEntity) entity_parent_mb_cls = get_member_class(IMyEntityParent) entity_child_mb_cls = get_member_class(IMyEntityChild) entity_grandchild_mb_cls = get_member_class(IMyEntityGrandchild) # Entity Parent resource deps should be empty. self.assert_equal(grph.neighbors(entity_parent_mb_cls), []) # Entity Child has Grandchild. self.assert_equal(grph.neighbors(entity_child_mb_cls), [entity_grandchild_mb_cls]) # Entity Grandchild has Child, but backrefs are excluded by default. self.assert_equal(grph.neighbors(entity_grandchild_mb_cls), []) # Entity has Parent and Child. self.assert_equal(set(grph.neighbors(entity_mb_cls)), set([entity_parent_mb_cls, entity_child_mb_cls]))