-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added additional information to exceptions (#134) * Added additional information to exceptions * Updated implementation Co-authored-by: Adam Kariv <akariv@users.noreply.github.com> * Complete exceptions work on other dsp kinds * Fix tests Co-authored-by: roll <roll@users.noreply.github.com>
- Loading branch information
Showing
10 changed files
with
182 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.0.74 | ||
0.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from .base import DataStream, DataStreamProcessor, schema_validator, ValidationError | ||
from .base import ResourceWrapper, PackageWrapper | ||
from .base import exceptions | ||
from .base import Flow | ||
from .processors import * # noqa | ||
from .processors import * # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class DataflowsException(Exception): | ||
pass | ||
|
||
|
||
class ProcessorError(DataflowsException): | ||
|
||
def __init__(self, cause, *, processor_name, processor_object, processor_position): | ||
self.cause = cause | ||
self.processor_name = processor_name | ||
self.processor_object = processor_object | ||
self.processor_position = processor_position | ||
super().__init__(str(cause)) | ||
|
||
def __str__(self): | ||
return 'Errored in processor %s in position #%s: %s' % \ | ||
(self.processor_name, self.processor_position, self.cause) | ||
|
||
|
||
class SourceLoadError(DataflowsException): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,99 @@ | ||
import pytest | ||
|
||
def test_exception_in_generator(): | ||
from dataflows import Flow, printer | ||
|
||
class MyException(Exception): | ||
pass | ||
class MyException(Exception): | ||
pass | ||
|
||
|
||
def test_exception_in_generator(): | ||
from dataflows import Flow, printer, exceptions | ||
|
||
def generator(): | ||
for i in range(5): | ||
raise MyException() | ||
yield {"i": i} | ||
|
||
with pytest.raises(MyException): | ||
with pytest.raises(exceptions.ProcessorError) as excinfo: | ||
Flow(generator(), printer()).process() | ||
assert isinstance(excinfo.value.cause, MyException) | ||
|
||
|
||
def test_exception_information(): | ||
from dataflows import Flow, load, exceptions | ||
flow = Flow( | ||
load('data/bad-path1.csv'), | ||
) | ||
with pytest.raises(exceptions.ProcessorError) as excinfo: | ||
flow.results() | ||
assert str(excinfo.value.cause) == "Failed to load source 'data/bad-path1.csv' and options {'custom_parsers': {'xml': <class 'dataflows.processors.load.XMLParser'>}, 'ignore_blank_headers': True, 'headers': 1}: [Errno 2] No such file or directory: 'data/bad-path1.csv'" | ||
assert excinfo.value.processor_name == 'load' | ||
assert excinfo.value.processor_object.load_source == 'data/bad-path1.csv' | ||
assert excinfo.value.processor_position == 1 | ||
|
||
|
||
def test_exception_information_multiple_processors_simple(): | ||
from dataflows import Flow, load, exceptions | ||
flow = Flow( | ||
load('data/bad-path1.csv'), | ||
load('data/bad-path2.csv'), | ||
) | ||
with pytest.raises(exceptions.ProcessorError) as excinfo: | ||
flow.results() | ||
assert str(excinfo.value.cause) == "Failed to load source 'data/bad-path1.csv' and options {'custom_parsers': {'xml': <class 'dataflows.processors.load.XMLParser'>}, 'ignore_blank_headers': True, 'headers': 1}: [Errno 2] No such file or directory: 'data/bad-path1.csv'" | ||
assert excinfo.value.processor_name == 'load' | ||
assert excinfo.value.processor_object.load_source == 'data/bad-path1.csv' | ||
assert excinfo.value.processor_position == 1 | ||
|
||
|
||
def test_exception_information_multiple_processors_last_errored(): | ||
from dataflows import Flow, load, exceptions | ||
flow = Flow( | ||
load('data/academy.csv'), | ||
load('data/bad-path2.csv'), | ||
) | ||
with pytest.raises(exceptions.ProcessorError) as excinfo: | ||
flow.results() | ||
assert str(excinfo.value.cause) == "Failed to load source 'data/bad-path2.csv' and options {'custom_parsers': {'xml': <class 'dataflows.processors.load.XMLParser'>}, 'ignore_blank_headers': True, 'headers': 1}: [Errno 2] No such file or directory: 'data/bad-path2.csv'" | ||
assert excinfo.value.processor_name == 'load' | ||
assert excinfo.value.processor_object.load_source == 'data/bad-path2.csv' | ||
assert excinfo.value.processor_position == 2 | ||
|
||
|
||
def test_exception_information_multiple_processors_function_error(): | ||
from dataflows import Flow, load, exceptions | ||
|
||
def func(rows): | ||
for i, row in enumerate(rows): | ||
if i == 1: | ||
raise MyException('custom-error') | ||
yield row | ||
|
||
flow = Flow( | ||
load('data/academy.csv'), | ||
func | ||
) | ||
with pytest.raises(exceptions.ProcessorError) as excinfo: | ||
flow.results() | ||
assert str(excinfo.value.cause) == 'custom-error' | ||
assert excinfo.value.processor_name == 'rows_processor' | ||
assert excinfo.value.processor_position == 2 | ||
|
||
|
||
def test_exception_information_multiple_processors_iterable_error(): | ||
from dataflows import Flow, printer, exceptions | ||
|
||
def func(): | ||
for i in range(10): | ||
if i == 1: | ||
raise MyException('custom-iterable-error') | ||
yield dict(a=i) | ||
|
||
flow = Flow( | ||
func(), | ||
printer() | ||
) | ||
with pytest.raises(exceptions.ProcessorError) as excinfo: | ||
flow.results() | ||
assert str(excinfo.value.cause) == 'custom-iterable-error' | ||
assert excinfo.value.processor_name == 'iterable_loader' | ||
assert excinfo.value.processor_position == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.