8
8
from pandas import (Series , DataFrame , DatetimeIndex , Timestamp ,
9
9
read_json , compat )
10
10
from datetime import timedelta
11
- moto = pytest .importorskip ("moto" )
12
11
import pandas as pd
13
12
14
13
from pandas .util .testing import (assert_almost_equal , assert_frame_equal ,
@@ -995,8 +994,13 @@ def test_read_inline_jsonl(self):
995
994
def testbucket_conn (self ):
996
995
""" Fixture for test_read_s3_jsonl"""
997
996
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 ()
1000
1004
1001
1005
conn = boto3 .client ('s3' )
1002
1006
conn .create_bucket (Bucket = 'testbucket' )
@@ -1005,25 +1009,25 @@ def testbucket_conn(self):
1005
1009
moto .mock_s3 ().stop ()
1006
1010
1007
1011
def test_read_s3_jsonl (self , testbucket_conn ):
1012
+ pytest .importorskip ('s3fs' )
1008
1013
# 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' )
1010
1019
1011
1020
result = read_json ('s3://testbucket/items.jsonl' , lines = True )
1012
1021
expected = DataFrame ([[1 , 2 ], [1 , 2 ]], columns = ['a' , 'b' ])
1013
1022
assert_frame_equal (result , expected )
1014
1023
1015
1024
def test_read_local_jsonl (self ):
1016
1025
# 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 ' )
1021
1028
result = read_json (fname , lines = True )
1022
1029
expected = DataFrame ([[1 , 2 ], [1 , 2 ]], columns = ['a' , 'b' ])
1023
1030
assert_frame_equal (result , expected )
1024
- finally :
1025
- import os
1026
- os .remove (fname )
1027
1031
1028
1032
def test_read_jsonl_unicode_chars (self ):
1029
1033
# GH15132: non-ascii unicode characters
0 commit comments