def test_to_image_1D(self): """ Conversion to image """ # 1D p = projectable.Projectable(np.arange(25)) self.assertRaises(ValueError, to_image, p)
def test_to_image_2D(self, mock_geoimage): """ Conversion to image """ # 2D data = np.arange(25).reshape((5, 5)) p = projectable.Projectable(data, mode="L", fill_value=0, palette=[0, 1, 2, 3, 4, 5]) to_image(p) np.testing.assert_array_equal(data, mock_geoimage.call_args[0][0][0]) mock_geoimage.reset_mock()
def test_to_image_3D(self, mock_geoimage): """ Conversion to image """ # 3D data = np.arange(75).reshape((3, 5, 5)) p = projectable.Projectable(data) to_image(p) np.testing.assert_array_equal(data[0], mock_geoimage.call_args[0][0][0]) np.testing.assert_array_equal(data[1], mock_geoimage.call_args[0][0][1]) np.testing.assert_array_equal(data[2], mock_geoimage.call_args[0][0][2])
def test_str(self): # FIXME: Is there a better way to fake the area? class FakeArea(object): name = "fake_area" # Normal situation p = projectable.Projectable( np.arange(25), sensor="fake_sensor", wavelength_range=500, resolution=250, fake_attr="fakeattr", area=FakeArea(), ) p_str = str(p) # Not loaded data p = projectable.Projectable([]) p_str = str(p) self.assertTrue("not loaded" in p_str) # Data that doesn't have a shape p = projectable.Projectable(data=tuple()) p_str = str(p)
def test_resample_2D(self, mock_resampler): data = np.arange(25).reshape((5, 5)) mock_resampler.return_value = data p = projectable.Projectable(data) class FakeAreaDef: def __init__(self, name): self.name = name source_area = FakeAreaDef("here") destination_area = FakeAreaDef("there") p.info["area"] = source_area res = p.resample(destination_area) self.assertEqual(mock_resampler.call_count, 1) self.assertEqual(mock_resampler.call_args[0][0], source_area) self.assertEqual(mock_resampler.call_args[0][2], destination_area) np.testing.assert_array_equal(data, mock_resampler.call_args[0][1]) self.assertTrue(isinstance(res, projectable.Projectable)) np.testing.assert_array_equal(res.data, mock_resampler.return_value)
def test_show_unloaded(self): p = projectable.Projectable([]) self.assertRaises(ValueError, show, p)
def test_show(self, mock_get_image): data = np.arange(25).reshape((5, 5)) p = projectable.Projectable(data) show(p) self.assertTrue(mock_get_image.return_value.show.called)
def test_isloaded(self): """ Test isloaded method """ self.assertFalse(projectable.Projectable([]).is_loaded()) self.assertTrue(projectable.Projectable(data=1).is_loaded())
def test_init(self): """ Test initialization """ self.assertTrue('name' in projectable.Projectable([]).info)