Skip to content
This repository has been archived by the owner on Dec 27, 2020. It is now read-only.

Commit

Permalink
Merge pull request #4 from steveny2k/master
Browse files Browse the repository at this point in the history
resolve "hide traceback from users #3"; correct unit tests; add test cases
  • Loading branch information
Kyle-Falconer authored Jan 13, 2017
2 parents 3dbfcaa + 594c13c commit 318ed1d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.pyc
*.pyc
.idea/
1 change: 1 addition & 0 deletions test_files/duplicatedColumnNames.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Column 1,Column 2,Column 2,Column 4,Column 5a,b,c,d,ea,b,c,d,e
Expand Down
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
12 changes: 10 additions & 2 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,9 +11,16 @@ 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(DuplicateColumnError):
validate_columns('test_files/duplicatedColumnNames.csv')

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

if __name__ == '__main__':
unittest.main()

0 comments on commit 318ed1d

Please sign in to comment.