You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by GitBox <gi...@apache.org> on 2021/04/07 22:11:54 UTC

[GitHub] [avro] subhashb commented on a change in pull request #1156: AVRO-2720: Enhance AvroTypeException message to include field name

subhashb commented on a change in pull request #1156:
URL: https://github.com/apache/avro/pull/1156#discussion_r609103608



##########
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:
       Changed in https://github.com/apache/avro/pull/1156/commits/5d34e2c380df85a0d43894f46c1ea01ee2305c1d




-- 
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:
users@infra.apache.org