示例#1
0
 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)
示例#2
0
 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)
示例#3
0
 def test_types(self):
     attrs = iter(get_resource_class_attributes(MyEntityMember).values())
     attr0 = next(attrs)
     self.assert_equal(attr0.resource_attr, ATTRIBUTE_NAMES[0])
     self.assert_equal(attr0.kind, RESOURCE_ATTRIBUTE_KINDS.TERMINAL)
     self.assert_equal(attr0.entity_attr, 'id')
     self.assert_equal(attr0.attr_type, int)
     attr1 = next(attrs)
     self.assert_equal(attr1.resource_attr, ATTRIBUTE_NAMES[1])
     self.assert_equal(attr1.kind, RESOURCE_ATTRIBUTE_KINDS.MEMBER)
     self.assert_equal(attr1.entity_attr, 'parent')
     self.assert_equal(attr1.attr_type, IMyEntityParent)
     attr2 = next(attrs)
     self.assert_equal(attr2.resource_attr, ATTRIBUTE_NAMES[2])
     self.assert_equal(attr2.kind,
                       RESOURCE_ATTRIBUTE_KINDS.COLLECTION)
     self.assert_equal(attr2.entity_attr, 'children')
     self.assert_equal(attr2.attr_type, IMyEntityChild)
     attr3 = next(attrs)
     self.assert_equal(attr3.resource_attr, ATTRIBUTE_NAMES[3])
     self.assert_equal(attr3.kind, RESOURCE_ATTRIBUTE_KINDS.TERMINAL)
     self.assert_equal(attr3.entity_attr, 'text')
     self.assert_equal(attr3.attr_type, str)
     attr4 = next(attrs)
     self.assert_equal(attr4.resource_attr, ATTRIBUTE_NAMES[4])
     attr5 = next(attrs)
     self.assert_equal(attr5.resource_attr, ATTRIBUTE_NAMES[5])
     self.assert_equal(attr5.kind, RESOURCE_ATTRIBUTE_KINDS.TERMINAL)
     self.assert_equal(attr5.entity_attr, 'number')
     self.assert_equal(attr5.attr_type, int)
     self.assert_true(is_resource_class_member_attribute(MyEntityMember,
                                                         'parent'))
     self.assert_true(is_resource_class_collection_attribute(MyEntityMember,
                                                             'children'))
     self.assert_true(is_resource_class_resource_attribute(MyEntityMember,
                                                           'parent'))
     self.assert_true(is_resource_class_resource_attribute(MyEntityMember,
                                                           'children'))
     self.assert_true(isinstance(getattr(MyEntityMember, 'id'),
                                 terminal_attribute))
示例#4
0
 def test_types(self):
     attrs = iter(get_resource_class_attributes(MyEntityMember).values())
     attr0 = next(attrs)
     self.assert_equal(attr0.resource_attr, ATTRIBUTE_NAMES[0])
     self.assert_equal(attr0.kind, RESOURCE_ATTRIBUTE_KINDS.TERMINAL)
     self.assert_equal(attr0.entity_attr, 'id')
     self.assert_equal(attr0.attr_type, int)
     attr1 = next(attrs)
     self.assert_equal(attr1.resource_attr, ATTRIBUTE_NAMES[1])
     self.assert_equal(attr1.kind, RESOURCE_ATTRIBUTE_KINDS.MEMBER)
     self.assert_equal(attr1.entity_attr, 'parent')
     self.assert_equal(attr1.attr_type, IMyEntityParent)
     attr2 = next(attrs)
     self.assert_equal(attr2.resource_attr, ATTRIBUTE_NAMES[2])
     self.assert_equal(attr2.kind, RESOURCE_ATTRIBUTE_KINDS.COLLECTION)
     self.assert_equal(attr2.entity_attr, 'children')
     self.assert_equal(attr2.attr_type, IMyEntityChild)
     attr3 = next(attrs)
     self.assert_equal(attr3.resource_attr, ATTRIBUTE_NAMES[3])
     self.assert_equal(attr3.kind, RESOURCE_ATTRIBUTE_KINDS.TERMINAL)
     self.assert_equal(attr3.entity_attr, 'text')
     self.assert_equal(attr3.attr_type, str)
     attr4 = next(attrs)
     self.assert_equal(attr4.resource_attr, ATTRIBUTE_NAMES[4])
     attr5 = next(attrs)
     self.assert_equal(attr5.resource_attr, ATTRIBUTE_NAMES[5])
     self.assert_equal(attr5.kind, RESOURCE_ATTRIBUTE_KINDS.TERMINAL)
     self.assert_equal(attr5.entity_attr, 'number')
     self.assert_equal(attr5.attr_type, int)
     self.assert_true(
         is_resource_class_member_attribute(MyEntityMember, 'parent'))
     self.assert_true(
         is_resource_class_collection_attribute(MyEntityMember, 'children'))
     self.assert_true(
         is_resource_class_resource_attribute(MyEntityMember, 'parent'))
     self.assert_true(
         is_resource_class_resource_attribute(MyEntityMember, 'children'))
     self.assert_true(
         isinstance(getattr(MyEntityMember, 'id'), terminal_attribute))
示例#5
0
文件: storing.py 项目: b8va/everest
 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)
示例#6
0
 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)