Skip to content

Commit 1bac2e0

Browse files
h-vetinariPingviinituutti
authored andcommitted
TST: use s3_resource fixture consistently (pandas-dev#24073)
1 parent f3bf0b5 commit 1bac2e0

File tree

2 files changed

+21
-32
lines changed

2 files changed

+21
-32
lines changed

pandas/tests/io/json/test_compression.py

+9-14
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,19 @@ def test_read_zipped_json(datapath):
3333

3434

3535
@td.skip_if_not_us_locale
36-
def test_with_s3_url(compression):
37-
boto3 = pytest.importorskip('boto3')
38-
pytest.importorskip('s3fs')
39-
moto = pytest.importorskip('moto')
36+
def test_with_s3_url(compression, s3_resource):
37+
# Bucket "pandas-test" created in tests/io/conftest.py
4038

4139
df = pd.read_json('{"a": [1, 2, 3], "b": [4, 5, 6]}')
42-
with moto.mock_s3():
43-
conn = boto3.resource("s3", region_name="us-east-1")
44-
bucket = conn.create_bucket(Bucket="pandas-test")
4540

46-
with tm.ensure_clean() as path:
47-
df.to_json(path, compression=compression)
48-
with open(path, 'rb') as f:
49-
bucket.put_object(Key='test-1', Body=f)
41+
with tm.ensure_clean() as path:
42+
df.to_json(path, compression=compression)
43+
with open(path, 'rb') as f:
44+
s3_resource.Bucket("pandas-test").put_object(Key='test-1', Body=f)
5045

51-
roundtripped_df = pd.read_json('s3://pandas-test/test-1',
52-
compression=compression)
53-
assert_frame_equal(df, roundtripped_df)
46+
roundtripped_df = pd.read_json('s3://pandas-test/test-1',
47+
compression=compression)
48+
assert_frame_equal(df, roundtripped_df)
5449

5550

5651
def test_lines_with_compression(compression):

pandas/tests/io/test_excel.py

+12-18
Original file line numberDiff line numberDiff line change
@@ -723,25 +723,19 @@ def test_read_from_http_url(self, ext):
723723
local_table = self.get_exceldf('test1', ext)
724724
tm.assert_frame_equal(url_table, local_table)
725725

726-
@td.skip_if_no("s3fs")
727726
@td.skip_if_not_us_locale
728-
def test_read_from_s3_url(self, ext):
729-
moto = pytest.importorskip("moto")
730-
boto3 = pytest.importorskip("boto3")
731-
732-
with moto.mock_s3():
733-
conn = boto3.resource("s3", region_name="us-east-1")
734-
conn.create_bucket(Bucket="pandas-test")
735-
file_name = os.path.join(self.dirpath, 'test1' + ext)
736-
737-
with open(file_name, "rb") as f:
738-
conn.Bucket("pandas-test").put_object(Key="test1" + ext,
739-
Body=f)
740-
741-
url = ('s3://pandas-test/test1' + ext)
742-
url_table = read_excel(url)
743-
local_table = self.get_exceldf('test1', ext)
744-
tm.assert_frame_equal(url_table, local_table)
727+
def test_read_from_s3_url(self, ext, s3_resource):
728+
# Bucket "pandas-test" created in tests/io/conftest.py
729+
file_name = os.path.join(self.dirpath, 'test1' + ext)
730+
731+
with open(file_name, "rb") as f:
732+
s3_resource.Bucket("pandas-test").put_object(Key="test1" + ext,
733+
Body=f)
734+
735+
url = ('s3://pandas-test/test1' + ext)
736+
url_table = read_excel(url)
737+
local_table = self.get_exceldf('test1', ext)
738+
tm.assert_frame_equal(url_table, local_table)
745739

746740
@pytest.mark.slow
747741
# ignore warning from old xlrd

0 commit comments

Comments
 (0)