Skip to content

TST: Cleanup Excel tests to make it easier to add and test additional writers #4844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 15, 2013

Conversation

jtratner
Copy link
Contributor

No description provided.

@jtratner
Copy link
Contributor Author

@jmcnamara - this should make it much easier for you to add and test xlsxwriter. Just follow the pattern for OpenpyxlTests and XlwtTests and you should be good.

@jtratner
Copy link
Contributor Author

For those interested: this doesn't add or remove tests, just makes it much easier to add new writers and new writer tests.

@jtratner
Copy link
Contributor Author

and preserves skip output:


#16 pandas.io.tests.test_excel.OpenpyxlTests.test_bool: openpyxl not installed, skipping
#17 pandas.io.tests.test_excel.OpenpyxlTests.test_colaliases: openpyxl not installed, skipping
#18 pandas.io.tests.test_excel.OpenpyxlTests.test_excel_010_hemstring: openpyxl not installed, skipping
#19 pandas.io.tests.test_excel.OpenpyxlTests.test_excel_roundtrip_datetime: openpyxl not installed, skipping
#20 pandas.io.tests.test_excel.OpenpyxlTests.test_excel_roundtrip_indexname: openpyxl not installed, skipping
#21 pandas.io.tests.test_excel.OpenpyxlTests.test_excel_sheet_by_name_raise: openpyxl not installed, skipping
#22 pandas.io.tests.test_excel.OpenpyxlTests.test_int64: openpyxl not installed, skipping
#23 pandas.io.tests.test_excel.OpenpyxlTests.test_mixed: openpyxl not installed, skipping
#24 pandas.io.tests.test_excel.OpenpyxlTests.test_roundtrip: openpyxl not installed, skipping
#25 pandas.io.tests.test_excel.OpenpyxlTests.test_roundtrip_indexlabels: openpyxl not installed, skipping
#26 pandas.io.tests.test_excel.OpenpyxlTests.test_sheets: openpyxl not installed, skipping
#27 pandas.io.tests.test_excel.OpenpyxlTests.test_to_excel_float_format: openpyxl not installed, skipping
#28 pandas.io.tests.test_excel.OpenpyxlTests.test_to_excel_multiindex: openpyxl not installed, skipping
#29 pandas.io.tests.test_excel.OpenpyxlTests.test_to_excel_multiindex_dates: openpyxl not installed, skipping
#30 pandas.io.tests.test_excel.OpenpyxlTests.test_to_excel_periodindex: openpyxl not installed, skipping
#31 pandas.io.tests.test_excel.OpenpyxlTests.test_to_excel_styleconverter: openpyxl not installed, skipping
#32 pandas.io.tests.test_excel.OpenpyxlTests.test_to_excel_unicode_filename: openpyxl not installed, skipping
#33 pandas.io.tests.test_excel.OpenpyxlTests.test_tsframe: openpyxl not installed, skipping
--------------------------------------------------------------------------------
#34 pandas.io.tests.test_excel.XlwtTests.test_bool: xlwt not installed, skipping
#35 pandas.io.tests.test_excel.XlwtTests.test_colaliases: xlwt not installed, skipping
#36 pandas.io.tests.test_excel.XlwtTests.test_excel_010_hemstring: xlwt not installed, skipping
#37 pandas.io.tests.test_excel.XlwtTests.test_excel_roundtrip_datetime: xlwt not installed, skipping
#38 pandas.io.tests.test_excel.XlwtTests.test_excel_roundtrip_indexname: xlwt not installed, skipping
#39 pandas.io.tests.test_excel.XlwtTests.test_excel_sheet_by_name_raise: xlwt not installed, skipping
#40 pandas.io.tests.test_excel.XlwtTests.test_int64: xlwt not installed, skipping
#41 pandas.io.tests.test_excel.XlwtTests.test_mixed: xlwt not installed, skipping
#42 pandas.io.tests.test_excel.XlwtTests.test_roundtrip: xlwt not installed, skipping
#43 pandas.io.tests.test_excel.XlwtTests.test_roundtrip_indexlabels: xlwt not installed, skipping
#44 pandas.io.tests.test_excel.XlwtTests.test_sheets: xlwt not installed, skipping
#45 pandas.io.tests.test_excel.XlwtTests.test_to_excel_float_format: xlwt not installed, skipping
#46 pandas.io.tests.test_excel.XlwtTests.test_to_excel_multiindex: xlwt not installed, skipping
#47 pandas.io.tests.test_excel.XlwtTests.test_to_excel_multiindex_dates: xlwt not installed, skipping
#48 pandas.io.tests.test_excel.XlwtTests.test_to_excel_periodindex: xlwt not installed, skipping
#49 pandas.io.tests.test_excel.XlwtTests.test_to_excel_styleconverter: xlwt not installed, skipping
#50 pandas.io.tests.test_excel.XlwtTests.test_to_excel_unicode_filename: xlwt not installed, skipping
#51 pandas.io.tests.test_excel.XlwtTests.test_tsframe: xlwt not installed, skipping

@jmcnamara
Copy link
Contributor

@jtratner That looks good. It will make adding tests for new engines very clean and straightforward.

jtratner added a commit that referenced this pull request Sep 15, 2013
TST: Cleanup Excel tests to make it easier to add and test additional writers
@jtratner jtratner merged commit 8a06d22 into pandas-dev:master Sep 15, 2013
@jtratner jtratner deleted the cleanup-excel-tests branch September 15, 2013 22:27
@jmcnamara
Copy link
Contributor

@jtratner How do you set the writer engine from a subclass? Should it be set up via set_option() in a constructor and reset to the previous value in the destructor?

Or am I missing something more direct.

@jtratner
Copy link
Contributor Author

@jmcnamara oh...very good point. wasn't thinking, give me a second, I'll put in a patch for you so you can get it to work.

@jtratner
Copy link
Contributor Author

@jmcnamara you can just add it to your PR...not going to do a separate pull request.

@jtratner
Copy link
Contributor Author

You can run the following to get the patch below:

git remote add jtratner https://www.github.com/jtratner/pandas.git
git fetch jtratner
git checkout <insert-your-branch>
git cherry-pick 37db6b58eecb742d98b507224c8390d3faa9a994

Or you can copy it in yourself by saving this to a file and using git apply (less likely to work though if you've made changes to the file)

diff --git a/pandas/io/tests/test_excel.py b/pandas/io/tests/test_excel.py
index 0053602..047f10c 100644
--- a/pandas/io/tests/test_excel.py
+++ b/pandas/io/tests/test_excel.py
@@ -16,6 +16,7 @@ from pandas.io.excel import (
     register_writer
 )
 from pandas.util.testing import ensure_clean
+from pandas.core.config import set_option, get_option
 import pandas.util.testing as tm
 import pandas as pd

@@ -277,6 +278,12 @@ class ExcelWriterBase(SharedItems):
     def setUp(self):
         self.check_skip()
         super(ExcelWriterBase, self).setUp()
+        self.option_name = 'io.excel.%s.writer' % self.ext
+        self.prev_engine = get_option(self.option_name)
+        set_option(self.option_name, self.engine_name)
+
+    def tearDown(self):
+        set_option(self.option_name, self.prev_engine)

     def test_excel_sheet_by_name_raise(self):
         _skip_if_no_xlrd()
@@ -790,6 +797,7 @@ class ExcelWriterBase(SharedItems):

 class OpenpyxlTests(ExcelWriterBase, unittest.TestCase):
     ext = 'xlsx'
+    engine_name = 'openpyxl'
     check_skip = staticmethod(_skip_if_no_openpyxl)

     def test_to_excel_styleconverter(self):
@@ -820,6 +828,7 @@ class OpenpyxlTests(ExcelWriterBase, unittest.TestCase):

 class XlwtTests(ExcelWriterBase, unittest.TestCase):
     ext = 'xls'
+    engine_name = 'xlwt'
     check_skip = staticmethod(_skip_if_no_xlwt)

     def test_to_excel_styleconverter(self):

@jtratner
Copy link
Contributor Author

@jmcnamara so obviously, once you integrate, just set engine_name = 'xlsxwriter' and you should be good.

@jmcnamara
Copy link
Contributor

@jtratner Got it Jeff. Thanks.

Your refactoring work on this and excel.py really make adding new engines very easy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants