Skip to content

Commit

Permalink
Merge pull request #23 from blazelibs/remove-xlrd-req
Browse files Browse the repository at this point in the history
Remove unnecessary xlrd requirement from xlsx_to_strio()
  • Loading branch information
bladams committed Jan 26, 2021
2 parents 19c0efe + febc56c commit 9e29b7b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
4 changes: 3 additions & 1 deletion blazeutils/spreadsheets.py
Expand Up @@ -60,6 +60,7 @@ def http_headers(filename, randomize=True):
return headers


@deprecate('xlrd is no longer maintained, recommend switching to openpyxl')
def workbook_to_reader(xlwt_wb):
"""
convert xlwt Workbook instance to an xlrd instance for reading
Expand All @@ -76,7 +77,6 @@ def xlsx_to_strio(xlsx_wb):
"""
convert xlwt Workbook instance to a BytesIO instance
"""
_xlrd_required()
fh = BytesIO()
xlsx_wb.filename = fh
xlsx_wb.close()
Expand All @@ -85,10 +85,12 @@ def xlsx_to_strio(xlsx_wb):
return fh


@deprecate('xlrd is no longer maintained, recommend switching to openpyxl')
def xlsx_to_reader(xlsx_wb):
"""
convert xlsxwriter Workbook instance to an xlrd instance for reading
"""
_xlrd_required()
fh = xlsx_to_strio(xlsx_wb)
return xlrd.open_workbook(file_contents=fh.read())

Expand Down
1 change: 1 addition & 0 deletions blazeutils/testing.py
Expand Up @@ -120,6 +120,7 @@ def current(self):
return self.contents[self.index]


@deprecate('The @emits_deprecation is deprecated. Use pytest.warns instead.')
def emits_deprecation(*messages):
"""
Decorate a test enforcing it emits the given DeprecationWarnings with
Expand Down
15 changes: 9 additions & 6 deletions blazeutils/tests/test_error_handling.py
@@ -1,30 +1,33 @@
from __future__ import absolute_import
from __future__ import unicode_literals

import pytest

from blazeutils.error_handling import tb_depth_in, traceback_depth, _uie_matches
from blazeutils.testing import emits_deprecation


@emits_deprecation('.+its a bad idea')
def test_traceback_funcs():
try:
import somethingthatwontbethereihope # noqa
assert False, 'expected import error'
except ImportError:
assert traceback_depth() == 0, 'if this test fails, you probably have something wrapping' \
'__import__'
with pytest.warns(DeprecationWarning, match='.+its a bad idea'):
assert traceback_depth() == 0, 'if this test fails, you probably have something ' \
'wrapping __import__'

try:
from ._bad_import import foobar # noqa
assert False, 'expected Import Error'
except ImportError:
assert traceback_depth() == 0
with pytest.warns(DeprecationWarning, match='.+its a bad idea'):
assert traceback_depth() == 0

try:
from ._bad_import_deeper import foobar2 # noqa
assert False, 'expected import error'
except ImportError:
assert traceback_depth() == 1
with pytest.warns(DeprecationWarning, match='.+its a bad idea'):
assert traceback_depth() == 1

assert tb_depth_in(1)
assert tb_depth_in((0, 1))
Expand Down
14 changes: 8 additions & 6 deletions blazeutils/tests/test_spreadsheets.py
Expand Up @@ -14,7 +14,6 @@
xlsx_to_reader,
xlsx_to_strio,
)
from blazeutils.testing import emits_deprecation


class TestWorkbookToReader(object):
Expand All @@ -26,30 +25,33 @@ def test_xlwt_to_reader(self):
ws = write_wb.add_sheet('Foo')
ws.write(0, 0, 'bar')

wb = workbook_to_reader(write_wb)
with pytest.warns(DeprecationWarning,
match='xlrd is no longer maintained, recommend switching to openpyxl'):
wb = workbook_to_reader(write_wb)
sh = wb.sheet_by_name('Foo')
assert sh.cell_value(rowx=0, colx=0) == 'bar'


class TestXlsxToReader(object):

def test_xlsx_to_reader(self):
import xlsxwriter

write_wb = xlsxwriter.Workbook()
ws = write_wb.add_worksheet('Foo')
ws.write(0, 0, 'bar')

wb = xlsx_to_reader(write_wb)
with pytest.warns(DeprecationWarning,
match='xlrd is no longer maintained, recommend switching to openpyxl'):
wb = xlsx_to_reader(write_wb)
sh = wb.sheet_by_name('Foo')
assert sh.cell_value(rowx=0, colx=0) == 'bar'


class TestWriter(object):

@emits_deprecation('XlwtHelper has been renamed to Writer')
def test_xlwt_helper_deprecation(self):
XlwtHelper()
with pytest.warns(DeprecationWarning, match='XlwtHelper has been renamed to Writer'):
XlwtHelper()


class TestWriterX:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -26,7 +26,7 @@
'tox',
'wheel',
'xlwt',
'xlrd',
'xlrd<2.0.0',
'xlsxwriter',

# pytest dep on windows
Expand Down

0 comments on commit 9e29b7b

Please sign in to comment.