Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akariv committed May 26, 2020
1 parent cc104c8 commit e666ade
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 31 deletions.
1 change: 1 addition & 0 deletions tests/test_edge_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def func(rows):
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

Expand Down
22 changes: 8 additions & 14 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

def test_example_1():
from dataflows import Flow

Expand All @@ -16,8 +18,6 @@ def lowerData(row):
)
data, *_ = f.results()

print(data)

# [[{'data': 'hello'}, {'data': 'world'}]]


Expand All @@ -33,8 +33,6 @@ def titleName(row):
)
data, *_ = f.results()

print(data)


def country_population():
from xml.etree import ElementTree
Expand Down Expand Up @@ -63,8 +61,6 @@ def test_example_3():
)
data, *_ = f.results()

print(data)

def test_example_4():
from dataflows import Flow, set_type

Expand All @@ -74,8 +70,6 @@ def test_example_4():
)
data, dp, _ = f.results()

print(data[0][:10])

def test_example_5():
from dataflows import Flow, set_type, dump_to_path

Expand Down Expand Up @@ -112,8 +106,9 @@ def filter_pythagorean_triplets(rows):
)
_ = f.process()


def test_validate():
from dataflows import Flow, validate, set_type, printer, ValidationError
from dataflows import Flow, validate, set_type, printer, ValidationError, exceptions

def adder(row):
row['a'] += 0.5
Expand All @@ -127,11 +122,10 @@ def adder(row):
validate(),
printer()
)
try:
_ = f.process()
assert False
except ValidationError:
pass

with pytest.raises(exceptions.ProcessorError) as excinfo:
f.process()
assert isinstance(excinfo.value.cause, ValidationError)


def test_example_7():
Expand Down
30 changes: 13 additions & 17 deletions tests/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ def test_set_type_resources():


def test_set_type_errors():
from dataflows import Flow, set_type, ValidationError
from dataflows import Flow, set_type, ValidationError, exceptions
from dataflows.base.schema_validator import ignore, drop, raise_exception

data = [
Expand Down Expand Up @@ -863,21 +863,18 @@ def test_set_type_errors():
data,
set_type('b', type='integer', on_error=raise_exception),
)
try:

with pytest.raises(exceptions.ProcessorError) as excinfo:
results, *_ = f.results()
assert False
except ValidationError:
pass
assert isinstance(excinfo.value.cause, ValidationError)

f = Flow(
data,
set_type('b', type='integer'),
)
try:
with pytest.raises(exceptions.ProcessorError) as excinfo:
results, *_ = f.results()
assert False
except ValidationError:
pass
assert isinstance(excinfo.value.cause, ValidationError)


def test_dump_to_path_use_titles():
Expand All @@ -899,7 +896,7 @@ def test_dump_to_path_use_titles():

def test_load_dates():
# from dateutil.tz import tzutc
from dataflows import Flow, dump_to_path, load, set_type, ValidationError
from dataflows import Flow, dump_to_path, load, set_type, ValidationError, exceptions
import datetime

_today = datetime.date.today()
Expand All @@ -913,11 +910,9 @@ def run_flow(datetime_format=None):
dump_to_path('out/dump_dates')
).process()

try:
with pytest.raises(exceptions.ProcessorError) as excinfo:
run_flow()
assert False
except ValidationError:
assert True
assert isinstance(excinfo.value.cause, ValidationError)

# Default is isoformat(), str() gives a slightly different format:
# >>> from datetime import datetime
Expand Down Expand Up @@ -1521,13 +1516,14 @@ def test_join_row_number_format_string():


def test_load_duplicate_headers():
from dataflows import load
from dataflows import load, exceptions
flow = Flow(
load('data/duplicate_headers.csv'),
)
with pytest.raises(ValueError) as excinfo:
with pytest.raises(exceptions.ProcessorError) as excinfo:
flow.results()
assert 'duplicate headers' in str(excinfo.value)
cause = excinfo.value.cause
assert 'duplicate headers' in str(cause)


def test_load_duplicate_headers_with_deduplicate_headers_flag():
Expand Down

0 comments on commit e666ade

Please sign in to comment.