def _pp_save_ppfield_values(cube): """ Emulate saving a cube as PP, and capture the resulting PP field values. """ # Create a test object to stand in for a real PPField. pp_field = mock.MagicMock(spec=pp.PPField3) # Add minimal content required by the pp.save operation. pp_field.HEADER_DEFN = pp.PPField3.HEADER_DEFN # Save cube to a dummy file, mocking the internally created PPField with mock.patch('iris.fileformats.pp.PPField3', return_value=pp_field): target_filelike = mock.Mock(name='target') target_filelike.mode = ('b') pp.save(cube, target_filelike) # Return pp-field mock with all the written properties return pp_field
def _pp_save_ppfield_values(cube): """ Emulate saving a cube as PP, and capture the resulting PP field values. """ # Create a test object to stand in for a real PPField. pp_field = mock.MagicMock(spec=pp.PPField3) # Add minimal content required by the pp.save operation. pp_field.HEADER_DEFN = pp.PPField3.HEADER_DEFN # Save cube to a dummy file, mocking the internally created PPField with mock.patch('iris.fileformats.pp.PPField3', return_value=pp_field): target_filelike = mock.Mock(name='target') target_filelike.mode = ('b') pp.save(cube, target_filelike) # Return pp-field mock with all the written properties return pp_field