Skip to content

Commit a4f3b14

Browse files
committed
Added decorator to XlrdTests
1 parent cd1b168 commit a4f3b14

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

pandas/tests/io/test_excel.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,11 @@ class ReadingTestsBase(SharedItems):
146146
#
147147
# Base class for test cases to run with different Excel readers.
148148
# To add a reader test, define the following:
149-
# 1. A check_skip function that skips your tests if your reader isn't
150-
# installed.
151-
# 2. Add a property ext, which is the file extension that your reader
149+
# 1. Add a property ext, which is the file extension that your reader
152150
# reades from. (needs to start with '.' so it's a valid path)
153-
# 3. Add a property engine_name, which is the name of the reader class.
151+
# 2. Add a property engine_name, which is the name of the reader class.
154152
# For the reader this is not used for anything at the moment.
155153

156-
def setup_method(self, method):
157-
self.check_skip()
158-
super(ReadingTestsBase, self).setup_method(method)
159-
160154
def test_usecols_int(self):
161155

162156
dfref = self.get_csv_refdf('test1')
@@ -567,6 +561,7 @@ def test_sheet_name_both_raises(self):
567561
self.get_exceldf('test1', sheetname='Sheet1', sheet_name='Sheet1')
568562

569563

564+
@td.skip_if_no('xlrd', '0.9')
570565
class XlrdTests(ReadingTestsBase):
571566
"""
572567
This is the base class for the xlrd tests, and 3 different file formats
@@ -589,7 +584,6 @@ def test_excel_read_buffer(self):
589584
def test_read_xlrd_Book(self):
590585
_skip_if_no_xlwt()
591586

592-
import xlrd
593587
df = self.frame
594588
with ensure_clean('.xls') as pth:
595589
df.to_excel(pth, "SheetA")
@@ -713,9 +707,9 @@ def tdf(sheetname):
713707
tm.assert_frame_equal(dfs[s], dfs_returned[s])
714708

715709
def test_reader_seconds(self):
716-
# Test reading times with and without milliseconds. GH5945.
717710
import xlrd
718711

712+
# Test reading times with and without milliseconds. GH5945.
719713
if LooseVersion(xlrd.__VERSION__) >= LooseVersion("0.9.3"):
720714
# Xlrd >= 0.9.3 can handle Excel milliseconds.
721715
expected = DataFrame.from_dict({"Time": [time(1, 2, 3),
@@ -1061,19 +1055,16 @@ def test_read_excel_squeeze(self):
10611055
class TestXlsReaderTests(XlrdTests):
10621056
ext = '.xls'
10631057
engine_name = 'xlrd'
1064-
check_skip = staticmethod(_skip_if_no_xlrd)
10651058

10661059

10671060
class TestXlsxReaderTests(XlrdTests):
10681061
ext = '.xlsx'
10691062
engine_name = 'xlrd'
1070-
check_skip = staticmethod(_skip_if_no_xlrd)
10711063

10721064

10731065
class TestXlsmReaderTests(XlrdTests):
10741066
ext = '.xlsm'
10751067
engine_name = 'xlrd'
1076-
check_skip = staticmethod(_skip_if_no_xlrd)
10771068

10781069

10791070
class ExcelWriterBase(SharedItems):

pandas/util/_test_decorators.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ def safe_import(mod_name, min_version=None):
5757
return mod
5858
else:
5959
import sys
60-
version = getattr(sys.modules[mod_name], '__version__')
60+
try:
61+
version = getattr(sys.modules[mod_name], '__version__')
62+
except AttributeError:
63+
# xlrd uses a capitalized attribute name
64+
version = getattr(sys.modules[mod_name], '__VERSION__')
6165
if version:
6266
from distutils.version import LooseVersion
6367
if LooseVersion(version) >= LooseVersion(min_version):

0 commit comments

Comments
 (0)