Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/fastavro/_validate_common.py: 50%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

12 statements  

1from collections import namedtuple 

2import json 

3 

4 

5class ValidationErrorData( 

6 namedtuple("ValidationErrorData", ["datum", "schema", "field"]) 

7): 

8 def __str__(self): 

9 if self.datum is None: 

10 return f"Field({self.field}) is None expected {self.schema}" 

11 

12 return ( 

13 f"{self.field} is <{self.datum}> of type " 

14 + f"{type(self.datum)} expected {self.schema}" 

15 ) 

16 

17 

18class ValidationError(Exception): 

19 def __init__(self, *errors): 

20 message = json.dumps([str(e) for e in errors], indent=2, ensure_ascii=False) 

21 super().__init__(message) 

22 self.errors = errors