Skip to content

Commit

Permalink
Changes to test to prevent warnings in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cruzzoe authored and roberthdevries committed Jun 29, 2020
1 parent 6bb95ab commit 41c4aff
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions pandas/tests/io/excel/test_xlrd.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

import pytest

import pandas as pd
Expand Down Expand Up @@ -26,7 +28,6 @@ def test_read_xlrd_book(read_ext, frame):
with tm.ensure_clean(read_ext) as pth:
df.to_excel(pth, sheet_name)
book = xlrd.open_workbook(pth)

with ExcelFile(book, engine=engine) as xl:
result = pd.read_excel(xl, sheet_name=sheet_name, index_col=0)
tm.assert_frame_equal(df, result)
Expand All @@ -38,20 +39,24 @@ def test_read_xlrd_book(read_ext, frame):
# TODO: test for openpyxl as well
def test_excel_table_sheet_by_index(datapath, read_ext):
path = datapath("io", "data", "excel", f"test1{read_ext}")
with pd.ExcelFile(path) as excel:
with pytest.raises(xlrd.XLRDError):
pd.read_excel(excel, sheet_name="asdf")
with warnings.catch_warnings():
warnings.simplefilter("ignore")
with pd.ExcelFile(path) as excel:
with pytest.raises(xlrd.XLRDError):
pd.read_excel(excel, sheet_name="asdf")


# See issue #29375
def test_excel_file_warning_with_default_engine(datapath):
path = datapath("io", "data", "test1.xls")
with tm.assert_produces_warning(FutureWarning):
path = datapath("io", "data", "excel", "test1.xls")
with warnings.catch_warnings(record=True) as w:
pd.ExcelFile(path)
assert "default to \"openpyxl\" in the future." in str(w[-1].message)


# See issue #29375
def test_read_excel_warning_with_default_engine(tmpdir, datapath):
path = datapath("io", "data", "test1.xls")
with tm.assert_produces_warning(FutureWarning):
pd.read_excel(path, sheet_name="Sheet1")
path = datapath("io", "data", "excel", "test1.xls")
with warnings.catch_warnings(record=True) as w:
pd.read_excel(path, "Sheet1")
assert "default to \"openpyxl\" in the future." in str(w[-1].message)

0 comments on commit 41c4aff

Please sign in to comment.