Skip to content

Commit

Permalink
Split test_excel.py (pandas-dev#24472)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbw committed Jan 13, 2019
1 parent f6309d9 commit 0f9d7f6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2,585 deletions.
14 changes: 5 additions & 9 deletions pandas/tests/io/excel/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def set_engine(self, request):
[1, 0, 3], [1, 3, 0],
[3, 0, 1], [3, 1, 0],
])

def test_usecols_diff_positional_int_columns_order(self, ext, usecols):
expected = self.get_csv_refdf("test1")[["A", "C"]]
result = self.get_exceldf("test1", ext, "Sheet1",
Expand All @@ -92,7 +91,6 @@ def test_usecols_diff_positional_int_columns_order(self, ext, usecols):
@pytest.mark.parametrize("usecols", [
["B", "D"], ["D", "B"]
])

def test_usecols_diff_positional_str_columns_order(self, ext, usecols):
expected = self.get_csv_refdf("test1")[["B", "D"]]
expected.index = range(len(expected))
Expand Down Expand Up @@ -931,7 +929,7 @@ def test_read_excel_squeeze(self, ext):
actual = pd.read_excel(f, 'one_column', squeeze=True)
expected = pd.Series([1, 2, 3], name='a')
tm.assert_series_equal(actual, expected)


class _WriterBase(SharedItems):

Expand Down Expand Up @@ -973,8 +971,6 @@ class and any subclasses, on account of the `autouse=True`
pytest.param('xlsxwriter', '.xlsx', marks=pytest.mark.skipif(
not td.safe_import('xlsxwriter'), reason='No xlsxwriter'))
])


class TestExcelWriter(_WriterBase):
# Base class for test cases to run with different Excel writers.

Expand Down Expand Up @@ -1958,7 +1954,7 @@ def test_write_append_mode(self, merge_cells, ext, engine, mode, expected):

for index, cell_value in enumerate(expected):
assert wb2.worksheets[index]['A1'].value == cell_value


@td.skip_if_no('xlwt')
@pytest.mark.parametrize("merge_cells,ext,engine", [
Expand Down Expand Up @@ -2019,7 +2015,7 @@ def test_write_append_mode_raises(self, merge_cells, ext, engine):
with ensure_clean(ext) as f:
with pytest.raises(ValueError, match=msg):
ExcelWriter(f, engine=engine, mode='a')


@td.skip_if_no('xlsxwriter')
@pytest.mark.parametrize("merge_cells,ext,engine", [
Expand Down Expand Up @@ -2142,7 +2138,7 @@ def check_called(func):
check_called(
lambda: df.to_excel(
'something.xls', engine='dummy'))


@pytest.mark.parametrize('engine', [
pytest.param('xlwt',
Expand Down Expand Up @@ -2294,7 +2290,7 @@ def custom_converter(css):
n_cells += 1

assert n_cells == (11 + 1) * (3 + 1)


@td.skip_if_no('openpyxl')
@pytest.mark.skipif(not PY36, reason='requires fspath')
Expand Down
21 changes: 9 additions & 12 deletions pandas/tests/io/excel/xlrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ def get_exceldf(self, basename, ext, *args, **kwds):
"""
pth = os.path.join(self.dirpath, basename + ext)
return read_excel(pth, *args, **kwds)


class XlrdReadingTestsBase(XlrdSharedItems):
# This is based on ExcelWriterBase

@pytest.fixture(autouse=True, params=['xlrd'])
def set_engine(self, request):
func_name = "get_exceldf"
Expand All @@ -102,7 +102,6 @@ def set_engine(self, request):
[1, 0, 3], [1, 3, 0],
[3, 0, 1], [3, 1, 0],
])

@td.skip_if_no("xlrd", "1.0.1") # see gh-22682
def test_usecols_int(self, ext):

Expand Down Expand Up @@ -192,7 +191,7 @@ def test_usecols_str(self, ext):
index_col=0, usecols='A,C:D')
tm.assert_frame_equal(df2, df1, check_names=False)
tm.assert_frame_equal(df3, df1, check_names=False)

@td.skip_if_no('xlrd', '1.0.1') # GH-22682
def test_deprecated_sheetname(self, ext):
# gh-17964
Expand Down Expand Up @@ -233,7 +232,7 @@ def test_excel_table_sheet_by_index(self, ext):
import xlrd
with pytest.raises(xlrd.XLRDError):
read_excel(excel, 'asdf')

@td.skip_if_no("xlrd", "1.0.1") # see gh-22682
def test_sheet_name_and_sheetname(self, ext):
# gh-10559: Minor improvement: Change "sheet_name" to "sheetname"
Expand Down Expand Up @@ -262,7 +261,7 @@ def test_sheet_name_and_sheetname(self, ext):
tm.assert_frame_equal(df2, df_ref, check_names=False)
tm.assert_frame_equal(df1_parse, df_ref, check_names=False)
tm.assert_frame_equal(df2_parse, df_ref, check_names=False)


@pytest.mark.parametrize("ext", ['.xls', '.xlsx', '.xlsm'])
class TestXlrdReader(XlrdReadingTestsBase):
Expand Down Expand Up @@ -290,8 +289,8 @@ def test_read_xlrd_book(self, ext):
result = read_excel(book, sheet_name=sheet_name,
engine=engine, index_col=0)
tm.assert_frame_equal(df, result)


class _XlrdWriterBase(XlrdSharedItems):

@pytest.fixture(autouse=True)
Expand Down Expand Up @@ -332,8 +331,6 @@ class and any subclasses, on account of the `autouse=True`
pytest.param('xlsxwriter', '.xlsx', marks=pytest.mark.skipif(
not td.safe_import('xlsxwriter'), reason='No xlsxwriter'))
])


class XlrdTestExcelWriter(_XlrdWriterBase):
# Base class for test cases to run with different Excel writers.

Expand All @@ -349,4 +346,4 @@ def test_excel_sheet_by_name_raise(self, *_):
tm.assert_frame_equal(gt, df)

with pytest.raises(xlrd.XLRDError):
read_excel(xl, "0")
read_excel(xl, "0")
2 changes: 1 addition & 1 deletion pandas/tests/io/formats/test_to_excel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Tests formatting as writer-agnostic ExcelCells
ExcelFormatter is tested implicitly in pandas/tests/io/test_excel.py
ExcelFormatter is tested implicitly in pandas/tests/io/mainF.py
"""

import pytest
Expand Down
Loading

0 comments on commit 0f9d7f6

Please sign in to comment.