Fix ValidationErrorData
fix the field to empty string issue in ValidationErrorData.__str__
also add a new unit test
MODIFY
fastavro/_validate_common.py
fastavro/_validate_common.py
@@ -5,17 +5,19 @@ import json
class ValidationErrorData(namedtuple('ValidationErrorData',
['datum', 'schema', 'field'])):
def __str__(self):
- if self.field is None:
- self.field = ''
+ # update field for prettier printing
+ field = self.field
+ if field is None:
+ field = ''
if self.datum is None:
return 'Field({field}) is None' \
- ' expected {schema}'.format(field=self.field,
+ ' expected {schema}'.format(field=field,
schema=self.schema)
return '{field} is <{datum}> of type ' \
'{given_type} expected {schema}'. \
format(datum=self.datum, given_type=type(self.datum),
- schema=self.schema, field=self.field)
+ schema=self.schema, field=field)
class ValidationError(Exception):

MODIFY
tests/test_validation.py
tests/test_validation.py
@@ -204,6 +204,12 @@ def test_validate_error_raises():
assert msg in str(error)
+def test_validate_error_none_field():
+ error = ValidationErrorData(10, "string", None)
+ msg = " is <10> of type <{} 'int'> expected string".format(type_type)
+ assert msg in str(error)
+
+
def test_validator_numeric():
for datum, schema in [
(1, 'int'),

Fix ValidationErrorData

#210 fix the field to empty string issue in ValidationErrorData.__str__
also add a new unit test