|
26 | 26 | from iris.coords import DimCoord, CellMethod |
27 | 27 | from iris.fileformats._ff_cross_references import STASH_TRANS |
28 | 28 | import iris.fileformats.pp as pp |
| 29 | +from iris.fileformats.pp_save_rules import _lbproc_rules |
29 | 30 | from iris.tests import mock |
30 | 31 | import iris.tests.stock as stock |
31 | 32 |
|
@@ -162,26 +163,42 @@ def test_um_version(self): |
162 | 163 |
|
163 | 164 |
|
164 | 165 | class Test_Save__LbprocProduction(tests.IrisTest): |
| 166 | + # This test class is a little different to the others. |
| 167 | + # If it called `pp.save` via `_pp_save_ppfield_values` it would run |
| 168 | + # `pp_save_rules.verify` and run all the save rules. As this class uses |
| 169 | + # a 3D cube with a time coord it would run the time rules, which would fail |
| 170 | + # because the mock object does not set up the `pp.lbtim` attribute |
| 171 | + # correctly (i.e. as a `SplittableInt` object). |
| 172 | + # To work around this we call the lbproc rules directly here. |
| 173 | + |
165 | 174 | def setUp(self): |
166 | 175 | self.cube = stock.realistic_3d() |
| 176 | + self.pp_field = mock.MagicMock(spec=pp.PPField3) |
| 177 | + self.pp_field.HEADER_DEFN = pp.PPField3.HEADER_DEFN |
| 178 | + self.patcher = mock.patch('iris.fileformats.pp.PPField3', |
| 179 | + return_value=self.pp_field) |
| 180 | + self.patcher.start() |
| 181 | + |
| 182 | + def tearDown(self): |
| 183 | + self.patcher.stop() |
167 | 184 |
|
168 | 185 | def test_no_cell_methods(self): |
169 | | - lbproc = _pp_save_ppfield_values(self.cube).lbproc |
| 186 | + lbproc = _lbproc_rules(self.cube, self.pp_field).lbproc |
170 | 187 | self.assertEqual(lbproc, 0) |
171 | 188 |
|
172 | 189 | def test_mean(self): |
173 | 190 | self.cube.cell_methods = (CellMethod('mean', 'time', '1 hour'),) |
174 | | - lbproc = _pp_save_ppfield_values(self.cube).lbproc |
| 191 | + lbproc = _lbproc_rules(self.cube, self.pp_field).lbproc |
175 | 192 | self.assertEqual(lbproc, 128) |
176 | 193 |
|
177 | 194 | def test_minimum(self): |
178 | 195 | self.cube.cell_methods = (CellMethod('minimum', 'time', '1 hour'),) |
179 | | - lbproc = _pp_save_ppfield_values(self.cube).lbproc |
| 196 | + lbproc = _lbproc_rules(self.cube, self.pp_field).lbproc |
180 | 197 | self.assertEqual(lbproc, 4096) |
181 | 198 |
|
182 | 199 | def test_maximum(self): |
183 | 200 | self.cube.cell_methods = (CellMethod('maximum', 'time', '1 hour'),) |
184 | | - lbproc = _pp_save_ppfield_values(self.cube).lbproc |
| 201 | + lbproc = _lbproc_rules(self.cube, self.pp_field).lbproc |
185 | 202 | self.assertEqual(lbproc, 8192) |
186 | 203 |
|
187 | 204 |
|
|
0 commit comments