Skip to content

Commit 38f043b

Browse files
author
Kevin Kuhl
committed
PEP-8 fixes. Ignore tests without s3fs available. Use ensure_clean
1 parent 2ae5a9d commit 38f043b

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

pandas/tests/io/json/test_pandas.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from pandas import (Series, DataFrame, DatetimeIndex, Timestamp,
99
read_json, compat)
1010
from datetime import timedelta
11-
moto = pytest.importorskip("moto")
1211
import pandas as pd
1312

1413
from pandas.util.testing import (assert_almost_equal, assert_frame_equal,
@@ -995,8 +994,13 @@ def test_read_inline_jsonl(self):
995994
def testbucket_conn(self):
996995
""" Fixture for test_read_s3_jsonl"""
997996
boto3 = pytest.importorskip('boto3')
998-
moto.mock_s3().start() # Start and stop mocking only once, surrounding the test run
999-
# to ensure single context is kept.
997+
moto = pytest.importorskip("moto")
998+
999+
"""
1000+
Start and stop mocking only once, surrounding the test run
1001+
to ensure single context is kept.
1002+
"""
1003+
moto.mock_s3().start()
10001004

10011005
conn = boto3.client('s3')
10021006
conn.create_bucket(Bucket='testbucket')
@@ -1005,25 +1009,25 @@ def testbucket_conn(self):
10051009
moto.mock_s3().stop()
10061010

10071011
def test_read_s3_jsonl(self, testbucket_conn):
1012+
pytest.importorskip('s3fs')
10081013
# GH17200
1009-
testbucket_conn.put_object(Body=b'{"a": 1, "b": 2}\n{"b":2, "a" :1}\n', Key='items.jsonl', Bucket='testbucket')
1014+
1015+
body = b'{"a": 1, "b": 2}\n{"b":2, "a" :1}\n'
1016+
testbucket_conn.put_object(Body=body,
1017+
Key='items.jsonl',
1018+
Bucket='testbucket')
10101019

10111020
result = read_json('s3://testbucket/items.jsonl', lines=True)
10121021
expected = DataFrame([[1, 2], [1, 2]], columns=['a', 'b'])
10131022
assert_frame_equal(result, expected)
10141023

10151024
def test_read_local_jsonl(self):
10161025
# GH17200
1017-
fname = "./tmp_items.jsonl"
1018-
try:
1019-
with open(fname, "w") as infile:
1020-
infile.write('{"a": 1, "b": 2}\n{"b":2, "a" :1}\n')
1026+
with ensure_clean('tmp_items.json') as infile:
1027+
infile.write('{"a": 1, "b": 2}\n{"b":2, "a" :1}\n')
10211028
result = read_json(fname, lines=True)
10221029
expected = DataFrame([[1, 2], [1, 2]], columns=['a', 'b'])
10231030
assert_frame_equal(result, expected)
1024-
finally:
1025-
import os
1026-
os.remove(fname)
10271031

10281032
def test_read_jsonl_unicode_chars(self):
10291033
# GH15132: non-ascii unicode characters

0 commit comments

Comments
 (0)