diff --git a/magicparse/schema.py b/magicparse/schema.py index 84017fc..10b9980 100644 --- a/magicparse/schema.py +++ b/magicparse/schema.py @@ -44,20 +44,21 @@ def register(cls, schema: "Schema") -> None: cls.registry[schema.key()] = schema - def parse(self, data: Union[bytes, BytesIO]) -> Tuple[List[dict], List[dict]]: items = [] errors = [] for item, row_errors in self.stream_parse(data): - if(row_errors): + if row_errors: errors.extend(row_errors) else: items.append(item) return items, errors - def stream_parse(self, data: Union[bytes, BytesIO]) -> Iterable[Tuple[dict, list[dict]]]: + def stream_parse( + self, data: Union[bytes, BytesIO] + ) -> Iterable[Tuple[dict, list[dict]]]: if isinstance(data, bytes): stream = BytesIO(data) else: @@ -96,6 +97,7 @@ def stream_parse(self, data: Union[bytes, BytesIO]) -> Iterable[Tuple[dict, list yield item, errors + class CsvSchema(Schema): def __init__(self, options: Dict[str, Any]) -> None: super().__init__(options) diff --git a/tests/test_schema.py b/tests/test_schema.py index 909d21a..ecfae8d 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -6,6 +6,7 @@ import pytest from unittest import TestCase + class TestBuild(TestCase): def test_default_csv_schema(self): schema = Schema.build( @@ -288,8 +289,8 @@ def test_register(self): ) assert isinstance(schema, self.PipedSchema) -class TestSteamParse(TestCase): +class TestSteamParse(TestCase): def test_stream_parse_errors_do_not_halt_parsing(self): schema = Schema.build( { @@ -299,12 +300,17 @@ def test_stream_parse_errors_do_not_halt_parsing(self): ) rows = list(schema.stream_parse(b"1\na\n2")) assert rows == [ - ({"age": 1}, []), - ({}, [{ - "row-number": 2, - "column-number": 1, - "field-key": "age", - "error": "value 'a' is not a valid integer", - }]), - ({"age": 2}, []) - ] \ No newline at end of file + ({"age": 1}, []), + ( + {}, + [ + { + "row-number": 2, + "column-number": 1, + "field-key": "age", + "error": "value 'a' is not a valid integer", + } + ], + ), + ({"age": 2}, []), + ]