def test_plot_map(self): # Test the nominal functionality. This doesn't check that the plot is what is expected, # rather, it simply tests if it seems to have been created dataset = xr.Dataset({ 'first': (['lat', 'lon', 'time'], np.random.rand(5, 10, 2)), 'second': (['lat', 'lon', 'time'], np.random.rand(5, 10, 2)), 'lat': np.linspace(-89.5, 89.5, 5), 'lon': np.linspace(-179.5, 179.5, 10), 'time': pd.date_range('2000-01-01', periods=2)}) with create_tmp_file('remove_me', 'png') as tmp_file: plot_map(dataset, file=tmp_file) self.assertTrue(os.path.isfile(tmp_file)) # Test if an error is raised when an unsupported format is passed with create_tmp_file('remove_me', 'pgm') as tmp_file: with self.assertRaises(ValueError): plot_map(dataset, file=tmp_file) self.assertFalse(os.path.isfile(tmp_file)) # Test if extents can be used with create_tmp_file('remove_me', 'pdf') as tmp_file: plot_map(dataset, var='second', region='-40.0, -20.0, 50.0, 60.0', file=tmp_file) self.assertTrue(os.path.isfile(tmp_file)) # Test time slice selection with create_tmp_file('remove_me', 'png') as tmp_file: plot_map(dataset, time='2000-01-01', file=tmp_file) self.assertTrue(os.path.isfile(tmp_file))
def test_plot_map(self): # Test the nominal functionality. This doesn't check that the plot is what is expected, # rather, it simply tests if it seems to have been created dataset = xr.Dataset({ 'first': (['lat', 'lon', 'time'], np.random.rand(5, 10, 2)), 'second': (['lat', 'lon', 'time'], np.random.rand(5, 10, 2)), 'lat': np.linspace(-89.5, 89.5, 5), 'lon': np.linspace(-179.5, 179.5, 10), 'time': pd.date_range('2000-01-01', periods=2)}) with create_tmp_file('remove_me', 'png') as tmp_file: plot_map(dataset, file=tmp_file) self.assertTrue(os.path.isfile(tmp_file)) # Test if an error is raised when an unsupported format is passed with create_tmp_file('remove_me', 'pgm') as tmp_file: with self.assertRaises(ValueError): plot_map(dataset, file=tmp_file) self.assertFalse(os.path.isfile(tmp_file)) # Test if extents can be used with create_tmp_file('remove_me', 'pdf') as tmp_file: plot_map(dataset, var='second', region='-40.0, -20.0, 50.0, 60.0', file=tmp_file) self.assertTrue(os.path.isfile(tmp_file)) # Test time slice selection with create_tmp_file('remove_me', 'png') as tmp_file: plot_map(dataset, indexers="time='2000-01-01'", file=tmp_file) self.assertTrue(os.path.isfile(tmp_file))
def test_plot_map_exceptions(self): # Test if the corner cases are detected without creating a plot for it. # Test value error is raised when passing an unexpected dataset type with create_tmp_file('remove_me', 'jpeg') as tmp_file: with self.assertRaises(ValueError) as cm: plot_map([1, 2, 4], file=tmp_file) self.assertEqual( str(cm.exception), "Input 'ds' for operation 'cate.ops.plot.plot_map' " "must be of type 'Dataset', but got type 'list'.") self.assertFalse(os.path.isfile(tmp_file)) # Test the extensions bound checking dataset = xr.Dataset({ 'first': (['lat', 'lon', 'time'], np.random.rand(2, 4, 1)), 'lat': np.linspace(-89.5, 89.5, 2), 'lon': np.linspace(-179.5, 179.5, 4) }) with self.assertRaises(ValueError): region = '-40.0, -95.0, 50.0, 60.0', plot_map(dataset, region=region) with self.assertRaises(ValueError): region = '-40.0, -20.0, 50.0, 95.0', plot_map(dataset, region=region) with self.assertRaises(ValueError): region = '-181.0, -20.0, 50.0, 60.0', plot_map(dataset, region=region) with self.assertRaises(ValueError): region = '-40.0, -20.0, 181.0, 60.0', plot_map(dataset, region=region) with self.assertRaises(ValueError): region = '-40.0, -20.0, 50.0, -25.0', plot_map(dataset, region=region) with self.assertRaises(ValueError): region = '-20.0, -20.0, -25.0, 60.0', plot_map(dataset, region=region) # Test temporal slice validation with self.assertRaises(ValueError): plot_map(dataset, time=0)
def test_plot_map_exceptions(self): # Test if the corner cases are detected without creating a plot for it. # Test value error is raised when passing an unexpected dataset type with self.assertRaises(NotImplementedError): plot_map([1, 2, 4], file='remove_me.jpeg') self.assertFalse(os.path.isfile('remove_me.jpg')) # Test the extensions bound checking dataset = xr.Dataset({ 'first': (['lat', 'lon', 'time'], np.random.rand(2, 4, 1)), 'lat': np.linspace(-89.5, 89.5, 2), 'lon': np.linspace(-179.5, 179.5, 4) }) with self.assertRaises(ValueError): region = '-40.0, -95.0, 50.0, 60.0', plot_map(dataset, region=region) with self.assertRaises(ValueError): region = '-40.0, -20.0, 50.0, 95.0', plot_map(dataset, region=region) with self.assertRaises(ValueError): region = '-181.0, -20.0, 50.0, 60.0', plot_map(dataset, region=region) with self.assertRaises(ValueError): region = '-40.0, -20.0, 181.0, 60.0', plot_map(dataset, region=region) with self.assertRaises(ValueError): region = '-40.0, -20.0, 50.0, -25.0', plot_map(dataset, region=region) with self.assertRaises(ValueError): region = '-20.0, -20.0, -25.0, 60.0', plot_map(dataset, region=region)
def test_plot_map_exceptions(self): # Test if the corner cases are detected without creating a plot for it. # Test value error is raised when passing an unexpected dataset type with create_tmp_file('remove_me', 'jpeg') as tmp_file: with self.assertRaises(ValueError) as cm: plot_map([1, 2, 4], file=tmp_file) self.assertEqual(str(cm.exception), "Input 'ds' for operation 'cate.ops.plot.plot_map' " "must be of type 'Dataset', but got type 'list'.") self.assertFalse(os.path.isfile(tmp_file)) # Test the extensions bound checking dataset = xr.Dataset({ 'first': (['lat', 'lon', 'time'], np.random.rand(2, 4, 1)), 'lat': np.linspace(-89.5, 89.5, 2), 'lon': np.linspace(-179.5, 179.5, 4)}) with self.assertRaises(ValueError): region = '-40.0, -95.0, 50.0, 60.0', plot_map(dataset, region=region) with self.assertRaises(ValueError): region = '-40.0, -20.0, 50.0, 95.0', plot_map(dataset, region=region) with self.assertRaises(ValueError): region = '-181.0, -20.0, 50.0, 60.0', plot_map(dataset, region=region) with self.assertRaises(ValueError): region = '-40.0, -20.0, 181.0, 60.0', plot_map(dataset, region=region) with self.assertRaises(ValueError): region = '-40.0, -20.0, 50.0, -25.0', plot_map(dataset, region=region) with self.assertRaises(ValueError): region = '-20.0, -20.0, -25.0, 60.0', plot_map(dataset, region=region) # Test temporal slice validation with self.assertRaises(ValueError): plot_map(dataset, time=0)