Skip to content
Snippets Groups Projects
Verified Commit d63bb2ed authored by Philipp S. Sommer's avatar Philipp S. Sommer
Browse files

consequently use assertAlmostArrayEqual for array comparison

parent 2307ec47
No related branches found
No related tags found
2 merge requests!44[release] compatibility fixes for matplotlib 3.9,!43add tests for mpl 3.9
Pipeline #403112 failed
"""Test module for the CombinedSimplePlotter."""
# SPDX-FileCopyrightText: 2021-2024 Helmholtz-Zentrum Hereon
# SPDX-FileCopyrightText: 2020-2021 Helmholtz-Zentrum Geesthacht
# SPDX-FileCopyrightText: 2016-2024 University of Lausanne
......@@ -318,20 +317,22 @@ class CombinedSimplePlotterTest(tv.SimpleVectorPlotterTest):
286.03,
289.84,
]
self.assertEqual(
np.round(self.plotter.bounds.norm.boundaries, 2).tolist(), bounds
self.assertAlmostArrayEqual(
self.plotter.bounds.norm.boundaries, bounds, atol=1e-2
)
self.update(bounds=["rounded", 5, 5, 95])
self.assertEqual(
np.round(self.plotter.bounds.norm.boundaries, 2).tolist(),
np.linspace(250, 290, 5, endpoint=True).tolist(),
self.assertAlmostArrayEqual(
self.plotter.bounds.norm.boundaries,
np.linspace(250, 290, 5, endpoint=True),
atol=1e-2,
)
# test vector bounds
self.update(color="absolute")
self.assertEqual(
np.round(self.plotter.vbounds.norm.boundaries, 2).tolist(),
np.linspace(0, 15, 11, endpoint=True).tolist(),
self.assertAlmostArrayEqual(
self.plotter.vbounds.norm.boundaries,
np.linspace(0, 15, 11, endpoint=True),
atol=1e-2,
)
self.update(vbounds="minmax")
bounds = [
......@@ -347,13 +348,14 @@ class CombinedSimplePlotterTest(tv.SimpleVectorPlotterTest):
9.77,
10.81,
]
self.assertEqual(
np.round(self.plotter.vbounds.norm.boundaries, 2).tolist(), bounds
self.assertAlmostArrayEqual(
self.plotter.vbounds.norm.boundaries, bounds, atol=1e-2
)
self.update(vbounds=["rounded", 5, 5, 95])
self.assertEqual(
np.round(self.plotter.vbounds.norm.boundaries, 3).tolist(),
np.linspace(1.0, 8.5, 5, endpoint=True).tolist(),
self.assertAlmostArrayEqual(
self.plotter.vbounds.norm.boundaries,
np.linspace(1.0, 8.5, 5, endpoint=True),
atol=1e-3,
)
def test_clabel(self):
......
"""Test module for the combined simple plotter for the icon grid."""
# SPDX-FileCopyrightText: 2021-2024 Helmholtz-Zentrum Hereon
# SPDX-FileCopyrightText: 2020-2021 Helmholtz-Zentrum Geesthacht
# SPDX-FileCopyrightText: 2016-2024 University of Lausanne
......@@ -107,20 +106,22 @@ class IconCombinedSimplePlotterTest(
300.21,
306.48,
]
self.assertEqual(
np.round(self.plotter.bounds.norm.boundaries, 2).tolist(), bounds
self.assertAlmostArrayEqual(
self.plotter.bounds.norm.boundaries, bounds, atol=1e-2
)
self.update(bounds=["rounded", 5, 5, 95])
self.assertEqual(
np.round(self.plotter.bounds.norm.boundaries, 2).tolist(),
np.linspace(255, 305, 5, endpoint=True).tolist(),
self.assertAlmostArrayEqual(
self.plotter.bounds.norm.boundaries,
np.linspace(255, 305, 5, endpoint=True),
atol=1e-2,
)
# test vector bounds
self.update(color="absolute")
self.assertEqual(
np.round(self.plotter.vbounds.norm.boundaries, 2).tolist(),
np.linspace(0, 15, 11, endpoint=True).tolist(),
self.assertAlmostArrayEqual(
self.plotter.vbounds.norm.boundaries,
np.linspace(0, 15, 11, endpoint=True),
atol=1e-2,
)
self.update(vbounds="minmax")
bounds = [
......@@ -136,13 +137,14 @@ class IconCombinedSimplePlotterTest(
9.99,
11.09,
]
self.assertEqual(
np.round(self.plotter.vbounds.norm.boundaries, 2).tolist(), bounds
self.assertAlmostArrayEqual(
self.plotter.vbounds.norm.boundaries, bounds, atol=1e-2
)
self.update(vbounds=["rounded", 5, 5, 95])
self.assertEqual(
np.round(self.plotter.vbounds.norm.boundaries, 2).tolist(),
np.round(np.linspace(0.5, 9.0, 5, endpoint=True), 2).tolist(),
self.assertAlmostArrayEqual(
self.plotter.vbounds.norm.boundaries,
np.linspace(0.5, 9.0, 5, endpoint=True),
atol=1e-2,
)
@property
......
"""Test module for 2D plots."""
# SPDX-FileCopyrightText: 2021-2024 Helmholtz-Zentrum Hereon
# SPDX-FileCopyrightText: 2020-2021 Helmholtz-Zentrum Geesthacht
# SPDX-FileCopyrightText: 2016-2024 University of Lausanne
......@@ -217,11 +216,12 @@ class Simple2DPlotterTest(tl.LinePlotterTest, References2D):
cticks = self._minmax_cticks
self.update(cticks="minmax")
cbar = self.plotter.cbar.cbars["b"]
self.assertEqual(
self.assertAlmostArrayEqual(
list(
map(lambda t: float(t.get_text()), cbar.ax.get_xticklabels())
),
cticks,
atol=1e-2,
)
self.update(cticklabels="%3.1f")
cticks = np.round(cticks, decimals=1).tolist()
......@@ -288,9 +288,10 @@ class Simple2DPlotterTest(tl.LinePlotterTest, References2D):
def test_bounds(self):
"""Test bounds formatoption"""
self.assertEqual(
np.round(self.plotter.bounds.norm.boundaries, 2).tolist(),
np.linspace(235, 310, 11, endpoint=True).tolist(),
self.assertAlmostArrayEqual(
self.plotter.bounds.norm.boundaries,
np.linspace(235, 310, 11, endpoint=True),
atol=1e-2,
)
self.update(bounds="minmax")
bounds = [
......@@ -306,13 +307,14 @@ class Simple2DPlotterTest(tl.LinePlotterTest, References2D):
302.79,
309.78,
]
self.assertEqual(
np.round(self.plotter.bounds.norm.boundaries, 2).tolist(), bounds
self.assertAlmostArrayEqual(
self.plotter.bounds.norm.boundaries, bounds, atol=1e-2
)
self.update(bounds=["rounded", 5, 5, 95])
self.assertEqual(
np.round(self.plotter.bounds.norm.boundaries, 2).tolist(),
np.linspace(245, 300, 5, endpoint=True).tolist(),
self.assertAlmostArrayEqual(
self.plotter.bounds.norm.boundaries,
np.linspace(245, 300, 5, endpoint=True),
atol=1e-2,
)
def test_miss_color(self, *args):
......
"""Test module for the 2D plot of icon files."""
# SPDX-FileCopyrightText: 2021-2024 Helmholtz-Zentrum Hereon
# SPDX-FileCopyrightText: 2020-2021 Helmholtz-Zentrum Geesthacht
# SPDX-FileCopyrightText: 2016-2024 University of Lausanne
......@@ -112,9 +111,10 @@ class IconSimplePlotterTest(IconTestMixin, t2d.Simple2DPlotterTest):
def test_bounds(self):
"""Test bounds formatoption"""
self.assertEqual(
np.round(self.plotter.bounds.norm.boundaries, 2).tolist(),
np.linspace(240, 310, 11, endpoint=True).tolist(),
self.assertAlmostArrayEqual(
self.plotter.bounds.norm.boundaries,
np.linspace(240, 310, 11, endpoint=True),
atol=1e-2,
)
self.update(bounds="minmax")
bounds = [
......@@ -130,11 +130,12 @@ class IconSimplePlotterTest(IconTestMixin, t2d.Simple2DPlotterTest):
300.21,
306.48,
]
self.assertEqual(
np.round(self.plotter.bounds.norm.boundaries, 2).tolist(), bounds
self.assertAlmostArrayEqual(
self.plotter.bounds.norm.boundaries, bounds, atol=1e-2
)
self.update(bounds=["rounded", 5, 5, 95])
self.assertEqual(
np.round(self.plotter.bounds.norm.boundaries, 2).tolist(),
self.assertAlmostArrayEqual(
self.plotter.bounds.norm.boundaries,
np.linspace(255, 305, 5, endpoint=True).tolist(),
atol=1e-2,
)
"""Test module for the contour plot for the icon edge grid."""
# SPDX-FileCopyrightText: 2021-2024 Helmholtz-Zentrum Hereon
# SPDX-FileCopyrightText: 2020-2021 Helmholtz-Zentrum Geesthacht
# SPDX-FileCopyrightText: 2016-2024 University of Lausanne
......@@ -27,9 +26,10 @@ class IconEdgeSimplePlotterTest(IconTestMixin, t2d.Simple2DPlotterTest):
def test_bounds(self):
"""Test bounds formatoption"""
self.assertEqual(
np.round(self.plotter.bounds.norm.boundaries, 2).tolist(),
np.linspace(240, 310, 11, endpoint=True).tolist(),
self.assertAlmostArrayEqual(
self.plotter.bounds.norm.boundaries,
np.linspace(240, 310, 11, endpoint=True),
atol=1e-2,
)
self.update(bounds="minmax")
bounds = [
......@@ -45,11 +45,12 @@ class IconEdgeSimplePlotterTest(IconTestMixin, t2d.Simple2DPlotterTest):
301.67,
308.25,
]
self.assertEqual(
np.round(self.plotter.bounds.norm.boundaries, 2).tolist(), bounds
self.assertAlmostArrayEqual(
self.plotter.bounds.norm.boundaries, bounds, atol=1e-2
)
self.update(bounds=["rounded", 5, 5, 95])
self.assertEqual(
np.round(self.plotter.bounds.norm.boundaries, 2).tolist(),
np.linspace(255, 305, 5, endpoint=True).tolist(),
self.assertAlmostArrayEqual(
self.plotter.bounds.norm.boundaries,
np.linspace(255, 305, 5, endpoint=True),
atol=1e-2,
)
"""Test module for vector (quiver) plots."""
# SPDX-FileCopyrightText: 2021-2024 Helmholtz-Zentrum Hereon
# SPDX-FileCopyrightText: 2020-2021 Helmholtz-Zentrum Geesthacht
# SPDX-FileCopyrightText: 2016-2024 University of Lausanne
......@@ -149,9 +148,10 @@ class SimpleVectorPlotterTest(t2d.Simple2DPlotterTest):
def test_bounds(self):
"""Test bounds formatoption"""
self.update(color="absolute")
self.assertEqual(
np.round(self.plotter.bounds.norm.boundaries, 2).tolist(),
np.linspace(0, 15, 11, endpoint=True).tolist(),
self.assertAlmostArrayEqual(
self.plotter.bounds.norm.boundaries,
np.linspace(0, 15, 11, endpoint=True),
atol=1e-2,
)
self.update(bounds="minmax")
bounds = [
......@@ -168,11 +168,12 @@ class SimpleVectorPlotterTest(t2d.Simple2DPlotterTest):
10.81,
]
self.assertEqual(
np.round(self.plotter.bounds.norm.boundaries, 2).tolist(), bounds
self.assertAlmostArrayEqual(
self.plotter.bounds.norm.boundaries, bounds, atol=1e-2
)
self.update(bounds=["rounded", 5, 5, 95])
self.assertEqual(
np.round(self.plotter.bounds.norm.boundaries, 3).tolist(),
np.linspace(1.0, 8.5, 5, endpoint=True).tolist(),
self.assertAlmostArrayEqual(
self.plotter.bounds.norm.boundaries,
np.linspace(1.0, 8.5, 5, endpoint=True),
atol=1e-3,
)
"""Test module for vector (quiver) plots with icon data."""
# SPDX-FileCopyrightText: 2021-2024 Helmholtz-Zentrum Hereon
# SPDX-FileCopyrightText: 2020-2021 Helmholtz-Zentrum Geesthacht
# SPDX-FileCopyrightText: 2016-2024 University of Lausanne
......@@ -52,9 +51,10 @@ class IconSimpleVectorPlotterTest(IconTestMixin, tv.SimpleVectorPlotterTest):
def test_bounds(self):
"""Test bounds formatoption"""
self.update(color="absolute")
self.assertEqual(
np.round(self.plotter.bounds.norm.boundaries, 2).tolist(),
np.linspace(0, 15, 11, endpoint=True).tolist(),
self.assertAlmostArrayEqual(
self.plotter.bounds.norm.boundaries,
np.linspace(0, 15, 11, endpoint=True),
atol=1e-2,
)
self.update(bounds="minmax")
bounds = [
......@@ -70,11 +70,12 @@ class IconSimpleVectorPlotterTest(IconTestMixin, tv.SimpleVectorPlotterTest):
9.99,
11.09,
]
self.assertEqual(
np.round(self.plotter.bounds.norm.boundaries, 2).tolist(), bounds
self.assertAlmostArrayEqual(
self.plotter.bounds.norm.boundaries, bounds, atol=1e-2
)
self.update(bounds=["rounded", 5, 5, 95])
self.assertEqual(
np.round(self.plotter.bounds.norm.boundaries, 2).tolist(),
np.round(np.linspace(0.5, 9.0, 5, endpoint=True), 2).tolist(),
self.assertAlmostArrayEqual(
self.plotter.bounds.norm.boundaries,
np.linspace(0.5, 9.0, 5, endpoint=True),
atol=1e-2,
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment