Skip to content

Commit c0b14d9

Browse files
authored
Converted integration/experimental to pytest (#6822)
* converted test_CubeRep * converted test_regrid_ProjUns * converted geovista/test_cube_to_poly * converted geovista/test_extract_uns_reg
1 parent 69847cd commit c0b14d9

File tree

4 files changed

+85
-89
lines changed

4 files changed

+85
-89
lines changed

lib/iris/tests/integration/experimental/geovista/test_cube_to_poly.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
# See LICENSE in the root of the repository for full licensing details.
55
"""Integration tests for the `iris.experimental.geovista.cube_to_polydata` function."""
66

7-
import numpy as np
8-
97
from iris import load_cube
108
from iris.experimental.geovista import cube_to_polydata
11-
from iris.tests import get_data_path
9+
from iris.tests import _shared_utils
1210

1311

1412
def test_integration_2d():
15-
file_path = get_data_path(
13+
file_path = _shared_utils.get_data_path(
1614
[
1715
"NetCDF",
1816
"ORCA2",
@@ -26,11 +24,13 @@ def test_integration_2d():
2624
# This is a known good output, we have plotted the result and checked it.
2725
assert polydata.GetNumberOfCells() == 26640
2826
assert polydata.GetNumberOfPoints() == 26969
29-
np.testing.assert_array_equal(cube[0, 1, :].data.flatten(), polydata.active_scalars)
27+
_shared_utils.assert_array_equal(
28+
cube[0, 1, :].data.flatten(), polydata.active_scalars
29+
)
3030

3131

3232
def test_integration_1d():
33-
file_path = get_data_path(
33+
file_path = _shared_utils.get_data_path(
3434
[
3535
"NetCDF",
3636
"global",
@@ -44,11 +44,11 @@ def test_integration_1d():
4444
# This is a known good output, we have plotted the result and checked it.
4545
assert polydata.GetNumberOfCells() == 51200
4646
assert polydata.GetNumberOfPoints() == 51681
47-
np.testing.assert_array_equal(cube[0, :].data.flatten(), polydata.active_scalars)
47+
_shared_utils.assert_array_equal(cube[0, :].data.flatten(), polydata.active_scalars)
4848

4949

5050
def test_integration_mesh():
51-
file_path = get_data_path(
51+
file_path = _shared_utils.get_data_path(
5252
[
5353
"NetCDF",
5454
"unstructured_grid",
@@ -62,4 +62,4 @@ def test_integration_mesh():
6262
# This is a known good output, we have plotted the result and checked it.
6363
assert polydata.GetNumberOfCells() == 864
6464
assert polydata.GetNumberOfPoints() == 866
65-
np.testing.assert_array_equal(polydata.active_scalars, cube[0, :].data)
65+
_shared_utils.assert_array_equal(polydata.active_scalars, cube[0, :].data)

lib/iris/tests/integration/experimental/geovista/test_extract_unstructured_region.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
from iris import load_cube
1010
from iris.experimental.geovista import cube_to_polydata, extract_unstructured_region
11-
from iris.tests import get_data_path
11+
from iris.tests import _shared_utils
1212

1313

1414
def test_face_region_extraction():
15-
file_path = get_data_path(
15+
file_path = _shared_utils.get_data_path(
1616
[
1717
"NetCDF",
1818
"unstructured_grid",

lib/iris/tests/integration/experimental/test_CubeRepresentation.py

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,22 @@
44
# See LICENSE in the root of the repository for full licensing details.
55
"""Integration tests for cube html representation."""
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
10-
117
from html import escape
128

139
import numpy as np
10+
import pytest
1411

1512
from iris.cube import Cube
1613
from iris.experimental.representation import CubeRepresentation
14+
from iris.tests import _shared_utils
1715
import iris.tests.stock as stock
1816

1917

20-
@tests.skip_data
21-
class TestNoMetadata(tests.IrisTest):
18+
@_shared_utils.skip_data
19+
class TestNoMetadata:
2220
# Test the situation where we have a cube with no metadata at all.
23-
def setUp(self):
21+
@pytest.fixture(autouse=True)
22+
def _setup(self):
2423
self.shape = (2, 3, 4)
2524
self.cube = Cube(np.arange(24).reshape(self.shape))
2625
self.representer = CubeRepresentation(self.cube)
@@ -29,26 +28,27 @@ def setUp(self):
2928
def test_cube_name(self):
3029
expected = "Unknown" # This cube has no metadata.
3130
result = self.representer.name
32-
self.assertEqual(expected, result)
31+
assert expected == result
3332

3433
def test_cube_units(self):
3534
expected = "unknown" # This cube has no metadata.
3635
result = self.representer.units
37-
self.assertEqual(expected, result)
36+
assert expected == result
3837

3938
def test_dim_names(self):
4039
expected = ["--"] * len(self.shape)
4140
result = self.representer.names
42-
self.assertEqual(expected, result)
41+
assert expected == result
4342

4443
def test_shape(self):
4544
result = self.representer.shapes
46-
self.assertEqual(result, self.shape)
45+
assert result == self.shape
4746

4847

49-
@tests.skip_data
50-
class TestMissingMetadata(tests.IrisTest):
51-
def setUp(self):
48+
@_shared_utils.skip_data
49+
class TestMissingMetadata:
50+
@pytest.fixture(autouse=True)
51+
def _setup(self):
5252
self.cube = stock.realistic_3d()
5353

5454
def test_no_coords(self):
@@ -57,107 +57,104 @@ def test_no_coords(self):
5757
self.cube.remove_coord(coord)
5858
representer = CubeRepresentation(self.cube)
5959
result = representer.repr_html().lower()
60-
self.assertNotIn("dimension coordinates", result)
61-
self.assertNotIn("auxiliary coordinates", result)
62-
self.assertNotIn("scalar coordinates", result)
63-
self.assertIn("attributes", result)
60+
assert "dimension coordinates" not in result
61+
assert "auxiliary coordinates" not in result
62+
assert "scalar coordinates" not in result
63+
assert "attributes" in result
6464

6565
def test_no_dim_coords(self):
6666
dim_coords = [c.name() for c in self.cube.coords(dim_coords=True)]
6767
for coord in dim_coords:
6868
self.cube.remove_coord(coord)
6969
representer = CubeRepresentation(self.cube)
7070
result = representer.repr_html().lower()
71-
self.assertNotIn("dimension coordinates", result)
72-
self.assertIn("auxiliary coordinates", result)
73-
self.assertIn("scalar coordinates", result)
74-
self.assertIn("attributes", result)
71+
assert "dimension coordinates" not in result
72+
assert "auxiliary coordinates" in result
73+
assert "scalar coordinates" in result
74+
assert "attributes" in result
7575

7676
def test_no_aux_coords(self):
7777
aux_coords = ["forecast_period"]
7878
for coord in aux_coords:
7979
self.cube.remove_coord(coord)
8080
representer = CubeRepresentation(self.cube)
8181
result = representer.repr_html().lower()
82-
self.assertIn("dimension coordinates", result)
83-
self.assertNotIn("auxiliary coordinates", result)
84-
self.assertIn("scalar coordinates", result)
85-
self.assertIn("attributes", result)
82+
assert "dimension coordinates" in result
83+
assert "auxiliary coordinates" not in result
84+
assert "scalar coordinates" in result
85+
assert "attributes" in result
8686

8787
def test_no_scalar_coords(self):
8888
aux_coords = ["air_pressure"]
8989
for coord in aux_coords:
9090
self.cube.remove_coord(coord)
9191
representer = CubeRepresentation(self.cube)
9292
result = representer.repr_html().lower()
93-
self.assertIn("dimension coordinates", result)
94-
self.assertIn("auxiliary coordinates", result)
95-
self.assertNotIn("scalar coordinates", result)
96-
self.assertIn("attributes", result)
93+
assert "dimension coordinates" in result
94+
assert "auxiliary coordinates" in result
95+
assert "scalar coordinates" not in result
96+
assert "attributes" in result
9797

9898
def test_no_attrs(self):
9999
self.cube.attributes = {}
100100
representer = CubeRepresentation(self.cube)
101101
result = representer.repr_html().lower()
102-
self.assertIn("dimension coordinates", result)
103-
self.assertIn("auxiliary coordinates", result)
104-
self.assertIn("scalar coordinates", result)
105-
self.assertNotIn("attributes", result)
102+
assert "dimension coordinates" in result
103+
assert "auxiliary coordinates" in result
104+
assert "scalar coordinates" in result
105+
assert "attributes" not in result
106106

107107
def test_no_cell_methods(self):
108108
representer = CubeRepresentation(self.cube)
109109
result = representer.repr_html().lower()
110-
self.assertNotIn("cell methods", result)
110+
assert "cell methods" not in result
111111

112112

113-
@tests.skip_data
114-
class TestScalarCube(tests.IrisTest):
115-
def setUp(self):
113+
@_shared_utils.skip_data
114+
class TestScalarCube:
115+
@pytest.fixture(autouse=True)
116+
def _setup(self):
116117
self.cube = stock.realistic_3d()[0, 0, 0]
117118
self.representer = CubeRepresentation(self.cube)
118119
self.representer.repr_html()
119120

120121
def test_identfication(self):
121122
# Is this scalar cube accurately identified?
122-
self.assertTrue(self.representer.scalar_cube)
123+
assert self.representer.scalar_cube
123124

124125
def test_header__name(self):
125126
header = self.representer._make_header()
126127
expected_name = escape(self.cube.name().title().replace("_", " "))
127-
self.assertIn(expected_name, header)
128+
assert expected_name in header
128129

129130
def test_header__units(self):
130131
header = self.representer._make_header()
131132
expected_units = escape(self.cube.units.symbol)
132-
self.assertIn(expected_units, header)
133+
assert expected_units in header
133134

134135
def test_header__scalar_str(self):
135136
# Check that 'scalar cube' is placed in the header.
136137
header = self.representer._make_header()
137138
expected_str = "(scalar cube)"
138-
self.assertIn(expected_str, header)
139+
assert expected_str in header
139140

140141
def test_content__scalars(self):
141142
# Check an element "Scalar coordinates" is present in the main content.
142143
content = self.representer._make_content()
143144
expected_str = "Scalar coordinates"
144-
self.assertIn(expected_str, content)
145+
assert expected_str in content
145146

146147
def test_content__specific_scalar_coord(self):
147148
# Check a specific scalar coord is present in the main content.
148149
content = self.representer._make_content()
149150
expected_coord = self.cube.coords()[0]
150151
expected_coord_name = escape(expected_coord.name())
151-
self.assertIn(expected_coord_name, content)
152+
assert expected_coord_name in content
152153
expected_coord_val = escape(str(expected_coord.points[0]))
153-
self.assertIn(expected_coord_val, content)
154+
assert expected_coord_val in content
154155

155156
def test_content__attributes(self):
156157
# Check an element "attributes" is present in the main content.
157158
content = self.representer._make_content()
158159
expected_str = "Attributes"
159-
self.assertIn(expected_str, content)
160-
161-
162-
if __name__ == "__main__":
163-
tests.main()
160+
assert expected_str in content

0 commit comments

Comments
 (0)