Skip to content

Commit

Permalink
DictWriter.writeheader should defer to the underlying writer
Browse files Browse the repository at this point in the history
d27d182 sought to DRY .writeheaders a bit, but introduced a bug.
No diff is too simple for a test, apparently.
  • Loading branch information
jdunck committed Apr 13, 2015
1 parent cccf4c8 commit 972e35d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 2 additions & 3 deletions unicodecsv/__init__.py
Expand Up @@ -6,7 +6,7 @@
izip = zip

#http://semver.org/
VERSION = (0, 11, 1)
VERSION = (0, 11, 2)
__version__ = ".".join(map(str,VERSION))

pass_throughs = [
Expand Down Expand Up @@ -154,8 +154,7 @@ def __init__(self, csvfile, fieldnames, restval='', extrasaction='raise', dialec
self.encoding_errors = errors

def writeheader(self):
fieldnames = _stringify_list(self.fieldnames, self.encoding, self.encoding_errors)
header = dict(zip(fieldnames, fieldnames))
header = dict(zip(self.fieldnames, self.fieldnames))
self.writerow(header)

class DictReader(csv.DictReader):
Expand Down
12 changes: 12 additions & 0 deletions unicodecsv/test.py
Expand Up @@ -599,6 +599,18 @@ def test_write_simple_dict(self):
fileobj.close()
os.unlink(name)

def test_write_unicode_header_dict(self):
fd, name = tempfile.mkstemp()
fileobj = open(name, 'w+b')
try:
writer = csv.DictWriter(fileobj, fieldnames = [u"ñ", u"ö"])
writer.writeheader()
fileobj.seek(0)
self.assertEqual(fileobj.readline().decode('utf-8'), u"ñ,ö\r\n")
finally:
fileobj.close()
os.unlink(name)

def test_write_no_fields(self):
fileobj = StringIO()
self.assertRaises(TypeError, csv.DictWriter, fileobj)
Expand Down

0 comments on commit 972e35d

Please sign in to comment.