def test_can_parse(self):
        schema_class = avro_schema_parser.parse_schema_string(self.avsc)
        self.assertTrue(pyschema.ispyschema(schema_class))
        self.assertEqual(schema_class._schema_name, self.schema_name)

        for (gen_name, gen_type), (ref_name, ref_type) in zip(schema_class._fields.items(), self.references):
            self.assertEqual(gen_name, ref_name)
            self.assertTrue(gen_type.is_similar_to(ref_type), "Types for field {0!r} don't match".format(ref_name))
    def test_can_parse(self):
        schema_class = avro_schema_parser.parse_schema_string(self.avsc)
        self.assertTrue(pyschema.ispyschema(schema_class))
        self.assertEqual(schema_class._schema_name, self.schema_name)

        for (gen_name, gen_type), (ref_name, ref_type) in zip(
                schema_class._fields.items(), self.references):
            self.assertEqual(gen_name, ref_name)
            self.assertTrue(
                gen_type.is_similar_to(ref_type),
                "Types for field {0!r} don't match".format(ref_name))
示例#3
0
def find_subrecords(a, include_this=False):
    subs = set()
    if pyschema.ispyschema(a):
        if include_this:
            subs.add(a)
        for _, field in a._fields.iteritems():
            subs |= find_subrecords(field, True)
    elif isinstance(a, types.List):
        subs |= find_subrecords(a.field_type, True)
    elif isinstance(a, types.Map):
        subs |= find_subrecords(a.value_type, True)
    elif isinstance(a, types.SubRecord):
        subs |= find_subrecords(a._schema, True)
    return subs
示例#4
0
def find_subrecords(a, include_this=False):
    subs = set()
    if pyschema.ispyschema(a):
        if include_this:
            subs.add(a)
        for _, field in a._fields.iteritems():
            subs |= find_subrecords(field, True)
    elif isinstance(a, types.List):
        subs |= find_subrecords(a.field_type, True)
    elif isinstance(a, types.Map):
        subs |= find_subrecords(a.value_type, True)
    elif isinstance(a, types.SubRecord):
        subs |= find_subrecords(a._schema, True)
    return subs
示例#5
0
def has_directed_link(a, b):
    # TODO: refactor to use find_subrecords instead
    #       to reduce duplication
    if pyschema.ispyschema(a):
        if a == b:
            return True
        for _, field in a._fields.iteritems():
            if has_directed_link(field, b):
                return True
    elif isinstance(a, types.List):
        if has_directed_link(a.field_type, b):
            return True
    elif isinstance(a, types.Map):
        if has_directed_link(a.value_type, b):
            return True
    elif isinstance(a, types.SubRecord):
        if has_directed_link(a._schema, b):
            return True
    return False
示例#6
0
def has_directed_link(a, b):
    # TODO: refactor to use find_subrecords instead
    #       to reduce duplication
    if pyschema.ispyschema(a):
        if a == b:
            return True
        for _, field in a._fields.iteritems():
            if has_directed_link(field, b):
                return True
    elif isinstance(a, types.List):
        if has_directed_link(a.field_type, b):
            return True
    elif isinstance(a, types.Map):
        if has_directed_link(a.value_type, b):
            return True
    elif isinstance(a, types.SubRecord):
        if has_directed_link(a._schema, b):
            return True
    return False
示例#7
0
 def find_descendants(self, a, max_depth=sys.getrecursionlimit()):
     if a in self.descendants:
         # fetch from cache
         return self.descendants[a]
     self.started.add(a)
     subs = set()
     if max_depth > 0:
         if pyschema.ispyschema(a):
             for _, field in a._fields.iteritems():
                 subs |= self.find_descendants(field, max_depth)
             self.descendants[a] = subs
         elif isinstance(a, types.List):
             subs |= self.find_descendants(a.field_type, max_depth)
         elif isinstance(a, types.Map):
             subs |= self.find_descendants(a.value_type, max_depth)
         elif isinstance(a, types.SubRecord):
             subs.add(a._schema)
             if a._schema not in self.started:  # otherwise there is a circular reference
                 subs |= self.find_descendants(a._schema, max_depth-1)
         self.started.remove(a)
     return subs
示例#8
0
文件: tests.py 项目: freider/pyschema
 def test_type_adherence(self):
     self.assertTrue(ispyschema(self.Foo))
     self.assertTrue(issubclass(self.Foo, Record))
     self.assertTrue(isinstance(self.Foo, pyschema.core.PySchema))
示例#9
0
 def test_type_adherence(self):
     self.assertTrue(ispyschema(self.Foo))
     self.assertTrue(issubclass(self.Foo, Record))
     self.assertTrue(isinstance(self.Foo, pyschema.core.PySchema))