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-
117from html import escape
128
139import numpy as np
10+ import pytest
1411
1512from iris .cube import Cube
1613from iris .experimental .representation import CubeRepresentation
14+ from iris .tests import _shared_utils
1715import 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