Skip to content

Commit

Permalink
Stop excel error handling from interfering with HTTP errors. (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgiana-b authored and pwalsh committed May 1, 2016
1 parent 795cf76 commit b8e9f9c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
17 changes: 11 additions & 6 deletions goodtables/datatable/datatable.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,19 @@ def excel_data_source(self, data_source):

instream = None

try:
if compat.urlparse(data_source).scheme in self.REMOTE_SCHEMES:
instream = self._stream_from_url(data_source).read()
except Exception:
if compat.urlparse(data_source).scheme in self.REMOTE_SCHEMES:
instream = self._stream_from_url(data_source).read()
else:
try:
data_source.seek(0)
instream = data_source.read()
except Exception:
pass
except AttributeError:
if os.path.exists(data_source):
pass
else:
msg = 'data source has to be a stream or a path to be processed as excel'
raise exceptions.DataSourceMalformatedError(msg, file_format='excel')

try:
if instream:
workbook = xlrd.open_workbook(file_contents=instream)
Expand Down
8 changes: 6 additions & 2 deletions tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ def test_report_summary_incorrect_type(self):

self.assertEqual(out, 33)

def test_pipeline_error_report_when_data_http_error(self):
def test_pipeline_error_report_when_data_http_error(self, format='csv'):

data_source = 'https://github.com/frictionlessdata/goodtables/blob/master/.travis.yaml'
validator = Pipeline(data_source, fail_fast=True)
validator = Pipeline(data_source, format=format, fail_fast=True)
result, report = validator.run()
generated_report = report.generate()
report_results = generated_report['results']
Expand All @@ -233,6 +233,9 @@ def test_pipeline_error_report_when_data_http_error(self):
self.assertEqual(len(report_results), 1)
self.assertEqual(report_results[0]['result_id'], 'http_404_error')

def test_excel_pipeline_error_report_when_data_http_error(self):
self.test_pipeline_error_report_when_data_http_error(format='excel')

def test_pipeline_group_error_report_when_http_error(self):

data_source = 'https://github.com/frictionlessdata/goodtables/blob/master/.travis.yaml'
Expand Down Expand Up @@ -320,3 +323,4 @@ def test_encoding_present_on_report_meta(self):
pipeline = Pipeline(self.data_string)
pipeline.set_report_meta()
self.assertEqual(pipeline.report.generate()['meta']['encoding'], 'utf-8')

0 comments on commit b8e9f9c

Please sign in to comment.