Пример #1
0
 def test_divmod(self):
     """Checks the __divmod__ function.
     """
     a = dataset.Dataset([7, 3, 1], bla=2, blu='hej')
     b = dataset.Dataset([2, 1, 1], bla=2, bli='hoj')
     c = divmod(a, b)
     self.assertDictEqual(c[0].info, {'bla': 2})
     self.assertDictEqual(c[1].info, {'bla': 2})
     c = divmod(a, 1)
     self.assertDictEqual(c[0].info, a.info)
     self.assertDictEqual(c[1].info, a.info)
     c = divmod(1, a)
     self.assertDictEqual(c[0].info, a.info)
     self.assertDictEqual(c[1].info, a.info)
Пример #2
0
 def test_to_image_1D(self):
     """
     Conversion to image
     """
     # 1D
     p = dataset.Dataset(np.arange(25))
     self.assertRaises(ValueError, to_image, p)
Пример #3
0
 def test_truediv(self):
     """Checks the __truediv__ function.
     """
     a = dataset.Dataset([7., 3., 1.], bla=2, blu='hej')
     b = dataset.Dataset([2., 1., 1.], bla=2, bli='hoj')
     c = a.__truediv__(b)
     self.assertDictEqual(c.info, {'bla': 2})
     c = a.__truediv__(1)
     self.assertDictEqual(c.info, a.info)
     c = a.__rtruediv__(1)
     self.assertDictEqual(c.info, a.info)
     a = a.__itruediv__(b)
     self.assertDictEqual(a.info, {'bla': 2})
     b_info = b.info.copy()
     b = b.__itruediv__(1)
     self.assertDictEqual(b.info, b_info)
Пример #4
0
 def test_mul(self):
     """Checks the __mul__ function.
     """
     a = dataset.Dataset([7, 3, 1], bla=2, blu='hej')
     b = dataset.Dataset([2, 0, 0], bla=2, bli='hoj')
     c = a * b
     self.assertDictEqual(c.info, {'bla': 2})
     c = a * 1
     self.assertDictEqual(c.info, a.info)
     c = 1 * a
     self.assertDictEqual(c.info, a.info)
     a *= b
     self.assertDictEqual(a.info, {'bla': 2})
     b_info = b.info.copy()
     b *= 1
     self.assertDictEqual(b.info, b_info)
Пример #5
0
 def test_floordiv(self):
     """Checks the __floordiv__ function.
     """
     a = dataset.Dataset([7, 3, 1], bla=2, blu='hej')
     b = dataset.Dataset([2, 1, 1], bla=2, bli='hoj')
     c = a // b
     self.assertDictEqual(c.info, {'bla': 2})
     c = a // 1
     self.assertDictEqual(c.info, a.info)
     c = 1 // a
     self.assertDictEqual(c.info, a.info)
     a //= b
     self.assertDictEqual(a.info, {'bla': 2})
     b_info = b.info.copy()
     b //= 1
     self.assertDictEqual(b.info, b_info)
Пример #6
0
 def test_and(self):
     """Checks the __and__ function.
     """
     a = dataset.Dataset([7, 3, 1], bla=2, blu='hej')
     b = dataset.Dataset([2, 1, 1], bla=2, bli='hoj')
     c = a & b
     self.assertDictEqual(c.info, {'bla': 2})
     c = a & 1
     self.assertDictEqual(c.info, a.info)
     c = 1 & a
     self.assertDictEqual(c.info, a.info)
     a &= b
     self.assertDictEqual(a.info, {'bla': 2})
     b_info = b.info.copy()
     b &= 1
     self.assertDictEqual(b.info, b_info)
Пример #7
0
 def test_or(self):
     """Checks the __or__ function.
     """
     a = dataset.Dataset([7, 3, 1], bla=2, blu='hej')
     b = dataset.Dataset([2, 1, 1], bla=2, bli='hoj')
     c = a | b
     self.assertDictEqual(c.info, {'bla': 2})
     c = a | 1
     self.assertDictEqual(c.info, a.info)
     c = 1 | a
     self.assertDictEqual(c.info, a.info)
     a |= b
     self.assertDictEqual(a.info, {'bla': 2})
     b_info = b.info.copy()
     b |= 1
     self.assertDictEqual(b.info, b_info)
Пример #8
0
 def test_rshift(self):
     """Checks the __rshift__ function.
     """
     a = dataset.Dataset([7, 3, 1], bla=2, blu='hej')
     b = dataset.Dataset([2, 1, 1], bla=2, bli='hoj')
     c = a >> b
     self.assertDictEqual(c.info, {'bla': 2})
     c = a >> 1
     self.assertDictEqual(c.info, a.info)
     c = 1 >> a
     self.assertDictEqual(c.info, a.info)
     a >>= b
     self.assertDictEqual(a.info, {'bla': 2})
     b_info = b.info.copy()
     b >>= 1
     self.assertDictEqual(b.info, b_info)
Пример #9
0
 def test_mod(self):
     """Checks the __mod__ function.
     """
     a = dataset.Dataset([7, 3, 1], bla=2, blu='hej')
     b = dataset.Dataset([2, 1, 1], bla=2, bli='hoj')
     c = a % b
     self.assertDictEqual(c.info, {'bla': 2})
     c = a % 1
     self.assertDictEqual(c.info, a.info)
     c = 1 % a
     self.assertDictEqual(c.info, a.info)
     a %= b
     self.assertDictEqual(a.info, {'bla': 2})
     b_info = b.info.copy()
     b %= 1
     self.assertDictEqual(b.info, b_info)
Пример #10
0
 def test_sub(self):
     """Checks the __sub__ function.
     """
     a = dataset.Dataset([7, 3, 1], bla=2, blu='hej')
     b = dataset.Dataset([2, 0, 0], bla=2, bli='hoj')
     c = a - b
     self.assertDictEqual(c.info, {'bla': 2})
     c = a - 1
     self.assertDictEqual(c.info, a.info)
     c = 1 - a
     self.assertDictEqual(c.info, a.info)
     a -= b
     self.assertDictEqual(a.info, {'bla': 2})
     b_info = b.info.copy()
     b -= 1
     self.assertDictEqual(b.info, b_info)
Пример #11
0
 def test_add(self):
     """Checks the __add__ function.
     """
     a = dataset.Dataset([7, 3, 1], bla=2, blu='hej')
     b = dataset.Dataset([2, 0, 0], bla=2, bli='hoj')
     c = a + b
     self.assertDictEqual(c.info, {'bla': 2})
     c = a + 1
     self.assertDictEqual(c.info, a.info)
     c = 1 + a
     self.assertDictEqual(c.info, a.info)
     a += b
     self.assertDictEqual(a.info, {'bla': 2})
     b_info = b.info.copy()
     b += 1
     self.assertDictEqual(b.info, b_info)
Пример #12
0
 def test_init(self):
     """
     Test initialization
     """
     d = dataset.Dataset([])
     self.assertTrue(hasattr(d, 'info'))
     self.assertTrue(hasattr(d, 'shape'))
     self.assertTrue(d.shape == (0, ))
Пример #13
0
 def test_to_image_2D(self, mock_geoimage):
     """
     Conversion to image
     """
     # 2D
     data = np.arange(25).reshape((5, 5))
     p = dataset.Dataset(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()
Пример #14
0
 def test_copy(self):
     """
     Test copying a dataset
     """
     ds = dataset.Dataset(np.arange(8), foo="bar")
     ds_copy = ds.copy()
     self.assertTrue(ds_copy.data is not ds.data
                     and all(ds.data == ds_copy.data))
     if sys.version >= "2.7":
         self.assertDictEqual(ds.info, ds_copy.info)
Пример #15
0
 def test_to_image_3D(self, mock_geoimage):
     """
     Conversion to image
     """
     # 3D
     data = np.arange(75).reshape((3, 5, 5))
     p = dataset.Dataset(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])
Пример #16
0
    def test_str(self):
        # FIXME: Is there a better way to fake the area?
        class FakeArea(object):
            name = "fake_area"

        # Normal situation
        p = dataset.Dataset(
            np.arange(25),
            sensor="fake_sensor",
            wavelength=500,
            resolution=250,
            fake_attr="fakeattr",
            area=FakeArea(),
        )
        p_str = str(p)

        # Not loaded data
        p = dataset.Dataset([])
        p_str = str(p)
        self.assertTrue("not loaded" in p_str)

        # Data that doesn't have a shape
        p = dataset.Dataset(data=tuple())
        p_str = str(p)
Пример #17
0
    def test_resample_2D(self, mock_resampler):
        data = np.arange(25).reshape((5, 5))
        mock_resampler.return_value = data
        p = dataset.Dataset(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, dataset.Dataset))
        np.testing.assert_array_equal(res.data, mock_resampler.return_value)
Пример #18
0
 def test_abs(self):
     """Checks the __abs__ function.
     """
     a = dataset.Dataset([7, 3, 1], bla=2, blu='hej')
     c = abs(a)
     self.assertDictEqual(c.info, a.info)
Пример #19
0
 def test_str_repr(self):
     ds = dataset.Dataset(np.arange(1, 25), foo="bar")
     ds_str = str(ds)
     ds_repr = repr(ds)
Пример #20
0
 def test_isloaded(self):
     """
     Test isloaded method
     """
     self.assertFalse(dataset.Dataset([]).is_loaded())
     self.assertTrue(dataset.Dataset(data=1).is_loaded())
Пример #21
0
 def test_show(self, mock_get_image):
     data = np.arange(25).reshape((5, 5))
     p = dataset.Dataset(data)
     show(p)
     self.assertTrue(mock_get_image.return_value.show.called)
Пример #22
0
 def test_invert(self):
     """Checks the __invert__ function.
     """
     a = dataset.Dataset([7, 3, 1], bla=2, blu='hej')
     c = ~a
     self.assertDictEqual(c.info, a.info)
Пример #23
0
 def test_show_unloaded(self):
     p = dataset.Dataset([])
     self.assertRaises(ValueError, show, p)