Skip to content

Commit 81ed8f4

Browse files
authored
Open netcdf grid using with statement
So that the file is closed properly for deletion later.
1 parent 0514bf0 commit 81ed8f4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

pygmt/tests/test_surface.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ def test_surface_with_outfile_param():
9090
)
9191
assert output is None # check that output is None since outfile is set
9292
assert os.path.exists(path=TEMP_GRID) # check that outfile exists at path
93-
grid = xr.open_dataarray(TEMP_GRID)
94-
assert isinstance(grid, xr.DataArray) # check that netcdf grid loaded properly
93+
with xr.open_dataarray(TEMP_GRID) as grid:
94+
assert isinstance(grid, xr.DataArray) # ensure netcdf grid loads ok
9595
finally:
9696
os.remove(path=TEMP_GRID)
9797
return output
@@ -108,8 +108,8 @@ def test_surface_short_aliases():
108108
output = surface(data=data, I="5m", R=[245, 255, 20, 30], G=TEMP_GRID)
109109
assert output is None # check that output is None since outfile is set
110110
assert os.path.exists(path=TEMP_GRID) # check that outfile exists at path
111-
grid = xr.open_dataarray(TEMP_GRID)
112-
assert isinstance(grid, xr.DataArray) # check that netcdf grid loaded properly
111+
with xr.open_dataarray(TEMP_GRID) as grid:
112+
assert isinstance(grid, xr.DataArray) # ensure netcdf grid loads ok
113113
finally:
114114
os.remove(path=TEMP_GRID)
115115
return output

0 commit comments

Comments
 (0)