def _grid_mapping_variable(self, coord_system): """ Return a mock netCDF variable that represents the conversion of the given coordinate system. """ cube = self._cube_with_cs(coord_system) class NCMock(mock.Mock): def setncattr(self, name, attr): setattr(self, name, attr) # Calls the actual NetCDF saver with appropriate mocking, returning # the grid variable that gets created. grid_variable = NCMock(name='NetCDFVariable') create_var_fn = mock.Mock(side_effect=[grid_variable]) dataset = mock.Mock(variables=[], createVariable=create_var_fn) saver = mock.Mock(spec=Saver, _coord_systems=[], _dataset=dataset) variable = NCMock() # This is the method we're actually testing! Saver._create_cf_grid_mapping(saver, cube, variable) self.assertEqual(create_var_fn.call_count, 1) self.assertEqual(variable.grid_mapping, grid_variable.grid_mapping_name) return grid_variable
def _grid_mapping_variable(self, coord_system): """ Return a mock netCDF variable that represents the conversion of the given coordinate system. """ cube = self._cube_with_cs(coord_system) class NCMock(mock.Mock): def setncattr(self, name, attr): setattr(self, name, attr) # Calls the actual NetCDF saver with appropriate mocking, returning # the grid variable that gets created. grid_variable = NCMock(name='NetCDFVariable') create_var_fn = mock.Mock(side_effect=[grid_variable]) dataset = mock.Mock(variables=[], createVariable=create_var_fn) saver = mock.Mock(spec=Saver, _coord_systems=[], _dataset=dataset) variable = NCMock() # This is the method we're actually testing! Saver._create_cf_grid_mapping(saver, cube, variable) self.assertEqual(create_var_fn.call_count, 1) self.assertEqual(variable.grid_mapping, grid_variable.grid_mapping_name) return grid_variable
def construct_cf_grid_mapping_variable(self, cube): # Calls the actual NetCDF saver with appropriate mocking, returning # the grid variable that gets created. grid_variable = mock.Mock(name='NetCDFVariable') create_var_fn = mock.Mock(side_effect=[grid_variable]) dataset = mock.Mock(variables=[], createVariable=create_var_fn) saver = mock.Mock(spec=Saver, _coord_systems=[], _dataset=dataset) variable = mock.Mock() Saver._create_cf_grid_mapping(saver, cube, variable) self.assertEqual(create_var_fn.call_count, 1) self.assertEqual(variable.grid_mapping, grid_variable.grid_mapping_name) return grid_variable
def construct_cf_grid_mapping_variable(self, cube): # Calls the actual NetCDF saver with appropriate mocking, returning # the grid variable that gets created. grid_variable = mock.Mock(name='NetCDFVariable') create_var_fn = mock.Mock(side_effect=[grid_variable]) dataset = mock.Mock(variables=[], createVariable=create_var_fn) saver = mock.Mock(spec=Saver, _coord_systems=[], _dataset=dataset) variable = mock.Mock() Saver._create_cf_grid_mapping(saver, cube, variable) self.assertEqual(create_var_fn.call_count, 1) self.assertEqual(variable.grid_mapping, grid_variable.grid_mapping_name) return grid_variable