Skip to content

Commit

Permalink
Open netcdf grid using with statement
Browse files Browse the repository at this point in the history
So that the file is closed properly for deletion later.
  • Loading branch information
weiji14 authored May 20, 2020
1 parent 0514bf0 commit 81ed8f4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pygmt/tests/test_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def test_surface_with_outfile_param():
)
assert output is None # check that output is None since outfile is set
assert os.path.exists(path=TEMP_GRID) # check that outfile exists at path
grid = xr.open_dataarray(TEMP_GRID)
assert isinstance(grid, xr.DataArray) # check that netcdf grid loaded properly
with xr.open_dataarray(TEMP_GRID) as grid:
assert isinstance(grid, xr.DataArray) # ensure netcdf grid loads ok
finally:
os.remove(path=TEMP_GRID)
return output
Expand All @@ -108,8 +108,8 @@ def test_surface_short_aliases():
output = surface(data=data, I="5m", R=[245, 255, 20, 30], G=TEMP_GRID)
assert output is None # check that output is None since outfile is set
assert os.path.exists(path=TEMP_GRID) # check that outfile exists at path
grid = xr.open_dataarray(TEMP_GRID)
assert isinstance(grid, xr.DataArray) # check that netcdf grid loaded properly
with xr.open_dataarray(TEMP_GRID) as grid:
assert isinstance(grid, xr.DataArray) # ensure netcdf grid loads ok
finally:
os.remove(path=TEMP_GRID)
return output

0 comments on commit 81ed8f4

Please sign in to comment.