def test_parsable(self):
     src = to_python_source(self.schema_classes)
     assertion_footer = "\n".join("assert {0}".format(schema._schema_name) for schema in self.schema_classes)
     try:
         call_python(src + "\n" + assertion_footer)
     except NonZeroExit as e:
         self.fail("Problem when parsing:\n\n{0}\n\n{1}".format(src, e.message))
 def test_parsable(self):
     src = to_python_source(self.schema_classes)
     assertion_footer = "\n".join("assert {0}".format(schema._schema_name)
                                  for schema in self.schema_classes)
     try:
         call_python(src + '\n' + assertion_footer)
     except NonZeroExit as e:
         self.fail("Problem when parsing:\n\n{0}\n\n{1}".format(
             src, e.message))
 def test_name_is_preserved(self):
     self.assertIn("name='MyEnum'", to_python_source(self.schema_classes))
Example #4
0
def to_python_source(s):
    """Return a Python syntax declaration of the schemas contained in `s`"""
    schema = parse_schema_string(s)
    return source_generation.to_python_source([schema])
Example #5
0
def to_python_source(s):
    """Return a Python syntax declaration of the schemas contained in `s`"""
    schema = parse_schema_string(s)
    return source_generation.to_python_source([schema])
 def test_name_is_preserved(self):
     self.assertIn("name='MyEnum'", to_python_source(self.schema_classes))
Example #7
0
        return build_and_add_to_enum_store

    COMPLEX_MAPPING = {
        "map": _parse_map,
        "record": _parse_subrecord,
        "array": _parse_array,
        "enum": _parse_enum
    }

    def _parse_complex(self, type_def_struct, enclosing_namespace):
        typename = type_def_struct["type"]
        parser_func = self.COMPLEX_MAPPING.get(typename)
        if parser_func:
            return parser_func(self, type_def_struct, enclosing_namespace)
        elif typename in SIMPLE_FIELD_MAP:
            # hack to support the weird case where you double wrap a simple type
            return SIMPLE_FIELD_MAP[typename]
        raise AVSCParseException("Unknown complex type: {0}".format(type_def_struct))


def to_python_source(s):
    """Return a Python syntax declaration of the schemas contained in `s`"""
    schema = parse_schema_string(s)
    return source_generation.to_python_source([schema])

if __name__ == "__main__":
    utf8_stdin = codecs.getreader("utf8")(sys.stdin)
    schema_struct = json.load(utf8_stdin)
    schema = AvroSchemaParser().parse_schema_struct(schema_struct)
    print source_generation.to_python_source([schema])