Skip to content

Commit

Permalink
csvlook respects --no-header-row
Browse files Browse the repository at this point in the history
  • Loading branch information
James McKinney committed Sep 5, 2012
1 parent 9cbcd32 commit 0805968
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion csvkit/utilities/csvlook.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def main(self):

self.output_file.write(('| %s |\n' % ('|'.join(output))).encode('utf-8'))

if i == 0 or i == len(rows) - 1:
if (i == 0 and not self.args.no_header_row) or i == len(rows) - 1:
self.output_file.write('%s\n' % divider)

def launch_new_instance():
Expand Down
2 changes: 2 additions & 0 deletions examples/no_header_row3.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1,2,3
4,5,6
14 changes: 14 additions & 0 deletions tests/test_utilities/test_csvlook.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,17 @@ def test_simple(self):
self.assertEqual(input_file.next(), '| 1 | 4 | 5 |\n')
self.assertEqual(input_file.next(), '|----+---+----|\n')

def test_no_header(self):
args = ['--no-header-row', 'examples/no_header_row3.csv']
output_file = StringIO.StringIO()
utility = CSVLook(args, output_file)

utility.main()

input_file = StringIO.StringIO(output_file.getvalue())

self.assertEqual(input_file.next(), '|----+---+----|\n')
self.assertEqual(input_file.next(), '| 1 | 2 | 3 |\n')
self.assertEqual(input_file.next(), '| 4 | 5 | 6 |\n')
self.assertEqual(input_file.next(), '|----+---+----|\n')

0 comments on commit 0805968

Please sign in to comment.