@@ -1029,6 +1029,18 @@ def test_read_excel_squeeze(self, ext):
1029
1029
tm .assert_series_equal (actual , expected )
1030
1030
1031
1031
1032
+ class _WriterBase (SharedItems ):
1033
+ """Provides fixture to set / reset options for all writer tests"""
1034
+
1035
+ @pytest .fixture (autouse = True )
1036
+ def set_options (self , request , merge_cells , engine , ext ):
1037
+ option_name = 'io.excel.{ext}.writer' .format (ext = ext .strip ('.' ))
1038
+ prev_engine = get_option (option_name )
1039
+ set_option (option_name , engine )
1040
+ yield
1041
+ set_option (option_name , prev_engine )
1042
+
1043
+
1032
1044
@pytest .mark .parametrize ("merge_cells" , [True , False ])
1033
1045
@pytest .mark .parametrize ("engine,ext" , [
1034
1046
pytest .param ('openpyxl' , '.xlsx' , marks = pytest .mark .skipif (
@@ -1038,9 +1050,8 @@ def test_read_excel_squeeze(self, ext):
1038
1050
pytest .param ('xlsxwriter' , '.xlsx' , marks = pytest .mark .skipif (
1039
1051
not td .safe_import ('xlsxwriter' ), reason = 'No xlsxwriter' ))
1040
1052
])
1041
- class TestExcelWriter (SharedItems ):
1053
+ class TestExcelWriter (_WriterBase ):
1042
1054
# Base class for test cases to run with different Excel writers.
1043
- merge_cells = True
1044
1055
1045
1056
def test_excel_sheet_by_name_raise (self , merge_cells , engine , ext ):
1046
1057
import xlrd
@@ -1935,10 +1946,11 @@ def test_path_localpath(self, merge_cells, engine, ext):
1935
1946
1936
1947
1937
1948
@td .skip_if_no ('openpyxl' )
1938
- @pytest .mark .parametrize ("ext" , ['.xlsx' ])
1939
- class TestOpenpyxlTests (SharedItems ):
1949
+ @pytest .mark .parametrize ("merge_cells,ext,engine" , [
1950
+ (None , '.xlsx' , 'openpyxl' )])
1951
+ class TestOpenpyxlTests (_WriterBase ):
1940
1952
1941
- def test_to_excel_styleconverter (self , ext ):
1953
+ def test_to_excel_styleconverter (self , merge_cells , ext , engine ):
1942
1954
from openpyxl import styles
1943
1955
1944
1956
hstyle = {
@@ -1992,7 +2004,7 @@ def test_to_excel_styleconverter(self, ext):
1992
2004
assert kw ['number_format' ] == number_format
1993
2005
assert kw ['protection' ] == protection
1994
2006
1995
- def test_write_cells_merge_styled (self , ext ):
2007
+ def test_write_cells_merge_styled (self , merge_cells , ext , engine ):
1996
2008
from pandas .io .formats .excel import ExcelCell
1997
2009
1998
2010
sheet_name = 'merge_styled'
@@ -2026,10 +2038,12 @@ def test_write_cells_merge_styled(self, ext):
2026
2038
2027
2039
2028
2040
@td .skip_if_no ('xlwt' )
2029
- @pytest .mark .parametrize ("ext" , ['.xls' ])
2030
- class TestXlwtTests (SharedItems ):
2041
+ @pytest .mark .parametrize ("merge_cells,ext,engine" , [
2042
+ (None , '.xls' , 'xlwt' )])
2043
+ class TestXlwtTests (_WriterBase ):
2031
2044
2032
- def test_excel_raise_error_on_multiindex_columns_and_no_index (self , ext ):
2045
+ def test_excel_raise_error_on_multiindex_columns_and_no_index (
2046
+ self , merge_cells , ext , engine ):
2033
2047
# MultiIndex as columns is not yet implemented 9794
2034
2048
cols = MultiIndex .from_tuples ([('site' , '' ),
2035
2049
('2014' , 'height' ),
@@ -2039,15 +2053,16 @@ def test_excel_raise_error_on_multiindex_columns_and_no_index(self, ext):
2039
2053
with ensure_clean (ext ) as path :
2040
2054
df .to_excel (path , index = False )
2041
2055
2042
- def test_excel_multiindex_columns_and_index_true (self , ext ):
2056
+ def test_excel_multiindex_columns_and_index_true (self , merge_cells , ext ,
2057
+ engine ):
2043
2058
cols = MultiIndex .from_tuples ([('site' , '' ),
2044
2059
('2014' , 'height' ),
2045
2060
('2014' , 'weight' )])
2046
2061
df = pd .DataFrame (np .random .randn (10 , 3 ), columns = cols )
2047
2062
with ensure_clean (ext ) as path :
2048
2063
df .to_excel (path , index = True )
2049
2064
2050
- def test_excel_multiindex_index (self , ext ):
2065
+ def test_excel_multiindex_index (self , merge_cells , ext , engine ):
2051
2066
# MultiIndex as index works so assert no error #9794
2052
2067
cols = MultiIndex .from_tuples ([('site' , '' ),
2053
2068
('2014' , 'height' ),
@@ -2056,7 +2071,7 @@ def test_excel_multiindex_index(self, ext):
2056
2071
with ensure_clean (ext ) as path :
2057
2072
df .to_excel (path , index = False )
2058
2073
2059
- def test_to_excel_styleconverter (self , ext ):
2074
+ def test_to_excel_styleconverter (self , merge_cells , ext , engine ):
2060
2075
import xlwt
2061
2076
2062
2077
hstyle = {"font" : {"bold" : True },
@@ -2077,10 +2092,11 @@ def test_to_excel_styleconverter(self, ext):
2077
2092
2078
2093
2079
2094
@td .skip_if_no ('xlsxwriter' )
2080
- @pytest .mark .parametrize ("ext" , ['.xlsx' ])
2081
- class TestXlsxWriterTests (SharedItems ):
2095
+ @pytest .mark .parametrize ("merge_cells,ext,engine" , [
2096
+ (None , '.xlsx' , 'xlsxwriter' )])
2097
+ class TestXlsxWriterTests (_WriterBase ):
2082
2098
2083
- def test_column_format (self , ext ):
2099
+ def test_column_format (self , merge_cells , ext , engine ):
2084
2100
# Test that column formats are applied to cells. Test for issue #9167.
2085
2101
# Applicable to xlsxwriter only.
2086
2102
with warnings .catch_warnings ():
0 commit comments