Skip to content

Commit

Permalink
Fix serialization bug in CSVKitDictWriter. Closes #182.
Browse files Browse the repository at this point in the history
  • Loading branch information
onyxfish committed Aug 17, 2012
1 parent c2f3894 commit b68fecf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion csvkit/__init__.py
Expand Up @@ -74,7 +74,7 @@ def writerow(self, row):
self._append_line_number(row) self._append_line_number(row)


# Convert embedded Mac line endings to unix style line endings so they get quoted # Convert embedded Mac line endings to unix style line endings so they get quoted
row = dict([(k, v.replace('\r', '\n')) if isinstance(v, basestring) else v for k, v in row.items()]) row = dict([(k, v.replace('\r', '\n')) if isinstance(v, basestring) else (k, v) for k, v in row.items()])


unicsv.UnicodeCSVDictWriter.writerow(self, row) unicsv.UnicodeCSVDictWriter.writerow(self, row)


Expand Down
30 changes: 15 additions & 15 deletions tests/test_utilities/test_csvclean.py
Expand Up @@ -18,21 +18,21 @@ def test_simple(self):
self.assertTrue(os.path.exists('examples/bad_err.csv')) self.assertTrue(os.path.exists('examples/bad_err.csv'))
self.assertTrue(os.path.exists('examples/bad_out.csv')) self.assertTrue(os.path.exists('examples/bad_out.csv'))


with open('examples/bad_err.csv') as f: try:
f.next() with open('examples/bad_err.csv') as f:
self.assertEqual(f.next()[0], '1') f.next()
self.assertEqual(f.next()[0], '2') self.assertEqual(f.next()[0], '1')
self.assertRaises(StopIteration, f.next) self.assertEqual(f.next()[0], '2')

self.assertRaises(StopIteration, f.next)
with open('examples/bad_out.csv') as f:
f.next() with open('examples/bad_out.csv') as f:
self.assertEqual(f.next()[0], '0') f.next()
self.assertRaises(StopIteration, f.next) self.assertEqual(f.next()[0], '0')

self.assertRaises(StopIteration, f.next)
# Cleanup finally:
os.remove('examples/bad_err.csv') # Cleanup
os.remove('examples/bad_out.csv') os.remove('examples/bad_err.csv')
sleep(0.1) os.remove('examples/bad_out.csv')


def test_dry_run(self): def test_dry_run(self):
args = ['-n', 'examples/bad.csv'] args = ['-n', 'examples/bad.csv']
Expand Down

0 comments on commit b68fecf

Please sign in to comment.