コード例 #1
0
class Supported(pyschema.Record):
    """We have doc"""
    _namespace = "com.spotify.pyschema.test"
    int_field = pyschema.Integer(nullable=False, size=4)
    float1 = pyschema.Float(nullable=False)
    required_string_field = pyschema.Text(nullable=False)
    long_field = pyschema.Integer(description="some number")
    optional_string_field = pyschema.Text(description="")
    undocumented_string_field = pyschema.Text()
    string_list = pyschema.List(pyschema.Text(nullable=False),
                                nullable=True,
                                default=None)
    string_map = pyschema.Map(pyschema.Text(nullable=False),
                              description="map of foo",
                              nullable=True,
                              default=None)
    bytes1 = pyschema.Bytes(description="bytes field 1")
    boolean1 = pyschema.Boolean(description="boolean field 1")
    another_string_field = pyschema.Text(description="What")
    boolean2 = pyschema.Boolean(description="boolean field 2")
    bytes2 = pyschema.Bytes(description="bytes field 2")
    weird_characters = pyschema.Integer(
        description=u"\';drop table schemas;--\u0100\u0101\x00\x00\n"
        u"http://uncyclopedia.wikia.com/wiki/AAAAAAAAA! "
        u"\\ \u043c\u043d\u043e\u0433\u0430\u0431\u0443"
        u"\u043a\u0430\u0444 <script>alert(\"eh\")</script>(:,%)\'")
    float2 = pyschema.Float(description="float field 2")
コード例 #2
0
class ParseThreeIncludingNullable(NoAutoRegister):
    schema_name = "FooRecord"
    avsc = """
{
  "type" : "record",
  "name" : "FooRecord",
  "fields" : [ {
    "name" : "field_a",
    "type" : [ "null", "string" ],
    "default" : null
  }, {
    "name" : "long_b",
    "type" : [ "null", "long" ],
    "default" : null
  }, {
    "name" : "required_c",
    "type" : "string"
  } ]
}"""

    references = [("field_a", pyschema.Text()), ("long_b", pyschema.Integer()),
                  ("required_c", pyschema.Text(nullable=False))]

    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_roundtrip(self):
        schema_class = avro_schema_parser.parse_schema_string(self.avsc)
        schema_struct = json.loads(self.avsc)
        regenerated_struct = avro.get_schema_dict(schema_class)
        self.assertEqual(schema_struct, regenerated_struct)
コード例 #3
0
 class Actual(pyschema.Record):
     target = pyschema.SubRecord(Target)
     piet = pyschema.Text()