Skip to content

Commit d8b15f7

Browse files
committed
use wb on output
1 parent 58df6bb commit d8b15f7

3 files changed

Lines changed: 9 additions & 19 deletions

File tree

jsoncsv/jsontool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,5 @@ def gen_objs_from_array():
163163
fout.write(content.encode('utf-8'))
164164
fout.write('\n'.encode('utf-8'))
165165
else:
166-
fout.write(content)
167-
fout.write('\n')
166+
fout.write(content.encode('utf-8'))
167+
fout.write(str('\n').encode('utf-8'))

jsoncsv/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def separator_type(sep):
5353
default='-')
5454
@click.argument(
5555
'output',
56-
type=click.File('w'),
56+
type=click.File('wb'),
5757
default='-')
5858
def jsoncsv(output, input, expand, restore, safe, separator, json_array):
5959
if expand and restore:

tests/test_jsontool.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import io
77
import unittest
88

9-
from jsoncsv import PY2
109
from jsoncsv.jsontool import expand, restore
1110
from jsoncsv.jsontool import is_array_index
1211
from jsoncsv.jsontool import convert_json
@@ -106,42 +105,33 @@ class TestConvertJSON(unittest.TestCase):
106105

107106
def test_convert_expand(self):
108107
fin = io.StringIO('{"a":{"b":3}}\n{"a":{"c":4}}\n')
109-
if PY2:
110-
fout = io.BytesIO()
111-
else:
112-
fout = io.StringIO()
108+
fout = io.BytesIO()
113109

114110
convert_json(fin, fout, expand)
115111

116-
self.assertEqual('{"a.b": 3}\n{"a.c": 4}\n', fout.getvalue())
112+
self.assertEqual(b'{"a.b": 3}\n{"a.c": 4}\n', fout.getvalue())
117113

118114
fin.close()
119115
fout.close()
120116

121117
def test_convert_restore(self):
122118
fin = io.StringIO('{"a.b": 3}\n{"a.c": 4}\n')
123-
if PY2:
124-
fout = io.BytesIO()
125-
else:
126-
fout = io.StringIO()
119+
fout = io.BytesIO()
127120

128121
convert_json(fin, fout, restore)
129122

130-
self.assertEqual('{"a": {"b": 3}}\n{"a": {"c": 4}}\n', fout.getvalue())
123+
self.assertEqual(b'{"a": {"b": 3}}\n{"a": {"c": 4}}\n', fout.getvalue())
131124

132125
fin.close()
133126
fout.close()
134127

135128
def test_convert_expand_json_array(self):
136129
fin = io.StringIO('[{"a":{"b":3}},{"a":{"c":4}}]')
137-
if PY2:
138-
fout = io.BytesIO()
139-
else:
140-
fout = io.StringIO()
130+
fout = io.BytesIO()
141131

142132
convert_json(fin, fout, expand, json_array=True)
143133

144-
self.assertEqual('{"a.b": 3}\n{"a.c": 4}\n', fout.getvalue())
134+
self.assertEqual(b'{"a.b": 3}\n{"a.c": 4}\n', fout.getvalue())
145135

146136
fin.close()
147137
fout.close()

0 commit comments

Comments
 (0)