# ================================================================================================ # These tests are more or less directly lifted from the java avro codebase # There's one test per Java file, so expect the first one to be a mammoth # ================================================================================================ BOOLEAN_SCHEMA = parse_json_ignore_trailing(json.dumps("boolean")) NULL_SCHEMA = parse_json_ignore_trailing(json.dumps("null")) INT_SCHEMA = parse_json_ignore_trailing(json.dumps("int")) LONG_SCHEMA = parse_json_ignore_trailing(json.dumps("long")) STRING_SCHEMA = parse_json_ignore_trailing(json.dumps("string")) BYTES_SCHEMA = parse_json_ignore_trailing(json.dumps("bytes")) FLOAT_SCHEMA = parse_json_ignore_trailing(json.dumps("float")) DOUBLE_SCHEMA = parse_json_ignore_trailing(json.dumps("double")) INT_ARRAY_SCHEMA = ArraySchema(INT_SCHEMA) LONG_ARRAY_SCHEMA = ArraySchema(LONG_SCHEMA) STRING_ARRAY_SCHEMA = ArraySchema(STRING_SCHEMA) INT_MAP_SCHEMA = MapSchema(INT_SCHEMA) LONG_MAP_SCHEMA = MapSchema(LONG_SCHEMA) STRING_MAP_SCHEMA = MapSchema(STRING_SCHEMA) ENUM1_AB_SCHEMA = parse_json_ignore_trailing( json.dumps({ "type": "enum", "name": "Enum1", "symbols": ["A", "B"] })) ENUM1_ABC_SCHEMA = parse_json_ignore_trailing( json.dumps({ "type": "enum", "name": "Enum1",
Names, PrimitiveSchema, Schema, UnionSchema, parse, ) BOOLEAN_SCHEMA = PrimitiveSchema(SchemaType.BOOLEAN) NULL_SCHEMA = PrimitiveSchema(SchemaType.NULL) INT_SCHEMA = PrimitiveSchema(SchemaType.INT) LONG_SCHEMA = PrimitiveSchema(SchemaType.LONG) STRING_SCHEMA = PrimitiveSchema(SchemaType.STRING) BYTES_SCHEMA = PrimitiveSchema(SchemaType.BYTES) FLOAT_SCHEMA = PrimitiveSchema(SchemaType.FLOAT) DOUBLE_SCHEMA = PrimitiveSchema(SchemaType.DOUBLE) INT_ARRAY_SCHEMA = ArraySchema(SchemaType.INT, names=Names()) LONG_ARRAY_SCHEMA = ArraySchema(SchemaType.LONG, names=Names()) STRING_ARRAY_SCHEMA = ArraySchema(SchemaType.STRING, names=Names()) INT_MAP_SCHEMA = MapSchema(SchemaType.INT, names=Names()) LONG_MAP_SCHEMA = MapSchema(SchemaType.LONG, names=Names()) STRING_MAP_SCHEMA = MapSchema(SchemaType.STRING, names=Names()) ENUM1_AB_SCHEMA = parse( json.dumps({ "type": SchemaType.ENUM, "name": "Enum1", "symbols": ["A", "B"] })) ENUM1_ABC_SCHEMA = parse( json.dumps({ "type": SchemaType.ENUM, "name": "Enum1",
import json import unittest from avro.compatibility import ReaderWriterCompatibilityChecker, SchemaCompatibilityType, SchemaType from avro.schema import ArraySchema, MapSchema, Names, PrimitiveSchema, Schema, UnionSchema, parse BOOLEAN_SCHEMA = PrimitiveSchema(SchemaType.BOOLEAN) NULL_SCHEMA = PrimitiveSchema(SchemaType.NULL) INT_SCHEMA = PrimitiveSchema(SchemaType.INT) LONG_SCHEMA = PrimitiveSchema(SchemaType.LONG) STRING_SCHEMA = PrimitiveSchema(SchemaType.STRING) BYTES_SCHEMA = PrimitiveSchema(SchemaType.BYTES) FLOAT_SCHEMA = PrimitiveSchema(SchemaType.FLOAT) DOUBLE_SCHEMA = PrimitiveSchema(SchemaType.DOUBLE) INT_ARRAY_SCHEMA = ArraySchema(SchemaType.INT, names=Names()) LONG_ARRAY_SCHEMA = ArraySchema(SchemaType.LONG, names=Names()) STRING_ARRAY_SCHEMA = ArraySchema(SchemaType.STRING, names=Names()) INT_MAP_SCHEMA = MapSchema(SchemaType.INT, names=Names()) LONG_MAP_SCHEMA = MapSchema(SchemaType.LONG, names=Names()) STRING_MAP_SCHEMA = MapSchema(SchemaType.STRING, names=Names()) ENUM1_AB_SCHEMA = parse(json.dumps({"type": SchemaType.ENUM, "name": "Enum1", "symbols": ["A", "B"]})) ENUM1_ABC_SCHEMA = parse(json.dumps({"type": SchemaType.ENUM, "name": "Enum1", "symbols": ["A", "B", "C"]})) ENUM1_BC_SCHEMA = parse(json.dumps({"type": SchemaType.ENUM, "name": "Enum1", "symbols": ["B", "C"]})) ENUM2_AB_SCHEMA = parse(json.dumps({"type": SchemaType.ENUM, "name": "Enum2", "symbols": ["A", "B"]})) ENUM_ABC_ENUM_DEFAULT_A_SCHEMA = parse( json.dumps({ "type": "enum", "name": "Enum", "symbols": ["A", "B", "C"], "default": "A"