Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/fastavro/repository/flat_dict.py: 38%

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

16 statements  

1import json 

2from os import path 

3 

4from .base import AbstractSchemaRepository, SchemaRepositoryError 

5 

6 

7class FlatDictRepository(AbstractSchemaRepository): 

8 def __init__(self, path): 

9 self.path = path 

10 self.file_ext = "avsc" 

11 

12 def load(self, name): 

13 file_path = path.join(self.path, f"{name}.{self.file_ext}") 

14 try: 

15 with open(file_path) as schema_file: 

16 return json.load(schema_file) 

17 except IOError as error: 

18 raise SchemaRepositoryError( 

19 f"Failed to load '{name}' schema", 

20 ) from error 

21 except json.decoder.JSONDecodeError as error: 

22 raise SchemaRepositoryError( 

23 f"Failed to parse '{name}' schema", 

24 ) from error