Skip to content

Commit

Permalink
add function duplicatedColumnNames to address issue: hide traceback f…
Browse files Browse the repository at this point in the history
…rom users codeforsanjose#3; correct unit tests
  • Loading branch information
steveny2k committed Dec 31, 2016
1 parent 4ddd489 commit 594c13c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
12 changes: 9 additions & 3 deletions validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,20 @@ def validate_columns(input_file):
raise NoDataError("Data file contains fewer than 2 rows!")


def validate_columns_simple_output(input_file):
try:
validate_columns(input_file)
except Exception as e:
print e


if __name__ == '__main__':
if len(sys.argv) is 1:
print "no arguments privided; running the program against some sample CSV files"
validate_columns("test_files/valid.csv")
validate_columns("test_files/rowLengthMismatch.csv")
validate_columns("test_files/tooFewColumns.csv")
validate_columns_simple_output("test_files/valid.csv")
validate_columns_simple_output("test_files/rowLengthMismatch.csv")
validate_columns_simple_output("test_files/duplicatedColumnNames.csv")
validate_columns_simple_output("test_files/tooFewColumns.csv")
else:
for arg in sys.argv[1:]:
if os.path.isfile(arg):
Expand Down
9 changes: 5 additions & 4 deletions validator tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import unittest
import sys

from validate import validate_columns
from validate import validate_columns, validate_columns_simple_output, \
DuplicateColumnError, NoDataError, ColumnMismatchError

class TestCSVValidator(unittest.TestCase):

Expand All @@ -10,15 +11,15 @@ def test_empty_arg(self):
validate_columns('')

def test_row_lengths(self):
with self.assertRaises(ValueError):
with self.assertRaises(NoDataError):
validate_columns('test_files/tooFewColumns.csv')

def test_duplicated_column_names(self):
with self.assertRaises(ValueError):
with self.assertRaises(DuplicateColumnError):
validate_columns('test_files/duplicatedColumnNames.csv')

def test_row_length_mismatch(self):
with self.assertRaises(ValueError):
with self.assertRaises(ColumnMismatchError):
validate_columns('test_files/rowLengthMismatch.csv')

if __name__ == '__main__':
Expand Down

0 comments on commit 594c13c

Please sign in to comment.