5
5
import os
6
6
from distutils .version import LooseVersion
7
7
8
+ import operator
9
+ import functools
8
10
import nose
9
11
10
12
from numpy import nan
@@ -45,10 +47,6 @@ def _skip_if_no_openpyxl():
45
47
except ImportError :
46
48
raise nose .SkipTest ('openpyxl not installed, skipping' )
47
49
48
- if not openpyxl_compat .is_compat ():
49
- raise nose .SkipTest ('need %s <= openpyxl < %s, skipping' %
50
- (openpyxl_compat .start_ver , openpyxl_compat .stop_ver ))
51
-
52
50
53
51
def _skip_if_no_xlsxwriter ():
54
52
try :
@@ -884,7 +882,6 @@ def test_to_excel_output_encoding(self):
884
882
result = read_excel (filename , 'TestSheet' , encoding = 'utf8' )
885
883
tm .assert_frame_equal (result , df )
886
884
887
-
888
885
def test_to_excel_unicode_filename (self ):
889
886
_skip_if_no_xlrd ()
890
887
with ensure_clean (u ('\u0192 u.' ) + self .ext ) as filename :
@@ -1094,13 +1091,36 @@ def test_swapped_columns(self):
1094
1091
tm .assert_series_equal (write_frame ['B' ], read_frame ['B' ])
1095
1092
1096
1093
1094
+ def raise_wrapper (orig_method ):
1095
+ @functools .wraps (orig_method )
1096
+ def wrapped (self , * args , ** kwargs ):
1097
+ _skip_if_no_openpyxl ()
1098
+ if openpyxl_compat .is_compat ():
1099
+ orig_method (self , * args , ** kwargs )
1100
+ else :
1101
+ msg = 'Installed openpyxl is not supported at this time\. Use.+'
1102
+ with tm .assertRaisesRegexp (ValueError , msg ):
1103
+ orig_method (self , * args , ** kwargs )
1104
+ return wrapped
1105
+
1106
+
1107
+ def raise_on_incompat_version (cls ):
1108
+ methods = filter (operator .methodcaller ('startswith' , 'test_' ), dir (cls ))
1109
+ for method in methods :
1110
+ setattr (cls , method , raise_wrapper (getattr (cls , method )))
1111
+ return cls
1112
+
1113
+
1114
+ @raise_on_incompat_version
1097
1115
class OpenpyxlTests (ExcelWriterBase , tm .TestCase ):
1098
1116
ext = '.xlsx'
1099
1117
engine_name = 'openpyxl'
1100
- check_skip = staticmethod (_skip_if_no_openpyxl )
1118
+ check_skip = staticmethod (lambda * args , ** kwargs : None )
1101
1119
1102
1120
def test_to_excel_styleconverter (self ):
1103
1121
_skip_if_no_openpyxl ()
1122
+ if not openpyxl_compat .is_compat ():
1123
+ raise nose .SkipTest ('incompatiable openpyxl version' )
1104
1124
1105
1125
import openpyxl
1106
1126
@@ -1114,17 +1134,17 @@ def test_to_excel_styleconverter(self):
1114
1134
xlsx_style = _OpenpyxlWriter ._convert_to_style (hstyle )
1115
1135
self .assertTrue (xlsx_style .font .bold )
1116
1136
self .assertEqual (openpyxl .style .Border .BORDER_THIN ,
1117
- xlsx_style .borders .top .border_style )
1137
+ xlsx_style .borders .top .border_style )
1118
1138
self .assertEqual (openpyxl .style .Border .BORDER_THIN ,
1119
- xlsx_style .borders .right .border_style )
1139
+ xlsx_style .borders .right .border_style )
1120
1140
self .assertEqual (openpyxl .style .Border .BORDER_THIN ,
1121
- xlsx_style .borders .bottom .border_style )
1141
+ xlsx_style .borders .bottom .border_style )
1122
1142
self .assertEqual (openpyxl .style .Border .BORDER_THIN ,
1123
- xlsx_style .borders .left .border_style )
1143
+ xlsx_style .borders .left .border_style )
1124
1144
self .assertEqual (openpyxl .style .Alignment .HORIZONTAL_CENTER ,
1125
- xlsx_style .alignment .horizontal )
1145
+ xlsx_style .alignment .horizontal )
1126
1146
self .assertEqual (openpyxl .style .Alignment .VERTICAL_TOP ,
1127
- xlsx_style .alignment .vertical )
1147
+ xlsx_style .alignment .vertical )
1128
1148
1129
1149
1130
1150
class XlwtTests (ExcelWriterBase , tm .TestCase ):
@@ -1160,6 +1180,7 @@ class XlsxWriterTests(ExcelWriterBase, tm.TestCase):
1160
1180
check_skip = staticmethod (_skip_if_no_xlsxwriter )
1161
1181
1162
1182
1183
+ @raise_on_incompat_version
1163
1184
class OpenpyxlTests_NoMerge (ExcelWriterBase , tm .TestCase ):
1164
1185
ext = '.xlsx'
1165
1186
engine_name = 'openpyxl'
@@ -1196,6 +1217,8 @@ def test_ExcelWriter_dispatch(self):
1196
1217
import xlsxwriter
1197
1218
writer_klass = _XlsxWriter
1198
1219
except ImportError :
1220
+ if not openpyxl_compat .is_compat ():
1221
+ raise nose .SkipTest ('incompatible openpyxl version' )
1199
1222
_skip_if_no_openpyxl ()
1200
1223
writer_klass = _OpenpyxlWriter
1201
1224
@@ -1246,6 +1269,7 @@ def check_called(func):
1246
1269
check_called (lambda : df .to_excel ('something.xls' , engine = 'dummy' ))
1247
1270
set_option ('io.excel.xlsx.writer' , val )
1248
1271
1272
+
1249
1273
if __name__ == '__main__' :
1250
1274
nose .runmodule (argv = [__file__ , '-vvs' , '-x' , '--pdb' , '--pdb-failure' ],
1251
1275
exit = False )
0 commit comments