Skip to content

TST: use s3_resource fixture consistently #24073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions pandas/tests/io/json/test_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,19 @@ def test_read_zipped_json(datapath):


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

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

with tm.ensure_clean() as path:
df.to_json(path, compression=compression)
with open(path, 'rb') as f:
bucket.put_object(Key='test-1', Body=f)
with tm.ensure_clean() as path:
df.to_json(path, compression=compression)
with open(path, 'rb') as f:
s3_resource.Bucket("pandas-test").put_object(Key='test-1', Body=f)

roundtripped_df = pd.read_json('s3://pandas-test/test-1',
compression=compression)
assert_frame_equal(df, roundtripped_df)
roundtripped_df = pd.read_json('s3://pandas-test/test-1',
compression=compression)
assert_frame_equal(df, roundtripped_df)


def test_lines_with_compression(compression):
Expand Down
30 changes: 12 additions & 18 deletions pandas/tests/io/test_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,25 +723,19 @@ def test_read_from_http_url(self, ext):
local_table = self.get_exceldf('test1', ext)
tm.assert_frame_equal(url_table, local_table)

@td.skip_if_no("s3fs")
@td.skip_if_not_us_locale
def test_read_from_s3_url(self, ext):
moto = pytest.importorskip("moto")
boto3 = pytest.importorskip("boto3")

with moto.mock_s3():
conn = boto3.resource("s3", region_name="us-east-1")
conn.create_bucket(Bucket="pandas-test")
file_name = os.path.join(self.dirpath, 'test1' + ext)

with open(file_name, "rb") as f:
conn.Bucket("pandas-test").put_object(Key="test1" + ext,
Body=f)

url = ('s3://pandas-test/test1' + ext)
url_table = read_excel(url)
local_table = self.get_exceldf('test1', ext)
tm.assert_frame_equal(url_table, local_table)
def test_read_from_s3_url(self, ext, s3_resource):
# Bucket "pandas-test" created in tests/io/conftest.py
file_name = os.path.join(self.dirpath, 'test1' + ext)

with open(file_name, "rb") as f:
s3_resource.Bucket("pandas-test").put_object(Key="test1" + ext,
Body=f)

url = ('s3://pandas-test/test1' + ext)
url_table = read_excel(url)
local_table = self.get_exceldf('test1', ext)
tm.assert_frame_equal(url_table, local_table)

@pytest.mark.slow
# ignore warning from old xlrd
Expand Down