コード例 #1
0
 def setUp(self):
     self.codec = AvroCodec(AVRO_SCHEMA)
コード例 #2
0
class AvroCodecTest(TestCase):

    def setUp(self):
        self.codec = AvroCodec(AVRO_SCHEMA)

    def test_dump(self):
        with byte_buffer() as out:
            self.codec.dump(VALID_OBJ, out)
            self.assertEquals(VALID_OBJ_ENCODED, out.getvalue())

    def test_dump_violates_schema(self):
        with self.assertRaises(AvroTypeException):
            with byte_buffer() as out:
                self.codec.dump(INVALID_OBJ, out)

    def test_dumps(self):
        self.assertEquals(VALID_OBJ_ENCODED, self.codec.dumps(VALID_OBJ))

    def test_dumps_violates_schema(self):
        with self.assertRaises(AvroTypeException):
            self.codec.dumps(INVALID_OBJ)

    def test_load(self):
        with byte_buffer(VALID_OBJ_ENCODED) as readable:
            self.assertEquals(VALID_OBJ, self.codec.load(readable))

    def test_load_bullshit_data(self):
        with self.assertRaises(TypeError):
            with byte_buffer(BULLSHIT_DATA) as readable:
                self.codec.load(readable)

    def test_load_valid_data_wrong_schema(self):
        with self.assertRaises(IndexError):
            with byte_buffer(OTHER_OBJ_ENCODED) as readable:
                self.codec.load(readable)

    def test_loads(self):
        self.assertEquals(VALID_OBJ, self.codec.loads(VALID_OBJ_ENCODED))

    def test_loads_bullshit_data(self):
        with self.assertRaises(TypeError):
            self.codec.loads(BULLSHIT_DATA)

    def test_loads_valid_data_wrong_schema(self):
        with self.assertRaises(IndexError):
            self.codec.loads(OTHER_OBJ_ENCODED)