Skip to content

Commit 81a9c27

Browse files
authored
Converted integration/analysis to pytest (#6823)
* converted test_area_weighted * tmp_path additions
1 parent 71a3c3c commit 81a9c27

File tree

1 file changed

+26
-28
lines changed

1 file changed

+26
-28
lines changed

lib/iris/tests/integration/analysis/test_area_weighted.py

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,69 +4,67 @@
44
# See LICENSE in the root of the repository for full licensing details.
55
"""Integration tests for area weighted regridding."""
66

7-
# Import iris.tests first so that some things can be initialised before
8-
# importing anything else.
9-
import iris.tests as tests # isort:skip
7+
import pytest
108

119
import iris
1210
from iris.analysis import AreaWeighted
11+
from iris.tests import _shared_utils
1312

1413

15-
@tests.skip_data
16-
class AreaWeightedTests(tests.IrisTest):
17-
def setUp(self):
14+
@_shared_utils.skip_data
15+
class TestAreaWeighted:
16+
@pytest.fixture(autouse=True)
17+
def _setup(self):
1818
# Prepare a cube and a template
1919

20-
cube_file_path = tests.get_data_path(["NetCDF", "regrid", "regrid_xyt.nc"])
20+
cube_file_path = _shared_utils.get_data_path(
21+
["NetCDF", "regrid", "regrid_xyt.nc"]
22+
)
2123
self.cube = iris.load_cube(cube_file_path)
2224

23-
template_file_path = tests.get_data_path(
25+
template_file_path = _shared_utils.get_data_path(
2426
["NetCDF", "regrid", "regrid_template_global_latlon.nc"]
2527
)
2628
self.template_cube = iris.load_cube(template_file_path)
2729

28-
def test_regrid_area_w_lazy(self):
30+
def test_regrid_area_w_lazy(self, tmp_path):
2931
# Regrid the cube onto the template.
3032
out = self.cube.regrid(self.template_cube, AreaWeighted())
3133
# Check data is still lazy
32-
self.assertTrue(self.cube.has_lazy_data())
33-
self.assertTrue(out.has_lazy_data())
34+
assert self.cube.has_lazy_data()
35+
assert out.has_lazy_data()
3436
# Save the data
35-
with self.temp_filename(suffix=".nc") as fname:
36-
iris.save(out, fname)
37+
fname = tmp_path / "test.nc"
38+
iris.save(out, fname)
3739

38-
def test_regrid_area_w_lazy_chunked(self):
40+
def test_regrid_area_w_lazy_chunked(self, tmp_path):
3941
# Chunked data makes the regridder run repeatedly
4042
self.cube.data = self.cube.lazy_data().rechunk((1, -1, -1))
4143
# Regrid the cube onto the template.
4244
out = self.cube.regrid(self.template_cube, AreaWeighted())
4345
# Check data is still lazy
44-
self.assertTrue(self.cube.has_lazy_data())
45-
self.assertTrue(out.has_lazy_data())
46+
assert self.cube.has_lazy_data()
47+
assert out.has_lazy_data()
4648
# Save the data
47-
with self.temp_filename(suffix=".nc") as fname:
48-
iris.save(out, fname)
49+
fname = tmp_path / "test.nc"
50+
iris.save(out, fname)
4951

50-
def test_regrid_area_w_real_save(self):
52+
def test_regrid_area_w_real_save(self, tmp_path):
5153
real_cube = self.cube.copy()
5254
real_cube.data
5355
# Regrid the cube onto the template.
5456
out = real_cube.regrid(self.template_cube, AreaWeighted())
5557
# Realise the data
5658
out.data
5759
# Save the data
58-
with self.temp_filename(suffix=".nc") as fname:
59-
iris.save(out, fname)
60+
fname = tmp_path / "test.nc"
61+
iris.save(out, fname)
6062

61-
def test_regrid_area_w_real_start(self):
63+
def test_regrid_area_w_real_start(self, tmp_path):
6264
real_cube = self.cube.copy()
6365
real_cube.data
6466
# Regrid the cube onto the template.
6567
out = real_cube.regrid(self.template_cube, AreaWeighted())
6668
# Save the data
67-
with self.temp_filename(suffix=".nc") as fname:
68-
iris.save(out, fname)
69-
70-
71-
if __name__ == "__main__":
72-
tests.main()
69+
fname = tmp_path / "test.nc"
70+
iris.save(out, fname)

0 commit comments

Comments
 (0)