Skip to content

Commit

Permalink
Remove unneeded cube copies in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrost-mo committed Jul 23, 2024
1 parent 0a70d68 commit 4c08683
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
2 changes: 0 additions & 2 deletions tests/operators/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ def test_noop_operator():

def test_remove_attribute_cube(cube):
"""Remove attribute from a Cube."""
cube = cube.copy()
assert "STASH" in cube.attributes
cube = misc.remove_attribute(cube, "STASH")[0]
assert "STASH" not in cube.attributes


def test_remove_attribute_cubelist(cubes):
"""Remove attribute from a CubeList."""
cubes = cubes.copy()
for cube in cubes:
assert "STASH" in cube.attributes
cubes = misc.remove_attribute(cubes, "STASH")
Expand Down
2 changes: 0 additions & 2 deletions tests/operators/test_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def test_check_single_cube():
def test_spatial_contour_plot(cube, tmp_working_dir):
"""Plot spatial contour plot of instant air temp."""
# Remove realization coord to increase coverage, and as its not needed.
cube = cube.copy()
cube.remove_coord("realization")
cube_2d = cube.slices_over("time").next()
plot.spatial_contour_plot(cube_2d, filename="plot")
Expand Down Expand Up @@ -67,7 +66,6 @@ def test_postage_stamp_contour_plot(monkeypatch, tmp_path):
def test_postage_stamp_contour_plot_sequence_coord_check(cube, tmp_working_dir):
"""Check error when cube has no time coordinate."""
# What does this even physically mean? No data?
cube = cube.copy()
cube.remove_coord("time")
with pytest.raises(ValueError):
plot.spatial_contour_plot(cube)
Expand Down
19 changes: 9 additions & 10 deletions tests/operators/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@
import CSET.operators._utils as operator_utils


def test_missing_coord_get_cube_yxcoordname(regrid_rectilinear_cube):
"""Missing coordinate raises error."""
# Missing X coordinate.
source = regrid_rectilinear_cube.copy()
source.remove_coord("longitude")
def test_missing_coord_get_cube_yxcoordname_x(regrid_rectilinear_cube):
"""Missing X coordinate raises error."""
regrid_rectilinear_cube.remove_coord("longitude")
with pytest.raises(ValueError):
operator_utils.get_cube_yxcoordname(source)
operator_utils.get_cube_yxcoordname(regrid_rectilinear_cube)

# Missing Y coordinate.
source = regrid_rectilinear_cube.copy()
source.remove_coord("latitude")

def test_missing_coord_get_cube_yxcoordname_y(regrid_rectilinear_cube):
"""Missing Y coordinate raises error."""
regrid_rectilinear_cube.remove_coord("longitude")
with pytest.raises(ValueError):
operator_utils.get_cube_yxcoordname(source)
operator_utils.get_cube_yxcoordname(regrid_rectilinear_cube)


def test_get_cube_yxcoordname(regrid_rectilinear_cube):
Expand Down

0 comments on commit 4c08683

Please sign in to comment.