From 5d9ff214d7bae6cfe8323f3803ca2c10cfa80469 Mon Sep 17 00:00:00 2001 From: bladams Date: Thu, 14 Jan 2021 10:51:59 -0500 Subject: [PATCH 1/2] Remove unnecessary xlrd requirement from xlsx_to_strio() --- blazeutils/spreadsheets.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/blazeutils/spreadsheets.py b/blazeutils/spreadsheets.py index acdf100..2619868 100644 --- a/blazeutils/spreadsheets.py +++ b/blazeutils/spreadsheets.py @@ -76,7 +76,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() @@ -89,6 +88,7 @@ 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()) diff --git a/setup.py b/setup.py index 220f456..300a320 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ 'tox', 'wheel', 'xlwt', - 'xlrd', + 'xlrd<2.0.0', 'xlsxwriter', # pytest dep on windows From febc56c721720c54cd12414b12fa3676b024c777 Mon Sep 17 00:00:00 2001 From: bladams Date: Tue, 26 Jan 2021 17:09:36 -0500 Subject: [PATCH 2/2] Deprecate remaining xlrd based functions and emits_deprecation decorator --- blazeutils/spreadsheets.py | 2 ++ blazeutils/testing.py | 1 + blazeutils/tests/test_error_handling.py | 15 +++++++++------ blazeutils/tests/test_spreadsheets.py | 14 ++++++++------ 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/blazeutils/spreadsheets.py b/blazeutils/spreadsheets.py index 2619868..be3459a 100644 --- a/blazeutils/spreadsheets.py +++ b/blazeutils/spreadsheets.py @@ -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 @@ -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 diff --git a/blazeutils/testing.py b/blazeutils/testing.py index bd9a0c2..f539d5f 100644 --- a/blazeutils/testing.py +++ b/blazeutils/testing.py @@ -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 diff --git a/blazeutils/tests/test_error_handling.py b/blazeutils/tests/test_error_handling.py index 478a030..8121927 100644 --- a/blazeutils/tests/test_error_handling.py +++ b/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)) diff --git a/blazeutils/tests/test_spreadsheets.py b/blazeutils/tests/test_spreadsheets.py index ef9ef47..4de0722 100644 --- a/blazeutils/tests/test_spreadsheets.py +++ b/blazeutils/tests/test_spreadsheets.py @@ -14,7 +14,6 @@ xlsx_to_reader, xlsx_to_strio, ) -from blazeutils.testing import emits_deprecation class TestWorkbookToReader(object): @@ -26,13 +25,14 @@ 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 @@ -40,16 +40,18 @@ def test_xlsx_to_reader(self): 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: