Permalink
Browse files

Fix serialization bug in CSVKitDictWriter. Closes #182.

  • Loading branch information...
1 parent c2f3894 commit b68fecf1024d09182d2d4280d2c82d5531f7dcf1 @onyxfish onyxfish committed Aug 17, 2012
Showing with 16 additions and 16 deletions.
  1. +1 −1 csvkit/__init__.py
  2. +15 −15 tests/test_utilities/test_csvclean.py
View
2 csvkit/__init__.py
@@ -74,7 +74,7 @@ def writerow(self, row):
self._append_line_number(row)
# 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)
View
30 tests/test_utilities/test_csvclean.py
@@ -18,21 +18,21 @@ def test_simple(self):
self.assertTrue(os.path.exists('examples/bad_err.csv'))
self.assertTrue(os.path.exists('examples/bad_out.csv'))
- with open('examples/bad_err.csv') as f:
- f.next()
- self.assertEqual(f.next()[0], '1')
- self.assertEqual(f.next()[0], '2')
- self.assertRaises(StopIteration, f.next)
-
- with open('examples/bad_out.csv') as f:
- f.next()
- self.assertEqual(f.next()[0], '0')
- self.assertRaises(StopIteration, f.next)
-
- # Cleanup
- os.remove('examples/bad_err.csv')
- os.remove('examples/bad_out.csv')
- sleep(0.1)
+ try:
+ with open('examples/bad_err.csv') as f:
+ f.next()
+ self.assertEqual(f.next()[0], '1')
+ self.assertEqual(f.next()[0], '2')
+ self.assertRaises(StopIteration, f.next)
+
+ with open('examples/bad_out.csv') as f:
+ f.next()
+ self.assertEqual(f.next()[0], '0')
+ self.assertRaises(StopIteration, f.next)
+ finally:
+ # Cleanup
+ os.remove('examples/bad_err.csv')
+ os.remove('examples/bad_out.csv')
def test_dry_run(self):
args = ['-n', 'examples/bad.csv']

0 comments on commit b68fecf

Please sign in to comment.