|
4 | 4 | # See LICENSE in the root of the repository for full licensing details. |
5 | 5 | """Integration tests for area weighted regridding.""" |
6 | 6 |
|
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 |
10 | 8 |
|
11 | 9 | import iris |
12 | 10 | from iris.analysis import AreaWeighted |
| 11 | +from iris.tests import _shared_utils |
13 | 12 |
|
14 | 13 |
|
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): |
18 | 18 | # Prepare a cube and a template |
19 | 19 |
|
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 | + ) |
21 | 23 | self.cube = iris.load_cube(cube_file_path) |
22 | 24 |
|
23 | | - template_file_path = tests.get_data_path( |
| 25 | + template_file_path = _shared_utils.get_data_path( |
24 | 26 | ["NetCDF", "regrid", "regrid_template_global_latlon.nc"] |
25 | 27 | ) |
26 | 28 | self.template_cube = iris.load_cube(template_file_path) |
27 | 29 |
|
28 | | - def test_regrid_area_w_lazy(self): |
| 30 | + def test_regrid_area_w_lazy(self, tmp_path): |
29 | 31 | # Regrid the cube onto the template. |
30 | 32 | out = self.cube.regrid(self.template_cube, AreaWeighted()) |
31 | 33 | # 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() |
34 | 36 | # 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) |
37 | 39 |
|
38 | | - def test_regrid_area_w_lazy_chunked(self): |
| 40 | + def test_regrid_area_w_lazy_chunked(self, tmp_path): |
39 | 41 | # Chunked data makes the regridder run repeatedly |
40 | 42 | self.cube.data = self.cube.lazy_data().rechunk((1, -1, -1)) |
41 | 43 | # Regrid the cube onto the template. |
42 | 44 | out = self.cube.regrid(self.template_cube, AreaWeighted()) |
43 | 45 | # 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() |
46 | 48 | # 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) |
49 | 51 |
|
50 | | - def test_regrid_area_w_real_save(self): |
| 52 | + def test_regrid_area_w_real_save(self, tmp_path): |
51 | 53 | real_cube = self.cube.copy() |
52 | 54 | real_cube.data |
53 | 55 | # Regrid the cube onto the template. |
54 | 56 | out = real_cube.regrid(self.template_cube, AreaWeighted()) |
55 | 57 | # Realise the data |
56 | 58 | out.data |
57 | 59 | # 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) |
60 | 62 |
|
61 | | - def test_regrid_area_w_real_start(self): |
| 63 | + def test_regrid_area_w_real_start(self, tmp_path): |
62 | 64 | real_cube = self.cube.copy() |
63 | 65 | real_cube.data |
64 | 66 | # Regrid the cube onto the template. |
65 | 67 | out = real_cube.regrid(self.template_cube, AreaWeighted()) |
66 | 68 | # 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