kojiromike commented on a change in pull request #1156:
URL: https://github.com/apache/avro/pull/1156#discussion_r608736873
##########
File path: lang/py/avro/test/test_io.py
##########
@@ -390,14 +391,39 @@ def test_field_order(self):
print('Datum Read: %s' % datum_read)
self.assertEqual(datum_to_read, datum_read)
- def test_type_exception(self):
+ def test_type_exception_int(self):
print_test_name('TEST TYPE EXCEPTION')
- writers_schema = avro.schema.parse("""\
- {"type": "record", "name": "Test",
- "fields": [{"name": "F", "type": "int"},
- {"name": "E", "type": "int"}]}""")
+ writers_schema = avro.schema.parse(json.dumps({
+ "type": "record", "name": "Test",
+ "fields": [
+ {"name": "F", "type": "int"},
+ {"name": "E", "type": "int"}]}))
datum_to_write = {'E': 5, 'F': 'Bad'}
- self.assertRaises(avro.errors.AvroTypeException, write_datum,
datum_to_write, writers_schema)
+ with self.assertRaises(avro.errors.AvroTypeException) as exc:
+ write_datum(datum_to_write, writers_schema)
+ assert str(exc.exception) == 'The datum "Bad" provided for "F" is not
an example of the schema "int"'
+
+ def test_type_exception_long(self):
+ writers_schema = avro.schema.parse(json.dumps({
+ "type": "record", "name": "Test",
+ "fields": [
+ {"name": "foo", "type": "long"}]}))
+ datum_to_write = {'foo': 5.0}
+ with self.assertRaises(avro.errors.AvroTypeException) as exc:
+ write_datum(datum_to_write, writers_schema)
+ assert str(exc.exception) == 'The datum "5.0" provided for "foo" is
not an example of the schema "long"'
+
+ def test_type_exception_record(self):
+ writers_schema = avro.schema.parse(json.dumps({
+ "type": "record", "name": "Test",
+ "fields": [
+ {"name": "foo", "type": "long"}]}))
+ datum_to_write = ('foo', 5.0)
+ pretty_expected = json.dumps(json.loads(str(writers_schema)), indent=2)
+ with self.assertRaises(avro.errors.AvroTypeException) as exc:
+ write_datum(datum_to_write, writers_schema)
+ assert str(exc.exception) == \
Review comment:
Consider `assertRaisesRegex` to test the message.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]