From 57d33249c233afc6cc0d71f88e16398eb0406f70 Mon Sep 17 00:00:00 2001 From: "Phillip J. Wolfram" Date: Sun, 2 Apr 2017 22:26:23 -0600 Subject: [PATCH] Try fix: Closes open file (for Windows error) ``` WindowsError: [Error 32] The process cannot access the file because it is being used by another process ``` --- xarray/tests/test_backends.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index 091d66794e5..0e73b710663 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -120,8 +120,8 @@ def test_write_store(self): expected.dump_to_store(store) # we need to cf decode the store because it has time and # non-dimension coordinates - actual = xr.decode_cf(store) - self.assertDatasetAllClose(expected, actual) + with xr.decode_cf(store) as actual: + self.assertDatasetAllClose(expected, actual) def check_dtypes_roundtripped(self, expected, actual): for k in expected: @@ -1044,10 +1044,9 @@ def test_read_byte_attrs_as_unicode(self): with create_tmp_file() as tmp_file: with nc4.Dataset(tmp_file, 'w') as nc: nc.foo = b'bar' - actual = open_dataset(tmp_file) - expected = Dataset(attrs={'foo': 'bar'}) - self.assertDatasetIdentical(expected, actual) - actual.close() + with open_dataset(tmp_file) as actual: + expected = Dataset(attrs={'foo': 'bar'}) + self.assertDatasetIdentical(expected, actual) def test_encoding_unlimited_dims(self): ds = Dataset({'x': ('y', np.arange(10.0))})