Skip to content

Commit fac53c0

Browse files
committed
add encoding fixture
1 parent 826aa2c commit fac53c0

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

pandas/tests/series/test_io.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from pandas import Series, DataFrame
1212

13-
from pandas.compat import StringIO, u
13+
from pandas.compat import StringIO, u, PY2
1414
from pandas.util.testing import (assert_series_equal, assert_almost_equal,
1515
assert_frame_equal, ensure_clean)
1616
import pandas.util.testing as tm
@@ -137,29 +137,35 @@ def test_to_csv_path_is_none(self):
137137
csv_str = s.to_csv(path=None)
138138
assert isinstance(csv_str, str)
139139

140-
def test_to_csv_compression(self, compression):
141-
142-
s = Series([0.123456, 0.234567, 0.567567], index=['A', 'B', 'C'],
143-
name='X')
140+
@pytest.mark.parametrize('s, encoding', [
141+
(Series([0.123456, 0.234567, 0.567567], index=['A', 'B', 'C'],
142+
name='X'), 'utf-8'),
143+
(Series(['abc', 'def', 'ghi'], name='X'), 'ascii'),
144+
(Series(["123", u"你好", u"世界"], name=u"中文"), 'gb2312'),
145+
(Series(["123", u"Γειά σου", u"Κόσμε"], name=u"Ελληνικά"), 'cp737')
146+
])
147+
def test_to_csv_compression(self, s, encoding, compression):
144148

145149
with ensure_clean() as filename:
146150

147-
s.to_csv(filename, compression=compression, header=True)
151+
s.to_csv(filename, compression=compression, encoding=encoding,
152+
header=True)
148153

149154
# test the round trip - to_csv -> read_csv
150155
rs = pd.read_csv(filename, compression=compression,
151-
index_col=0, squeeze=True)
156+
encoding=encoding, index_col=0, squeeze=True)
152157
assert_series_equal(s, rs)
153158

154159
# explicitly ensure file was compressed
155160
with tm.decompress_file(filename, compression) as fh:
156-
text = fh.read().decode('utf8')
161+
text = fh.read().decode(encoding)
157162
assert s.name in text
158163

159164
with tm.decompress_file(filename, compression) as fh:
160165
assert_series_equal(s, pd.read_csv(fh,
161166
index_col=0,
162-
squeeze=True))
167+
squeeze=True,
168+
encoding=encoding))
163169

164170

165171
class TestSeriesIO(TestData):

0 commit comments

Comments
 (0)