@@ -93,39 +93,40 @@ def test_latlon_simple_1d(self):
9393
9494class TestApiExtras :
9595 # Check operation with alternative calling setups.
96+
97+ @pytest .fixture (autouse = True )
98+ def _setup (self ):
99+ self .co_x = DimCoord ([1.0 , 2.0 , 3.0 ], long_name = "x" )
100+ self .co_y = DimCoord ([10.0 , 20.0 ], long_name = "y" )
101+ self .cube = Cube (np .zeros ((2 , 3 )))
102+
96103 def test_no_y_dim (self ):
97104 # Operate in X only, returned slice should be [:, ix].
98- co_x = DimCoord ([1.0 , 2.0 , 3.0 ], long_name = "x" )
99- co_y = DimCoord ([10.0 , 20.0 ], long_name = "y" )
100- cube = Cube (np .zeros ((2 , 3 )))
101- cube .add_dim_coord (co_y , 0 )
102- cube .add_dim_coord (co_x , 1 )
105+
106+ self .cube .add_dim_coord (self .co_y , 0 )
107+ self .cube .add_dim_coord (self .co_x , 1 )
103108 sample_point = [("x" , 2.8 )]
104- result = nn_ndinds (cube , sample_point )
109+ result = nn_ndinds (self . cube , sample_point )
105110 assert result == [(slice (None ), 2 )]
106111
107112 def test_no_x_dim (self ):
108113 # Operate in Y only, returned slice should be [iy, :].
109- co_x = DimCoord ([1.0 , 2.0 , 3.0 ], long_name = "x" )
110- co_y = DimCoord ([10.0 , 20.0 ], long_name = "y" )
111- cube = Cube (np .zeros ((2 , 3 )))
112- cube .add_dim_coord (co_y , 0 )
113- cube .add_dim_coord (co_x , 1 )
114+
115+ self .cube .add_dim_coord (self .co_y , 0 )
116+ self .cube .add_dim_coord (self .co_x , 1 )
114117 sample_point = [("y" , 18.5 )]
115- result = nn_ndinds (cube , sample_point )
118+ result = nn_ndinds (self . cube , sample_point )
116119 assert result == [(1 , slice (None ))]
117120
118121 def test_sample_dictionary (self ):
119122 # Pass sample_point arg as a dictionary: this usage mode is deprecated.
120- co_x = AuxCoord ([1.0 , 2.0 , 3.0 ], long_name = "x" )
121- co_y = AuxCoord ([10.0 , 20.0 ], long_name = "y" )
122- cube = Cube (np .zeros ((2 , 3 )))
123- cube .add_aux_coord (co_y , 0 )
124- cube .add_aux_coord (co_x , 1 )
123+
124+ self .cube .add_aux_coord (self .co_y , 0 )
125+ self .cube .add_aux_coord (self .co_x , 1 )
125126 sample_point = {"x" : 2.8 , "y" : 18.5 }
126127 exp_emsg = r"must be a list of \(coordinate, value\) pairs"
127128 with pytest .raises (TypeError , match = exp_emsg ):
128- nn_ndinds (cube , sample_point )
129+ nn_ndinds (self . cube , sample_point )
129130
130131
131132class TestLatlon :
0 commit comments