From 12cae22e5fabd27eeb9d2c91fbc1e52907c96258 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Thu, 13 Sep 2018 08:24:14 -0500 Subject: [PATCH] TST: Close ZipFile in compression test (#22679) * Updates HypothesisCheck setting * Skips tests for old xlrd --- pandas/conftest.py | 11 +++++++---- pandas/tests/io/test_excel.py | 6 ++++++ pandas/tests/io/test_pickle.py | 8 ++++---- pandas/util/testing.py | 4 ++-- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index fdac045e67ffa7..28c24fc8c0640b 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -8,11 +8,14 @@ import pandas as pd from pandas.compat import PY3 import pandas.util._test_decorators as td - import hypothesis -hypothesis.settings.suppress_health_check = (hypothesis.HealthCheck.too_slow,) -# HealthCheck.all() to disable all health checks -# https://hypothesis.readthedocs.io/en/latest/healthchecks.html + + +hypothesis.settings.register_profile( + "ci", + suppress_health_check=(hypothesis.HealthCheck.too_slow,) +) +hypothesis.settings.load_profile("ci") def pytest_addoption(parser): diff --git a/pandas/tests/io/test_excel.py b/pandas/tests/io/test_excel.py index 5f27ff719fda1e..6741645e466f32 100644 --- a/pandas/tests/io/test_excel.py +++ b/pandas/tests/io/test_excel.py @@ -105,6 +105,7 @@ def get_exceldf(self, basename, ext, *args, **kwds): class ReadingTestsBase(SharedItems): # This is based on ExcelWriterBase + @td.skip_if_no('xlrd', '1.0.1') # GH-22682 def test_usecols_int(self, ext): dfref = self.get_csv_refdf('test1') @@ -122,6 +123,7 @@ def test_usecols_int(self, ext): tm.assert_frame_equal(df2, dfref, check_names=False) tm.assert_frame_equal(df3, dfref, check_names=False) + @td.skip_if_no('xlrd', '1.0.1') # GH-22682 def test_usecols_list(self, ext): dfref = self.get_csv_refdf('test1') @@ -140,6 +142,7 @@ def test_usecols_list(self, ext): tm.assert_frame_equal(df2, dfref, check_names=False) tm.assert_frame_equal(df3, dfref, check_names=False) + @td.skip_if_no('xlrd', '1.0.1') # GH-22682 def test_usecols_str(self, ext): dfref = self.get_csv_refdf('test1') @@ -219,6 +222,7 @@ def test_excel_passes_na(self, ext): columns=['Test']) tm.assert_frame_equal(parsed, expected) + @td.skip_if_no('xlrd', '1.0.1') # GH-22682 def test_deprecated_sheetname(self, ext): # gh-17964 excel = self.get_excelfile('test1', ext) @@ -229,6 +233,7 @@ def test_deprecated_sheetname(self, ext): with pytest.raises(TypeError): read_excel(excel, sheet='Sheet1') + @td.skip_if_no('xlrd', '1.0.1') # GH-22682 def test_excel_table_sheet_by_index(self, ext): excel = self.get_excelfile('test1', ext) @@ -507,6 +512,7 @@ def test_date_conversion_overflow(self, ext): result = self.get_exceldf('testdateoverflow', ext) tm.assert_frame_equal(result, expected) + @td.skip_if_no('xlrd', '1.0.1') # GH-22682 def test_sheet_name_and_sheetname(self, ext): # GH10559: Minor improvement: Change "sheet_name" to "sheetname" # GH10969: DOC: Consistent var names (sheetname vs sheet_name) diff --git a/pandas/tests/io/test_pickle.py b/pandas/tests/io/test_pickle.py index c71e26ae56e8e6..77b4a3c7cac5ff 100644 --- a/pandas/tests/io/test_pickle.py +++ b/pandas/tests/io/test_pickle.py @@ -332,9 +332,9 @@ def compress_file(self, src_path, dest_path, compression): f = bz2.BZ2File(dest_path, "w") elif compression == 'zip': import zipfile - zip_file = zipfile.ZipFile(dest_path, "w", - compression=zipfile.ZIP_DEFLATED) - zip_file.write(src_path, os.path.basename(src_path)) + f = zipfile.ZipFile(dest_path, "w", + compression=zipfile.ZIP_DEFLATED) + f.write(src_path, os.path.basename(src_path)) elif compression == 'xz': lzma = pandas.compat.import_lzma() f = lzma.LZMAFile(dest_path, "w") @@ -345,7 +345,7 @@ def compress_file(self, src_path, dest_path, compression): if compression != "zip": with open(src_path, "rb") as fh: f.write(fh.read()) - f.close() + f.close() def test_write_explicit(self, compression, get_random_path): base = get_random_path diff --git a/pandas/util/testing.py b/pandas/util/testing.py index f785ec35f52dbf..1e8c123fa6f132 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -2560,7 +2560,7 @@ class for all warnings. To check that no warning is returned, the ``__warningsregistry__`` to ensure that no warning messages are suppressed by this context manager. If ``None`` is specified, the ``__warningsregistry__`` keeps track of which warnings have been - shown, and does not show them again. + shown, and does not show them again. check_stacklevel : bool, default True If True, displays the line that called the function containing the warning to show were the function is called. Otherwise, the @@ -2589,7 +2589,7 @@ class for all warnings. To check that no warning is returned, with warnings.catch_warnings(record=True) as w: if clear is not None: - # make sure that we are clearning these warnings + # make sure that we are clearing these warnings # if they have happened before # to guarantee that we will catch them if not is_list_like(clear):