Created by: dannguyen
csvformat's test_no_header_row() test seems to be incomplete/non-functional, e.g. it omits the default headers from the expected results:
def test_no_header_row(self):
self.assertLines(['--no-header-row', 'examples/no_header_row.csv'], [
'1,2,3',
])
I changed the test to this:
def test_no_header_row(self):
self.assertLines(['--no-header-row', 'examples/no_header_row.csv'], [
'a,b,c',
'1,2,3',
])
And in csvformat.py, I copied the relevant snippet from cli.py:get_rows_and_column_names_and_column_ids() for generating default headers:
reader = agate.csv.reader(self.skip_lines(), **self.reader_kwargs)
writer = agate.csv.writer(self.output_file, **self.writer_kwargs)
# new-code
if self.args.no_header_row:
# Peek at a row to get the number of columns.
_row = next(reader)
reader = itertools.chain([_row], reader)
headers = make_default_headers(len(_row))
writer.writerow(headers)
# /new-code
writer.writerows(reader)