Skip to content

Commit

Permalink
Deprecate remaining xlrd based functions and emits_deprecation decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
bladams committed Jan 26, 2021
1 parent 5d9ff21 commit febc56c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
2 changes: 2 additions & 0 deletions 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 @@ -84,6 +85,7 @@ 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
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

0 comments on commit febc56c

Please sign in to comment.