Skip to content

Commit 44cc50d

Browse files
authored
Fix test_88_character_filename_segmentation_fault (#2026)
* 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
1 parent 8e4231a commit 44cc50d

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

xarray/backends/netCDF4_.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,13 @@ def open(cls, filename, mode='r', format='NETCDF4', group=None,
264264
if (len(filename) == 88 and
265265
LooseVersion(nc4.__version__) < "1.3.1"):
266266
warnings.warn(
267-
'\nA segmentation fault may occur when the\n'
268-
'file path has exactly 88 characters as it does\n'
269-
'in this case. The issue is known to occur with\n'
270-
'version 1.2.4 of netCDF4 and can be addressed by\n'
271-
'upgrading netCDF4 to at least version 1.3.1.\n'
272-
'More details can be found here:\n'
273-
'https://github.com/pydata/xarray/issues/1745 \n')
267+
'A segmentation fault may occur when the '
268+
'file path has exactly 88 characters as it does '
269+
'in this case. The issue is known to occur with '
270+
'version 1.2.4 of netCDF4 and can be addressed by '
271+
'upgrading netCDF4 to at least version 1.3.1. '
272+
'More details can be found here: '
273+
'https://github.com/pydata/xarray/issues/1745')
274274
if format is None:
275275
format = 'NETCDF4'
276276
opener = functools.partial(_open_netcdf4_group, filename, mode=mode,

xarray/tests/test_backends.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,8 +1137,10 @@ def test_88_character_filename_segmentation_fault(self):
11371137
# should be fixed in netcdf4 v1.3.1
11381138
with mock.patch('netCDF4.__version__', '1.2.4'):
11391139
with warnings.catch_warnings():
1140-
warnings.simplefilter("error")
1141-
with raises_regex(Warning, 'segmentation fault'):
1140+
message = ('A segmentation fault may occur when the '
1141+
'file path has exactly 88 characters')
1142+
warnings.filterwarnings('error', message)
1143+
with pytest.raises(Warning):
11421144
# Need to construct 88 character filepath
11431145
xr.Dataset().to_netcdf('a' * (88 - len(os.getcwd()) - 1))
11441146

0 commit comments

Comments
 (0)