Skip to content

Commit

Permalink
Minor tweaks to exception handling for 'tse_fileio.py'. Refs: #91
Browse files Browse the repository at this point in the history
  • Loading branch information
cgddrd committed Apr 3, 2015
1 parent f9a324e commit 3d6cc80
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,11 @@ def test_read_file_no_delimiter(self):
expected_result = ['1', '2', '3']

assert_equal(self.test_fileio.read_file("./data/test_file.txt", None, 0), expected_result)

def test_read_file_invalid_file(self):

with assert_raises(IOError) as e:
self.test_fileio.read_file("./data/invalid_file.txt", None, 0)

assert_equal(e.exception.message, 'File not found: ./data/invalid_file.txt')

9 changes: 7 additions & 2 deletions src/template_matching_scaling/tse/tse_fileio.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import errno

__author__ = 'connorgoddard'

Expand Down Expand Up @@ -45,8 +46,12 @@ def read_file(file_path, split_delimiter=None, start_position=0):

file_results.append(line.rstrip())

except IOError:
print "Error: Unable to open file or read data({0})".format(file_path)
except IOError as e:

if e.errno == errno.ENOENT:
raise IOError("File not found: {0}".format(file_path))

print "Error: Unable to read data - {0}".format(file_path)

return file_results

Expand Down

0 comments on commit 3d6cc80

Please sign in to comment.