def test_not_deferred_mask_field(self): # Check that the order of the load is unchanged if a land mask # has already been seen. f1, mask = self.pp_field, self.land_mask_field mask2 = deepcopy(mask) result = list(pp._interpret_fields([mask, f1, mask2])) self.assertEqual(result, [mask, f1, mask2])
def test_deferred_mask_field(self): # Check that the order of the load is yielded last if the mask # hasn't yet been seen. result = list( pp._interpret_fields([self.pp_field, self.land_mask_field]) ) self.assertEqual(result, [self.land_mask_field, self.pp_field])
def test_shared_land_mask_field(self): # Check that multiple land masked fields share the # land mask field instance. f1 = deepcopy(self.pp_field) f2 = deepcopy(self.pp_field) self.assertIsNot(f1, f2) list(pp._interpret_fields([f1, self.land_mask_field, f2])) self.assertIs(f1._data.item().mask, f2._data.item().mask)
def test_fix_lbrow_lbnpt_no_mask_available(self): # Check a warning is issued when loading a land masked field # without a land mask. with mock.patch('warnings.warn') as warn: list(pp._interpret_fields([self.pp_field])) self.assertEqual(warn.call_count, 1) warn_msg = warn.call_args[0][0] self.assertTrue(warn_msg.startswith('Landmask compressed fields ' 'existed without a landmask'), 'Unexpected warning message: {!r}'.format(warn_msg))
def test_non_deferred_fix_lbrow_lbnpt(self): # Checks the fix_lbrow_lbnpt is applied to fields which are not # deferred. f1, mask = self.pp_field, self.land_mask_field self.assertEqual(f1.lbrow, 0) self.assertEqual(f1.lbnpt, 0) list(pp._interpret_fields([mask, f1])) self.assertEqual(f1.lbrow, 3) self.assertEqual(f1.lbnpt, 4) # Check the data's shape has been updated too. self.assertEqual(f1._data.shape, (3, 4))
def test_shared_land_mask_field(self): # Check that multiple land masked fields share the # land mask field instance. f1 = deepcopy(self.pp_field) f2 = deepcopy(self.pp_field) self.assertIsNot(f1, f2) with mock.patch('iris.fileformats.pp.PPDataProxy') as PPDataProxy: PPDataProxy.return_value = mock.MagicMock() list(pp._interpret_fields([f1, self.land_mask_field, f2])) for call in PPDataProxy.call_args_list: positional_args = call[0] self.assertIs(positional_args[7], self.land_mask_field)
def test_shared_land_mask_field(self): # Check that multiple land masked fields share the # land mask field instance. f1 = deepcopy(self.pp_field) f2 = deepcopy(self.pp_field) self.assertIsNot(f1, f2) with mock.patch('iris.fileformats.pp.PPDataProxy') as PPDataProxy: PPDataProxy.return_value = mock.MagicMock() list(pp._interpret_fields([f1, self.land_mask_field, f2])) for call in PPDataProxy.call_args_list: positional_args = call[0] self.assertIs(positional_args[8], self.land_mask_field)
def test_deferred_fix_lbrow_lbnpt(self): # Check the fix is also applied to fields which are deferred. f1, mask = self.pp_field, self.land_mask_field list(pp._interpret_fields([f1, mask])) self.assertEqual(f1.lbrow, 3) self.assertEqual(f1.lbnpt, 4)
def test_deferred_mask_field(self): # Check that the order of the load is yielded last if the mask # hasn't yet been seen. result = list(pp._interpret_fields([self.pp_field, self.land_mask_field])) self.assertEqual(result, [self.land_mask_field, self.pp_field])