Exemplo n.º 1
0
    def test_masked_array_float(self):
        value = ma.arange(10, dtype=np.float64)
        expected = self._masked(value)
        self.assertEqual(expected, hexdigest(value))

        value[0] = ma.masked
        self.assertNotEqual(expected, hexdigest(value))
        expected = self._masked(value)
        self.assertEqual(expected, hexdigest(value))
Exemplo n.º 2
0
    def test_instance(self):
        class Dummy:
            pass

        value = Dummy()
        expected = self._expected(value)
        self.assertEqual(expected, hexdigest(value))
Exemplo n.º 3
0
 def _summary_coord_extra(self, cube, coord):
     # Returns the text needed to ensure this coordinate can be
     # distinguished from all others with the same name.
     extra = ""
     similar_coords = cube.coords(coord.name())
     if len(similar_coords) > 1:
         # Find all the attribute keys
         keys = set()
         for similar_coord in similar_coords:
             keys.update(similar_coord.attributes.keys())
         # Look for any attributes that vary
         vary = set()
         attributes = {}
         for key in keys:
             for similar_coord in similar_coords:
                 if key not in similar_coord.attributes:
                     vary.add(key)
                     break
                 value = similar_coord.attributes[key]
                 # Like "if attributes.setdefault(key, value) != value:"
                 # ..except setdefault fails if values are numpy arrays.
                 if key not in attributes:
                     attributes[key] = value
                 elif hexdigest(attributes[key]) != hexdigest(value):
                     # NOTE: fast and array-safe comparison, as used in
                     # :mod:`iris.common.metadata`.
                     vary.add(key)
                     break
         keys = sorted(vary & set(coord.attributes.keys()))
         bits = [
             "{}={}".format(
                 key, value_repr(coord.attributes[key], quote_strings=True)
             )
             for key in keys
         ]
         if bits:
             extra = ", ".join(bits)
     return extra
Exemplo n.º 4
0
 def test_numpy_array_reshape_not_flat(self):
     value = np.arange(10).reshape(2, 5)
     expected = self._ndarray(value)
     self.assertNotEqual(expected, hexdigest(value.flatten()))
Exemplo n.º 5
0
 def test_dict(self):
     value = dict(one=1, two=2, three=3)
     expected = self._expected(value)
     self.assertEqual(expected, hexdigest(value))
Exemplo n.º 6
0
 def test_numpy_array_float(self):
     value = np.arange(10, dtype=np.float64)
     expected = self._ndarray(value)
     self.assertEqual(expected, hexdigest(value))
Exemplo n.º 7
0
 def test_numpy_array_reshape(self):
     value = np.arange(10).reshape(2, 5)
     expected = self._ndarray(value)
     self.assertEqual(expected, hexdigest(value))
Exemplo n.º 8
0
 def test_int_not_str(self):
     value = 123
     expected = self._expected(value)
     self.assertNotEqual(expected, hexdigest(str(value)))
Exemplo n.º 9
0
 def test_string(self):
     value = "hello world"
     self.hasher.update(value)
     expected = self.hasher.hexdigest()
     self.assertEqual(expected, hexdigest(value))
Exemplo n.º 10
0
 def test_masked_array_not_array(self):
     value = ma.arange(10)
     expected = self._masked(value)
     self.assertNotEqual(expected, hexdigest(value.data))
Exemplo n.º 11
0
 def test_masked_array_reshape(self):
     value = ma.arange(10).reshape(2, 5)
     expected = self._masked(value)
     self.assertEqual(expected, hexdigest(value))
Exemplo n.º 12
0
 def test_tuple(self):
     value = (1, 2, 3)
     expected = self._expected(value)
     self.assertEqual(expected, hexdigest(value))
Exemplo n.º 13
0
 def test_masked_array_float_not_int(self):
     ivalue = ma.arange(10, dtype=np.int_)
     fvalue = ma.arange(10, dtype=np.float64)
     expected = self._masked(ivalue)
     self.assertNotEqual(expected, hexdigest(fvalue))
Exemplo n.º 14
0
 def test_list(self):
     value = [1, 2, 3]
     expected = self._expected(value)
     self.assertEqual(expected, hexdigest(value))
Exemplo n.º 15
0
 def test_numpy_float(self):
     value = float(123.4)
     expected = self._expected(value)
     self.assertEqual(expected, hexdigest(value))
Exemplo n.º 16
0
 def test_float(self):
     value = 123.4
     expected = self._expected(value)
     self.assertEqual(expected, hexdigest(value))
Exemplo n.º 17
0
 def test_numpy_int(self):
     value = int(123)
     expected = self._expected(value)
     self.assertEqual(expected, hexdigest(value))
Exemplo n.º 18
0
 def test_masked_array_reshape_not_flat(self):
     value = ma.arange(10).reshape(2, 5)
     expected = self._masked(value)
     self.assertNotEqual(expected, hexdigest(value.flatten()))
Exemplo n.º 19
0
 def test_sentinel(self):
     value = mock.sentinel.value
     expected = self._expected(value)
     self.assertEqual(expected, hexdigest(value))
Exemplo n.º 20
0
 def test_numpy_array_float_not_int(self):
     ivalue = np.arange(10, dtype=np.int)
     fvalue = np.arange(10, dtype=np.float)
     expected = self._ndarray(ivalue)
     self.assertNotEqual(expected, hexdigest(fvalue))