|
1 | | -# (C) British Crown Copyright 2014 - 2015, Met Office |
| 1 | +# (C) British Crown Copyright 2014 - 2017, Met Office |
2 | 2 | # |
3 | 3 | # This file is part of Iris. |
4 | 4 | # |
@@ -86,6 +86,47 @@ def _func(self): |
86 | 86 | return self.assertMaskedArrayEqual |
87 | 87 |
|
88 | 88 |
|
| 89 | +class Test_assertMaskedArrayEqual__Nonmaasked(tests.IrisTest): |
| 90 | + def test_nonmasked_same(self): |
| 91 | + # Masked test can be used on non-masked arrays. |
| 92 | + arr1 = np.array([1, 2]) |
| 93 | + self.assertMaskedArrayEqual(arr1, arr1) |
| 94 | + |
| 95 | + def test_masked_nonmasked_same(self): |
| 96 | + # Masked test can be used between masked + non-masked arrays, and will |
| 97 | + # consider them equal, when mask=None. |
| 98 | + arr1 = np.ma.masked_array([1, 2]) |
| 99 | + arr2 = np.array([1, 2]) |
| 100 | + self.assertMaskedArrayEqual(arr1, arr2) |
| 101 | + |
| 102 | + def test_masked_nonmasked_different(self): |
| 103 | + arr1 = np.ma.masked_array([1, 2]) |
| 104 | + arr2 = np.array([1, 3]) |
| 105 | + with self.assertRaisesRegexp(AssertionError, 'Arrays are not equal'): |
| 106 | + self.assertMaskedArrayEqual(arr1, arr2) |
| 107 | + |
| 108 | + def test_nonmasked_masked_same(self): |
| 109 | + # Masked test can be used between masked + non-masked arrays, and will |
| 110 | + # consider them equal, when mask=None. |
| 111 | + arr1 = np.array([1, 2]) |
| 112 | + arr2 = np.ma.masked_array([1, 2]) |
| 113 | + self.assertMaskedArrayEqual(arr1, arr2) |
| 114 | + |
| 115 | + def test_masked_nonmasked_same_falsemask(self): |
| 116 | + # Masked test can be used between masked + non-masked arrays, and will |
| 117 | + # consider them equal, when mask=False. |
| 118 | + arr1 = np.ma.masked_array([1, 2], mask=False) |
| 119 | + arr2 = np.array([1, 2]) |
| 120 | + self.assertMaskedArrayEqual(arr1, arr2) |
| 121 | + |
| 122 | + def test_masked_nonmasked_same_emptymask(self): |
| 123 | + # Masked test can be used between masked + non-masked arrays, and will |
| 124 | + # consider them equal, when mask=zeros. |
| 125 | + arr1 = np.ma.masked_array([1, 2], mask=[False, False]) |
| 126 | + arr2 = np.array([1, 2]) |
| 127 | + self.assertMaskedArrayEqual(arr1, arr2) |
| 128 | + |
| 129 | + |
89 | 130 | class Test_assertMaskedArrayAlmostEqual(_MaskedArrayEquality, tests.IrisTest): |
90 | 131 | @property |
91 | 132 | def _func(self): |
|
0 commit comments