Skip to content

Commit

Permalink
Migrate Figure.colorbar tests to use dvc (#1143)
Browse files Browse the repository at this point in the history
* remove test_colorbar_using_paper_coordinates_horizontal()
* remove test_colorbar_box_with_rounded_corners()
* remove test_colorbar_shading_string()
* remove test_colorbar_positioned_using_justification_code()
* remove test_colorbar_box_with_secondary_border()
* remove test_colorbar_box_with_clearance()
* remove test_colorbar_box_with_pen()
* remove test_colorbar_box_with_offset_background()
* update test_colorbar_shading_boolean() to use mpl_image_compare
* remove test_color_shading_float and update test_colorbar_shading_list to use mpl_image_compare
* remove .png files, add .dvc files
* remove test_colorbar_positioned_using_normalized_coords()
* remove test_colorbar_positioned_using_map_coordinates()
* remove test_colorbar_using_paper_coordinates()

Co-authored-by: Wei Ji <[email protected]>
Co-authored-by: Dongdong Tian <[email protected]>
  • Loading branch information
3 people authored Apr 2, 2021
1 parent e96c869 commit e37d361
Show file tree
Hide file tree
Showing 21 changed files with 34 additions and 159 deletions.
Binary file removed pygmt/tests/baseline/test_colorbar_box.png
Binary file not shown.
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_colorbar_box.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 6b0f073c0adc00a3c93693ee22e92b6b
size: 1522
path: test_colorbar_box.png
Binary file not shown.
Binary file removed pygmt/tests/baseline/test_colorbar_box_with_fill.png
Binary file not shown.
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_colorbar_box_with_fill.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: f8971e61c1e44c95156372f39913b945
size: 1454
path: test_colorbar_box_with_fill.png
Binary file not shown.
Binary file removed pygmt/tests/baseline/test_colorbar_box_with_pen.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_colorbar_scaled_z_values.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 513afcc325c918500f3b3c8de86cd63c
size: 1870
path: test_colorbar_scaled_z_values.png
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_colorbar_shading_boolean.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 056c3872738c08667a816f49c676418f
size: 54042
path: test_colorbar_shading_boolean.png
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_colorbar_shading_list.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: e888834c32778bbcfeccaa9fd0d04b1f
size: 59418
path: test_colorbar_shading_list.png
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 03e10c11514fc071f6e970c6babfd6c8
size: 2542
path: test_colorbar_truncated_to_zlow_zhigh.png
Binary file not shown.
Binary file not shown.
169 changes: 10 additions & 159 deletions pygmt/tests/test_colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,6 @@
"""
import pytest
from pygmt import Figure
from pygmt.helpers.testing import check_figures_equal


@pytest.mark.mpl_image_compare
def test_colorbar_using_paper_coordinates():
"""
Create colorbar positioned at 0cm,0cm with length 1cm and width 0.5cm.
"""
fig = Figure()
fig.colorbar(cmap="rainbow", position="x0c/0c+w1c/0.5c")
return fig


@pytest.mark.mpl_image_compare
def test_colorbar_using_paper_coordinates_horizontal():
"""
Create colorbar positioned at 0cm,0cm with length 2cm oriented
horizontally.
"""
fig = Figure()
fig.colorbar(cmap="rainbow", position="x0c/0c+w2c+h")
return fig


@pytest.mark.mpl_image_compare
def test_colorbar_positioned_using_map_coordinates():
"""
Create colorbar positioned at longitude,latitude 3,6 with length 2cm.
"""
fig = Figure()
fig.basemap(region=[2, 4, 6, 8], projection="t0/2c", frame=True)
fig.colorbar(cmap="rainbow", position="g3/6+w2c")
return fig


@check_figures_equal()
def test_colorbar_positioned_using_justification_code():
"""
Create colorbar at Top Center inside the map frame with length 2cm.
"""
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
def test_colorbar_positioned_using_normalized_coords():
"""
Create colorbar at normalized coordinates 0.75,0.25 with length 2cm.
"""
fig = Figure()
fig.basemap(region=[2, 4, 6, 8], projection="t0/2c", frame=True)
fig.colorbar(cmap="rainbow", position="n0.75/0.25+w2c")
return fig


@pytest.mark.mpl_image_compare
Expand All @@ -74,16 +15,6 @@ def test_colorbar_box():
return fig


@pytest.mark.mpl_image_compare
def test_colorbar_box_with_pen():
"""
Create colorbar with box that has a different colored pen.
"""
fig = Figure()
fig.colorbar(cmap="rainbow", box="+porange", position="x0c/0c+w1c/0.5c")
return fig


@pytest.mark.mpl_image_compare
def test_colorbar_box_with_fill():
"""
Expand All @@ -94,48 +25,6 @@ def test_colorbar_box_with_fill():
return fig


@pytest.mark.mpl_image_compare
def test_colorbar_box_with_clearance():
"""
Create colorbar with box that has an x-clearance of 0.8cm and y-clearance
of 0.4cm.
"""
fig = Figure()
fig.colorbar(cmap="rainbow", box="+c0.8c/0.4c+porange", position="x0c/0c+w1c/0.5c")
return fig


@pytest.mark.mpl_image_compare
def test_colorbar_box_with_secondary_border():
"""
Create colorbar with box that has a secondary, inner border in addition to
the main primary, outer border.
"""
fig = Figure()
fig.colorbar(cmap="rainbow", box="+porange+imagenta", position="x0c/0c+w1c/0.5c")
return fig


@pytest.mark.mpl_image_compare
def test_colorbar_box_with_rounded_corners():
"""
Create colorbar with box that has rounded corners.
"""
fig = Figure()
fig.colorbar(cmap="rainbow", box="+porange+r", position="x0c/0c+w1c/0.5c")
return fig


@pytest.mark.mpl_image_compare
def test_colorbar_box_with_offset_background():
"""
Create colorbar with box and an offset background shaded region.
"""
fig = Figure()
fig.colorbar(cmap="rainbow", box="+s5p/-5p", position="x0c/0c+w1c/0.5c")
return fig


@pytest.mark.mpl_image_compare
def test_colorbar_truncated_to_zlow_zhigh():
"""
Expand All @@ -156,61 +45,23 @@ def test_colorbar_scaled_z_values():
return fig


@check_figures_equal()
@pytest.mark.mpl_image_compare
def test_colorbar_shading_boolean():
"""
Create colorbar and set shading with a Boolean value.
"""
fig_ref, fig_test = Figure(), Figure()
# Use single-character arguments for the reference image
fig_ref.basemap(R="0/10/0/10", J="X15c", B="a")
fig_ref.colorbar(C="geo", I="")

fig_test.basemap(region=[0, 10, 0, 10], projection="X15c", frame="a")
fig_test.colorbar(cmap="geo", shading=True)
return fig_ref, fig_test


@check_figures_equal()
def test_colorbar_shading_float():
"""
Create colorbar and set shading with a single float variable.
"""
fig_ref, fig_test = Figure(), Figure()
# Use single-character arguments for the reference image
fig_ref.basemap(R="0/10/0/10", J="X15c", B="a")
fig_ref.colorbar(C="geo", I=0.5)

fig_test.basemap(region=[0, 10, 0, 10], projection="X15c", frame="a")
fig_test.colorbar(cmap="geo", shading=0.5)
return fig_ref, fig_test


@check_figures_equal()
def test_colorbar_shading_string():
"""
Create colorbar and set shading by passing the low/high values as a string.
"""
fig_ref, fig_test = Figure(), Figure()
# Use single-character arguments for the reference image
fig_ref.basemap(R="0/10/0/10", J="X15c", B="a")
fig_ref.colorbar(C="geo", I="-0.7/0.2")

fig_test.basemap(region=[0, 10, 0, 10], projection="X15c", frame="a")
fig_test.colorbar(cmap="geo", shading="-0.7/0.2")
return fig_ref, fig_test
fig = Figure()
fig.basemap(region=[0, 10, 0, 10], projection="X15c", frame="a")
fig.colorbar(cmap="geo", shading=True, frame=True)
return fig


@check_figures_equal()
@pytest.mark.mpl_image_compare
def test_colorbar_shading_list():
"""
Create colorbar and set shading by passing the high/low values as a list.
"""
fig_ref, fig_test = Figure(), Figure()
# Use single-character arguments for the reference image
fig_ref.basemap(R="0/10/0/10", J="X15c", B="a")
fig_ref.colorbar(C="geo", I="-0.7/0.2")

fig_test.basemap(region=[0, 10, 0, 10], projection="X15c", frame="a")
fig_test.colorbar(cmap="geo", shading=[-0.7, 0.2])
return fig_ref, fig_test
fig = Figure()
fig.basemap(region=[0, 10, 0, 10], projection="X15c", frame="a")
fig.colorbar(cmap="geo", shading=[-0.7, 0.2], frame=True)
return fig

0 comments on commit e37d361

Please sign in to comment.