Skip to content

Commit d11dcae

Browse files
committed
use _get_handle to produce a handle
1 parent 5e66ee2 commit d11dcae

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

pandas/tests/test_common.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pandas.compat import range, lmap
1212
import pandas.core.common as com
1313
from pandas.core import ops
14+
from pandas.io.common import _get_handle
1415
import pandas.util.testing as tm
1516

1617

@@ -246,19 +247,19 @@ def test_compression_size(obj, method, compression_only):
246247
[12.32112, 123123.2, 321321.2]],
247248
columns=['X', 'Y', 'Z']),
248249
Series(100 * [0.123456, 0.234567, 0.567567], name='X')])
249-
@pytest.mark.parametrize('method', ['to_csv'])
250+
@pytest.mark.parametrize('method', ['to_csv', 'to_json'])
250251
def test_compression_size_fh(obj, method, compression_only):
251252

252253
with tm.ensure_clean() as filename:
253-
with open(filename, 'w') as fh:
254-
getattr(obj, method)(fh, compression=compression_only)
255-
assert not fh.closed
256-
assert fh.closed
254+
f, _handles = _get_handle(filename, 'w', compression=compression_only)
255+
with f:
256+
getattr(obj, method)(f)
257+
assert not f.closed
257258
compressed = os.path.getsize(filename)
258259
with tm.ensure_clean() as filename:
259-
with open(filename, 'w') as fh:
260-
getattr(obj, method)(fh, compression=None)
261-
assert not fh.closed
262-
assert fh.closed
260+
f, _handles = _get_handle(filename, 'w', compression=None)
261+
with f:
262+
getattr(obj, method)(f)
263+
assert not f.closed
263264
uncompressed = os.path.getsize(filename)
264265
assert uncompressed > compressed

0 commit comments

Comments
 (0)