Skip to content

Commit

Permalink
Fix test_88_character_filename_segmentation_fault (#2026)
Browse files Browse the repository at this point in the history
* Fix test_88_character_filename_segmentation_fault

This test turning all warnings into errors. Now it's more robust, and only
converts the appropriate warning into an error.

Fixes GH2025

* Fix bad git merge
  • Loading branch information
shoyer authored Mar 30, 2018
1 parent 8e4231a commit 44cc50d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 7 additions & 7 deletions xarray/backends/netCDF4_.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,13 @@ def open(cls, filename, mode='r', format='NETCDF4', group=None,
if (len(filename) == 88 and
LooseVersion(nc4.__version__) < "1.3.1"):
warnings.warn(
'\nA segmentation fault may occur when the\n'
'file path has exactly 88 characters as it does\n'
'in this case. The issue is known to occur with\n'
'version 1.2.4 of netCDF4 and can be addressed by\n'
'upgrading netCDF4 to at least version 1.3.1.\n'
'More details can be found here:\n'
'https://github.com/pydata/xarray/issues/1745 \n')
'A segmentation fault may occur when the '
'file path has exactly 88 characters as it does '
'in this case. The issue is known to occur with '
'version 1.2.4 of netCDF4 and can be addressed by '
'upgrading netCDF4 to at least version 1.3.1. '
'More details can be found here: '
'https://github.com/pydata/xarray/issues/1745')
if format is None:
format = 'NETCDF4'
opener = functools.partial(_open_netcdf4_group, filename, mode=mode,
Expand Down
6 changes: 4 additions & 2 deletions xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -1137,8 +1137,10 @@ def test_88_character_filename_segmentation_fault(self):
# should be fixed in netcdf4 v1.3.1
with mock.patch('netCDF4.__version__', '1.2.4'):
with warnings.catch_warnings():
warnings.simplefilter("error")
with raises_regex(Warning, 'segmentation fault'):
message = ('A segmentation fault may occur when the '
'file path has exactly 88 characters')
warnings.filterwarnings('error', message)
with pytest.raises(Warning):
# Need to construct 88 character filepath
xr.Dataset().to_netcdf('a' * (88 - len(os.getcwd()) - 1))

Expand Down

0 comments on commit 44cc50d

Please sign in to comment.