Skip to content

Commit

Permalink
Merge pull request #435 from fitnr/master
Browse files Browse the repository at this point in the history
fixed AttributeError with -n argument for utils with -H suppressed
  • Loading branch information
James McKinney committed Jan 22, 2016
2 parents 0ae1294 + f9706a7 commit 347bf33
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion csvkit/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def print_column_names(self):
"""
Pretty-prints the names and indices of all columns to a file-like object (usually sys.stdout).
"""
if self.args.no_header_row:
if getattr(self.args, 'no_header_row', None):
raise RequiredHeaderError('You cannot use --no-header-row with the -n or --names options.')

f = self.input_file
Expand Down
13 changes: 13 additions & 0 deletions tests/test_utilities/test_csvgrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,16 @@ def test_invalid_column(self):
utility = CSVGrep(args, output_file)

self.assertRaises(ColumnIdentifierError, utility.main)

def test_display_column_names(self):
args = ['-n', 'examples/realdata/FY09_EDU_Recipients_by_State.csv']
output_file = six.StringIO()

utility = CSVGrep(args, output_file)
utility.main()

input_file = six.StringIO(output_file.getvalue())
reader = CSVKitReader(input_file)

self.assertEqual(next(reader), [' 1: State Name'])
self.assertEqual(next(reader), [' 2: State Abbreviate'])

0 comments on commit 347bf33

Please sign in to comment.