Skip to content

Commit

Permalink
Merge dataset-independent tests into a separate test file (#2690)
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman authored Sep 15, 2023
1 parent 594d3f1 commit 1e48454
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 299 deletions.
38 changes: 0 additions & 38 deletions pygmt/tests/test_datasets_earth_age.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,7 @@
"""
import numpy as np
import numpy.testing as npt
import pytest
from pygmt.datasets import load_earth_age
from pygmt.exceptions import GMTInvalidInput


def test_earth_age_fails():
"""
Make sure earth_age fails for invalid resolutions.
"""
resolutions = "1m 1d bla 60d 001m 03".split()
resolutions.append(60)
for resolution in resolutions:
with pytest.raises(GMTInvalidInput):
load_earth_age(resolution=resolution)


def test_earth_age_incorrect_registration():
"""
Test loading earth_age with incorrect registration type.
"""
with pytest.raises(GMTInvalidInput):
load_earth_age(registration="improper_type")


def test_earth_age_01d():
Expand Down Expand Up @@ -57,23 +36,6 @@ def test_earth_age_01d_with_region():
npt.assert_allclose(data.max(), 125.12, atol=0.01)


def test_earth_age_01m_without_region():
"""
Test loading high-resolution earth age without passing 'region'.
"""
with pytest.raises(GMTInvalidInput):
load_earth_age("01m")


def test_earth_age_incorrect_resolution_registration():
"""
Test that an error is raised when trying to load a grid registration with
an unavailable resolution.
"""
with pytest.raises(GMTInvalidInput):
load_earth_age(resolution="01m", region=[0, 1, 3, 5], registration="pixel")


def test_earth_age_01m_default_registration():
"""
Test that the grid returned by default for the 1 arc-minute resolution has
Expand Down
30 changes: 0 additions & 30 deletions pygmt/tests/test_datasets_earth_free_air_anomaly.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,7 @@
"""
import numpy as np
import numpy.testing as npt
import pytest
from pygmt.datasets import load_earth_free_air_anomaly
from pygmt.exceptions import GMTInvalidInput


def test_earth_faa_fails():
"""
Make sure earth_free_air_anomaly fails for invalid resolutions.
"""
resolutions = "1m 1d bla 60d 001m 03".split()
resolutions.append(60)
for resolution in resolutions:
with pytest.raises(GMTInvalidInput):
load_earth_free_air_anomaly(resolution=resolution)


def test_earth_faa_incorrect_registration():
"""
Test loading earth_free_air_anomaly with incorrect registration type.
"""
with pytest.raises(GMTInvalidInput):
load_earth_free_air_anomaly(registration="improper_type")


def test_earth_faa_01d():
Expand Down Expand Up @@ -57,15 +36,6 @@ def test_earth_faa_01d_with_region():
npt.assert_allclose(data.max(), 69.975, atol=0.025)


def test_earth_faa_01m_without_region():
"""
Test loading high-resolution earth free air anomaly without passing
'region'.
"""
with pytest.raises(GMTInvalidInput):
load_earth_free_air_anomaly("01m")


def test_earth_faa_01m_default_registration():
"""
Test that the grid returned by default for the 1 arc-minute resolution has
Expand Down
38 changes: 0 additions & 38 deletions pygmt/tests/test_datasets_earth_geoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,7 @@
"""
import numpy as np
import numpy.testing as npt
import pytest
from pygmt.datasets import load_earth_geoid
from pygmt.exceptions import GMTInvalidInput


def test_earth_geoid_fails():
"""
Make sure load_earth_geoid fails for invalid resolutions.
"""
resolutions = "1m 1d bla 60d 001m 03".split()
resolutions.append(60)
for resolution in resolutions:
with pytest.raises(GMTInvalidInput):
load_earth_geoid(resolution=resolution)


def test_earth_geoid_incorrect_registration():
"""
Test loading load_earth_geoid with incorrect registration type.
"""
with pytest.raises(GMTInvalidInput):
load_earth_geoid(registration="improper_type")


def test_earth_geoid_01d():
Expand Down Expand Up @@ -57,23 +36,6 @@ def test_earth_geoid_01d_with_region():
npt.assert_allclose(data.max(), 29.89, atol=0.01)


def test_earth_geoid_01m_without_region():
"""
Test loading high-resolution earth geoid without passing 'region'.
"""
with pytest.raises(GMTInvalidInput):
load_earth_geoid("01m")


def test_earth_geoid_incorrect_resolution_registration():
"""
Test that an error is raised when trying to load a grid registration with
an unavailable resolution.
"""
with pytest.raises(GMTInvalidInput):
load_earth_geoid(resolution="01m", region=[0, 1, 3, 5], registration="pixel")


def test_earth_geoid_01m_default_registration():
"""
Test that the grid returned by default for the 1 arc-minute resolution has
Expand Down
66 changes: 0 additions & 66 deletions pygmt/tests/test_datasets_earth_magnetic_anomaly.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,6 @@
from pygmt.exceptions import GMTInvalidInput


def test_earth_mag_fails():
"""
Make sure earth_magnetic_anomaly fails for invalid resolutions.
"""
resolutions = "1m 1d bla 60d 001m 03".split()
resolutions.append(60)
for resolution in resolutions:
with pytest.raises(GMTInvalidInput):
load_earth_magnetic_anomaly(resolution=resolution)


def test_earth_mag_incorrect_registration():
"""
Test loading earth_magnetic_anomaly with incorrect registration type.
"""
with pytest.raises(GMTInvalidInput):
load_earth_magnetic_anomaly(registration="improper_type")


def test_earth_mag_01d():
"""
Test some properties of the magnetic anomaly 01d data.
Expand Down Expand Up @@ -57,29 +38,6 @@ def test_earth_mag_01d_with_region():
npt.assert_allclose(data.max(), 127.4, atol=0.2)


def test_earth_mag_02m_without_region():
"""
Test loading high-resolution earth magnetic anomaly without passing
'region'.
"""
with pytest.raises(GMTInvalidInput):
load_earth_magnetic_anomaly("02m")


def test_earth_mag_incorrect_resolution_registration():
"""
Test that an error is raised when trying to load a EMAG2 grid registration
with an unavailable resolution.
"""
with pytest.raises(GMTInvalidInput):
load_earth_magnetic_anomaly(
resolution="02m",
region=[0, 1, 3, 5],
registration="gridline",
data_source="emag2_4km",
)


def test_earth_mag_02m_default_registration():
"""
Test that the grid returned by default for the 2 arc-minute resolution has
Expand Down Expand Up @@ -202,30 +160,6 @@ def test_earth_mag_03m_wdmam_with_region():
npt.assert_allclose(data.max(), 528.0, atol=0.2)


def test_earth_mag_03m_wdmam_without_region():
"""
Test loading a high-resolution WDMAM grid without passing 'region'.
"""
with pytest.raises(GMTInvalidInput):
load_earth_magnetic_anomaly(
resolution="03m", registration="gridline", data_source="wdmam"
)


def test_earth_mag_wdmam_incorrect_resolution_registration():
"""
Test that an error is raised when trying to load a WDMAM grid registration
with an unavailable resolution.
"""
with pytest.raises(GMTInvalidInput):
load_earth_magnetic_anomaly(
resolution="03m",
region=[0, 1, 3, 5],
registration="pixel",
data_source="wdmam",
)


def test_earth_mag_data_source_error():
"""
Test that an error is raised when an invalid argument is passed to
Expand Down
21 changes: 0 additions & 21 deletions pygmt/tests/test_datasets_earth_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,7 @@
"""
import numpy as np
import numpy.testing as npt
import pytest
from pygmt.datasets import load_earth_mask
from pygmt.exceptions import GMTInvalidInput


def test_earth_mask_fails():
"""
Make sure load_earth_mask fails for invalid resolutions.
"""
resolutions = "1m 1d bla 60d 001m 03".split()
resolutions.append(60)
for resolution in resolutions:
with pytest.raises(GMTInvalidInput):
load_earth_mask(resolution=resolution)


def test_earth_mask_incorrect_registration():
"""
Test loading load_earth_mask with incorrect registration type.
"""
with pytest.raises(GMTInvalidInput):
load_earth_mask(registration="improper_type")


def test_earth_mask_01d():
Expand Down
64 changes: 0 additions & 64 deletions pygmt/tests/test_datasets_earth_relief.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@
from pygmt.exceptions import GMTInvalidInput


@pytest.mark.parametrize("data_source", ["igpp", "gebco", "gebcosi", "synbath"])
def test_earth_relief_fails(data_source):
"""
Make sure earth relief fails for invalid resolutions.
"""
resolutions = "1m 1d bla 60d 001m 03".split()
resolutions.append(60)
for resolution in resolutions:
with pytest.raises(GMTInvalidInput):
load_earth_relief(resolution=resolution, data_source=data_source)


# Only test 01d and 30m to avoid downloading large datasets in CI
@pytest.mark.parametrize("data_source", ["igpp", "synbath"])
def test_earth_relief_01d_igpp_synbath(data_source):
Expand Down Expand Up @@ -140,14 +128,6 @@ def test_earth_relief_30s_synbath():
npt.assert_allclose(data.max(), -2257.5, atol=0.5)


def test_earth_relief_01m_without_region():
"""
Test loading high-resolution earth relief without passing 'region'.
"""
with pytest.raises(GMTInvalidInput):
load_earth_relief("01m")


def test_earth_relief_03s_landonly_srtm():
"""
Test loading original 3 arc-seconds land-only SRTM tiles.
Expand All @@ -167,28 +147,6 @@ def test_earth_relief_03s_landonly_srtm():
assert data.sizes["lon"] == 1201


def test_earth_relief_incorrect_registration():
"""
Test loading earth relief with incorrect registration type.
"""
with pytest.raises(GMTInvalidInput):
load_earth_relief(registration="improper_type")


def test_earth_relief_invalid_resolution_registration_combination():
"""
Test loading earth relief with invalid combination of resolution and
registration.
"""
for resolution, registration in [
("15s", "gridline"),
("03s", "pixel"),
("01s", "pixel"),
]:
with pytest.raises(GMTInvalidInput):
load_earth_relief(resolution=resolution, registration=registration)


def test_earth_relief_invalid_data_source():
"""
Test loading earth relief with invalid data_source argument.
Expand All @@ -214,28 +172,6 @@ def test_earth_relief_invalid_data_source_with_use_srtm():
)


@pytest.mark.parametrize("data_source", ["igpp", "gebco", "gebcosi", "synbath"])
def test_earth_relief_incorrect_resolution_registration(data_source):
"""
Test that an error is raised when trying to load a grid registration with
an unavailable resolution.
"""
with pytest.raises(GMTInvalidInput):
load_earth_relief(
resolution="03s",
region=[0, 1, 3, 5],
registration="pixel",
data_source=data_source,
)
with pytest.raises(GMTInvalidInput):
load_earth_relief(
resolution="15s",
region=[0, 1, 3, 5],
registration="gridline",
data_source=data_source,
)


def test_earth_relief_15s_default_registration():
"""
Test that the grid returned by default for the 15 arc-second resolution has
Expand Down
Loading

0 comments on commit 1e48454

Please sign in to comment.