From b9774f4753a83b904dca7b4c4254ae876f0cc4d6 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 12 Feb 2022 09:18:09 +0000 Subject: [PATCH 1/3] add fixture to test_grdinfo.py, switch sample grid to use static_earth_relief --- pygmt/tests/test_grdinfo.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/pygmt/tests/test_grdinfo.py b/pygmt/tests/test_grdinfo.py index 71612b459da..399b0e1d71e 100644 --- a/pygmt/tests/test_grdinfo.py +++ b/pygmt/tests/test_grdinfo.py @@ -4,25 +4,31 @@ import numpy as np import pytest from pygmt import grdinfo -from pygmt.datasets import load_earth_relief +from pygmt.helpers.testing import load_static_earth_relief from pygmt.exceptions import GMTInvalidInput -def test_grdinfo(): +@pytest.fixture(scope="module", name="grid") +def fixture_grid(): + """ + Load the grid data from the static_earth_relief file. + """ + return load_static_earth_relief() + +def test_grdinfo(grid): """ Make sure grdinfo works as expected. """ - grid = load_earth_relief(registration="gridline") result = grdinfo(grid=grid, force_scan=0, per_column="n") - assert result.strip() == "-180 180 -90 90 -8592.5 5559 1 1 361 181 0 1" + assert result.strip() == "-55 -47 -24 -10 190 981 1 1 8 14 1 1" def test_grdinfo_file(): """ Test grdinfo with file input. """ - result = grdinfo(grid="@earth_relief_01d", force_scan=0, per_column="n") - assert result.strip() == "-180 180 -90 90 -8182 5651.5 1 1 360 180 1 1" + result = grdinfo(grid="@static_earth_relief.nc", force_scan=0, per_column="n") + assert result.strip() == "-55 -47 -24 -10 190 981 1 1 8 14 1 1" def test_grdinfo_fails(): @@ -33,14 +39,9 @@ def test_grdinfo_fails(): grdinfo(np.arange(10).reshape((5, 2))) -def test_grdinfo_region(): +def test_grdinfo_region(grid): """ Check that the region argument works in grdinfo. """ - result = grdinfo( - grid="@earth_relief_01d", - force_scan=0, - per_column="n", - region=[-170, 170, -80, 80], - ) - assert result.strip() == "-170 170 -80 80 -8182 5651.5 1 1 340 160 1 1" + result = grdinfo(grid=grid, force_scan=0, per_column="n", region=[-54, -50, -23, -20]) + assert result.strip() == "-54 -50 -23 -20 284.5 491 1 1 4 3 1 1" From ddf3346bb1f7a27063d0557068c9cb4c955897e7 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 12 Feb 2022 09:18:27 +0000 Subject: [PATCH 2/3] remove test_grdinfo_file() --- pygmt/tests/test_grdinfo.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pygmt/tests/test_grdinfo.py b/pygmt/tests/test_grdinfo.py index 399b0e1d71e..ca98ebe8605 100644 --- a/pygmt/tests/test_grdinfo.py +++ b/pygmt/tests/test_grdinfo.py @@ -23,14 +23,6 @@ def test_grdinfo(grid): assert result.strip() == "-55 -47 -24 -10 190 981 1 1 8 14 1 1" -def test_grdinfo_file(): - """ - Test grdinfo with file input. - """ - result = grdinfo(grid="@static_earth_relief.nc", force_scan=0, per_column="n") - assert result.strip() == "-55 -47 -24 -10 190 981 1 1 8 14 1 1" - - def test_grdinfo_fails(): """ Check that grdinfo fails correctly. From 6a84d8f73491020a8a96caf3463ced8f17cff7fc Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 12 Feb 2022 09:19:01 +0000 Subject: [PATCH 3/3] run make format --- pygmt/tests/test_grdinfo.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pygmt/tests/test_grdinfo.py b/pygmt/tests/test_grdinfo.py index ca98ebe8605..f58107ad123 100644 --- a/pygmt/tests/test_grdinfo.py +++ b/pygmt/tests/test_grdinfo.py @@ -4,8 +4,8 @@ import numpy as np import pytest from pygmt import grdinfo -from pygmt.helpers.testing import load_static_earth_relief from pygmt.exceptions import GMTInvalidInput +from pygmt.helpers.testing import load_static_earth_relief @pytest.fixture(scope="module", name="grid") @@ -15,6 +15,7 @@ def fixture_grid(): """ return load_static_earth_relief() + def test_grdinfo(grid): """ Make sure grdinfo works as expected. @@ -35,5 +36,7 @@ def test_grdinfo_region(grid): """ Check that the region argument works in grdinfo. """ - result = grdinfo(grid=grid, force_scan=0, per_column="n", region=[-54, -50, -23, -20]) + result = grdinfo( + grid=grid, force_scan=0, per_column="n", region=[-54, -50, -23, -20] + ) assert result.strip() == "-54 -50 -23 -20 284.5 491 1 1 4 3 1 1"