Skip to content

Commit

Permalink
TST: Close ZipFile in compression test (pandas-dev#22679)
Browse files Browse the repository at this point in the history
* Updates HypothesisCheck setting
* Skips tests for old xlrd
  • Loading branch information
TomAugspurger authored and victor committed Sep 30, 2018
1 parent ab6b17b commit 12cae22
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
11 changes: 7 additions & 4 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/io/test_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/io/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 12cae22

Please sign in to comment.