Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor xfail tests to avoid storing baseline images #603

Merged
merged 10 commits into from
Oct 15, 2020
Merged
15 changes: 8 additions & 7 deletions pygmt/tests/test_basemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

from .. import Figure
from ..helpers.testing import check_figures_equal
from ..exceptions import GMTInvalidInput


Expand Down Expand Up @@ -54,15 +55,15 @@ def test_basemap_power_axis():
return fig


@pytest.mark.xfail(
reason="Baseline image not updated to use earth relief grid in GMT 6.1.0",
)
@pytest.mark.mpl_image_compare
@check_figures_equal()
def test_basemap_polar():
"Create a polar basemap plot"
fig = Figure()
fig.basemap(R="0/360/0/1000", J="P6i", B="afg")
return fig
fig_ref, fig_test = Figure(), Figure()
# Use single-character arguments for the reference image
fig_ref.basemap(R="0/360/0/1000", J="P6i", B="afg")
fig_test.basemap(region=[0, 360, 0, 1000], projection="P6i", frame="afg")

return fig_ref, fig_test


@pytest.mark.mpl_image_compare
Expand Down
16 changes: 9 additions & 7 deletions pygmt/tests/test_coast.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

from .. import Figure
from ..helpers.testing import check_figures_equal


@pytest.mark.mpl_image_compare
Expand All @@ -25,15 +26,16 @@ def test_coast():
return fig


@pytest.mark.xfail(
reason="Baseline image not updated to use earth relief grid in GMT 6.1.0",
)
@pytest.mark.mpl_image_compare
@check_figures_equal()
def test_coast_iceland():
"Test passing in R as a list"
fig = Figure()
fig.coast(R=[-30, -10, 60, 65], J="m1c", B=True, G="p28+r100")
return fig
fig_ref, fig_test = Figure(), Figure()
# Use single-character arguments for the reference image
fig_ref.coast(R="-30/-10/60/65", J="m1c", B="", G="p28+r100")
fig_test.coast(
region=[-30, -10, 60, 65], projection="m1c", frame=True, land="p28+r100"
)
return fig_ref, fig_test


@pytest.mark.mpl_image_compare
Expand Down
18 changes: 10 additions & 8 deletions pygmt/tests/test_colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

from .. import Figure
from ..helpers.testing import check_figures_equal


@pytest.mark.mpl_image_compare
Expand Down Expand Up @@ -37,18 +38,19 @@ def test_colorbar_positioned_using_map_coordinates():
return fig


@pytest.mark.xfail(
reason="Baseline image not updated to use earth relief grid in GMT 6.1.0",
)
@pytest.mark.mpl_image_compare
@check_figures_equal()
def test_colorbar_positioned_using_justification_code():
"""
Create colorbar at Top Center inside the map frame with length 2cm.
"""
fig = Figure()
fig.basemap(region=[2, 4, 6, 8], projection="t0/2c", frame=True)
fig.colorbar(cmap="rainbow", position="jTC+w2c")
return fig
fig_ref, fig_test = Figure(), Figure()
# Use single-character arguments for the reference image
fig_ref.basemap(R="2/4/6/8", J="t0/2c", B="")
fig_ref.colorbar(C="rainbow", D="jTC+w2c")

fig_test.basemap(region=[2, 4, 6, 8], projection="t0/2c", frame=True)
fig_test.colorbar(cmap="rainbow", position="jTC+w2c")
return fig_ref, fig_test


@pytest.mark.mpl_image_compare
Expand Down
30 changes: 20 additions & 10 deletions pygmt/tests/test_grdcontour.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,36 @@ def test_grdcontour_file():
return fig


@pytest.mark.xfail(
reason="Baseline image not updated to use earth relief grid in GMT 6.1.0",
)
@pytest.mark.mpl_image_compare
@check_figures_equal()
def test_grdcontour_interval_file_full_opts():
""" Plot based on external contour level file """
fig = Figure()
comargs = {
fig_ref, fig_test = Figure(), Figure()
# Use single-character arguments for the reference image
comargs_ref = {
"grid": "@earth_relief_10m",
"R": "-161.5/-154/18.5/23",
"C": TEST_CONTOUR_FILE,
"S": 100,
"J": "M6i",
"Q": 10,
}
fig_ref.grdcontour(**comargs_ref, L="-25000/-1", W=["a1p,blue", "c0.5p,blue"])
fig_ref.grdcontour(**comargs_ref, L="0", W=["a1p,black", "c0.5p,black"])

comargs_test = {
"region": [-161.5, -154, 18.5, 23],
"interval": TEST_CONTOUR_FILE,
"grid": "@earth_relief_10m",
"resample": "100",
"projection": "M6i",
"cut": 10,
}
fig_test.grdcontour(
**comargs_test, limit=(-25000, -1), pen=["a1p,blue", "c0.5p,blue"]
)
fig_test.grdcontour(**comargs_test, limit="0", pen=["a1p,black", "c0.5p,black"])
seisman marked this conversation as resolved.
Show resolved Hide resolved

fig.grdcontour(**comargs, limit=(-25000, -1), pen=["a1p,blue", "c0.5p,blue"])

fig.grdcontour(**comargs, limit="0", pen=["a1p,black", "c0.5p,black"])
return fig
return fig_ref, fig_test


def test_grdcontour_fails():
Expand Down
39 changes: 25 additions & 14 deletions pygmt/tests/test_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .. import Figure
from ..exceptions import GMTInvalidInput
from ..helpers import GMTTempFile
from ..helpers.testing import check_figures_equal


@pytest.mark.mpl_image_compare
Expand Down Expand Up @@ -44,32 +45,42 @@ def test_legend_default_position():
return fig


@pytest.mark.xfail(
reason="Baseline image not updated to use earth relief grid in GMT 6.1.0",
)
@pytest.mark.mpl_image_compare
@check_figures_equal()
def test_legend_entries():
"""
Test different marker types/shapes.
"""
fig_ref, fig_test = Figure(), Figure()

fig = Figure()

fig.basemap(projection="x1i", region=[0, 7, 3, 7], frame=True)
# Use single-character arguments for the reference image
fig_ref = Figure()
fig_ref.basemap(J="x1i", R="0/7/3/7", B="")
fig_ref.plot(
data="@Table_5_11.txt",
S="c0.15i",
G="lightgreen",
W="faint",
l="Apples",
)
fig_ref.plot(data="@Table_5_11.txt", W="1.5p,gray", l='"My lines"')
fig_ref.plot(data="@Table_5_11.txt", S="t0.15i", G="orange", l="Oranges")
fig_ref.legend(D="JTR+jTR")

fig.plot(
fig_test.basemap(projection="x1i", region=[0, 7, 3, 7], frame=True)
fig_test.plot(
data="@Table_5_11.txt",
style="c0.15i",
color="lightgreen",
pen="faint",
l="Apples",
label="Apples",
)
fig.plot(data="@Table_5_11.txt", pen="1.5p,gray", label='"My lines"')
fig.plot(data="@Table_5_11.txt", style="t0.15i", color="orange", label="Oranges")

fig.legend(position="JTR+jTR")
fig_test.plot(data="@Table_5_11.txt", pen="1.5p,gray", label='"My lines"')
fig_test.plot(
data="@Table_5_11.txt", style="t0.15i", color="orange", label="Oranges"
)
fig_test.legend(position="JTR+jTR")

return fig
return fig_ref, fig_test


@pytest.mark.mpl_image_compare
Expand Down
27 changes: 18 additions & 9 deletions pygmt/tests/test_logo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,32 @@

from .. import Figure
from ..exceptions import GMTInvalidInput
from ..helpers.testing import check_figures_equal


@pytest.mark.mpl_image_compare
@check_figures_equal()
def test_logo():
"Plot a GMT logo of a 2 inch width as a stand-alone plot"
fig = Figure()
fig.logo(D="x0/0+w2i")
return fig
fig_ref, fig_test = Figure(), Figure()
# Use single-character arguments for the reference image
fig_ref.logo(D="x0/0+w2i")
fig_test.logo(position="x0/0+w2i")
return fig_ref, fig_test


@pytest.mark.mpl_image_compare
@check_figures_equal()
def test_logo_on_a_map():
"Plot a GMT logo in the upper right corner of a map"
fig = Figure()
fig.coast(region=[-90, -70, 0, 20], projection="M6i", land="chocolate", frame=True)
fig.logo(D="jTR+o0.1i/0.1i+w3i", F=True)
return fig
fig_ref, fig_test = Figure(), Figure()
# Use single-character arguments for the reference image
fig_ref.coast(R="-90/-70/0/20", J="M6i", G="chocolate", B="")
fig_ref.logo(D="jTR+o0.1i/0.1i+w3i", F="")

fig_test.coast(
region=[-90, -70, 0, 20], projection="M6i", land="chocolate", frame=True
)
fig_test.logo(position="jTR+o0.1i/0.1i+w3i", box=True)
return fig_ref, fig_test


def test_logo_fails():
Expand Down
17 changes: 10 additions & 7 deletions pygmt/tests/test_makecpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from ..datasets import load_earth_relief
from ..exceptions import GMTInvalidInput
from ..helpers import GMTTempFile
from ..helpers.testing import check_figures_equal

TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "data")
POINTS_DATA = os.path.join(TEST_DATA_DIR, "points.txt")
Expand Down Expand Up @@ -62,19 +63,21 @@ def test_makecpt_to_plot_grid(grid):
return fig


@pytest.mark.xfail(
reason="Baseline image not updated to use earth relief grid in GMT 6.1.0",
)
@pytest.mark.mpl_image_compare
@check_figures_equal()
def test_makecpt_to_plot_grid_scaled_with_series(grid):
"""
Use static color palette table scaled to a min/max series to change color
of grid
"""
fig = Figure()
# Use single-character arguments for the reference image
fig_ref = Figure()
makecpt(C="oleron", T="-4500/4500")
fig_ref.grdimage(grid, J="W0/6i")

fig_test = Figure()
makecpt(cmap="oleron", series="-4500/4500")
fig.grdimage(grid, projection="W0/6i")
return fig
fig_test.grdimage(grid, projection="W0/6i")
return fig_ref, fig_test


def test_makecpt_output_to_cpt_file():
Expand Down
19 changes: 15 additions & 4 deletions pygmt/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from .. import Figure
from ..exceptions import GMTInvalidInput
from ..helpers.testing import check_figures_equal


TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "data")
Expand Down Expand Up @@ -126,11 +127,21 @@ def test_plot_projection(data):
return fig


@pytest.mark.mpl_image_compare
@check_figures_equal()
def test_plot_colors(data, region):
"Plot the data using z as sizes"
fig = Figure()
fig.plot(
fig_ref, fig_test = Figure(), Figure()
# Use single-character arguments for the reference image
fig_ref.plot(
data=POINTS_DATA,
J="X3i",
R="/".join(map(str, region)),
B="af",
S="c0.5c",
C="cubhelix",
seisman marked this conversation as resolved.
Show resolved Hide resolved
)

fig_test.plot(
x=data[:, 0],
y=data[:, 1],
color=data[:, 2],
Expand All @@ -140,7 +151,7 @@ def test_plot_colors(data, region):
cmap="cubhelix",
frame="af",
)
return fig
return fig_ref, fig_test


@pytest.mark.mpl_image_compare
Expand Down