def test_attribute_checkers(self): self.assert_true( is_resource_class_terminal_attribute(IMyEntity, 'text')) self.assert_true( is_resource_class_member_attribute(IMyEntity, 'parent')) self.assert_true( is_resource_class_collection_attribute(IMyEntity, 'children')) self.assert_true( is_resource_class_resource_attribute(IMyEntity, 'parent')) self.assert_true( is_resource_class_resource_attribute(IMyEntity, 'children')) attr_names = list(get_resource_class_attribute_names(MyEntityMember)) self.assert_equal(attr_names, ATTRIBUTE_NAMES) it = get_resource_class_attribute_iterator(MyEntityMember) self.assert_equal([attr.resource_attr for attr in it], ATTRIBUTE_NAMES)
def test_attribute_checkers(self): self.assert_true(is_resource_class_terminal_attribute(IMyEntity, 'text')) self.assert_true(is_resource_class_member_attribute(IMyEntity, 'parent')) self.assert_true(is_resource_class_collection_attribute(IMyEntity, 'children')) self.assert_true(is_resource_class_resource_attribute(IMyEntity, 'parent')) self.assert_true(is_resource_class_resource_attribute(IMyEntity, 'children')) attr_names = list(get_resource_class_attribute_names(MyEntityMember)) self.assert_equal(attr_names, ATTRIBUTE_NAMES) it = get_resource_class_attribute_iterator(MyEntityMember) self.assert_equal([attr.resource_attr for attr in it], ATTRIBUTE_NAMES)
def visit(mb_cls, grph, path, incl_backrefs): for attr_name in get_resource_class_attribute_names(mb_cls): if is_resource_class_terminal_attribute(mb_cls, attr_name): continue child_descr = getattr(mb_cls, attr_name) child_mb_cls = get_member_class(child_descr.attr_type) # We do not follow cyclic references back to a resource class # that is last in the path. if len(path) > 0 and child_mb_cls is path[-1] \ and not incl_backrefs: continue if not grph.has_node(child_mb_cls): grph.add_node(child_mb_cls) path.append(mb_cls) visit(child_mb_cls, grph, path, incl_backrefs) path.pop() if not grph.has_edge((mb_cls, child_mb_cls)): grph.add_edge((mb_cls, child_mb_cls))
def visit(rc, grph, dep_grph): mb_cls = type(rc) attr_map = get_resource_class_attributes(mb_cls) for attr_name, attr in iteritems_(attr_map): if is_resource_class_terminal_attribute(mb_cls, attr_name): continue # Only follow the resource attribute if the dependency graph # has an edge here. child_mb_cls = get_member_class(attr.attr_type) if not dep_grph.has_edge((mb_cls, child_mb_cls)): continue child_rc = getattr(rc, attr_name) if is_resource_class_collection_attribute(mb_cls, attr_name): for child_mb in child_rc: if not grph.has_node(child_mb): # Ignore cyclic references. grph.add_node(child_mb) grph.add_edge((rc, child_mb)) visit(child_mb, grph, dep_grph) else: # Member. if not grph.has_node(child_rc): # Ignore cyclic references. grph.add_node(child_rc) grph.add_edge((rc, child_rc)) visit(child_rc, grph, dep_grph)
def visit(rc, grph, dep_grph): mb_cls = type(rc) attr_map = get_resource_class_attributes(mb_cls) for attr_name, attr in iteritems_(attr_map): if is_resource_class_terminal_attribute(mb_cls, attr_name): continue # Only follow the resource attribute if the dependency graph # has an edge here. child_mb_cls = get_member_class(attr.attr_type) if not dep_grph.has_edge((mb_cls, child_mb_cls)): continue child_rc = getattr(rc, attr_name) if is_resource_class_collection_attribute(mb_cls, attr_name): for child_mb in child_rc: if not grph.has_node( child_mb): # Ignore cyclic references. grph.add_node(child_mb) grph.add_edge((rc, child_mb)) visit(child_mb, grph, dep_grph) else: # Member. if not grph.has_node(child_rc): # Ignore cyclic references. grph.add_node(child_rc) grph.add_edge((rc, child_rc)) visit(child_rc, grph, dep_grph)