Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/iris/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ def _assertMaskedArray(self, assertion, a, b, strict, **kwargs):
# Define helper function to extract unmasked values as a 1d
# array.
def unmasked_data_as_1d_array(array):
array = ma.asarray(array)
if array.ndim == 0:
if array.mask:
data = np.array([])
Expand Down
43 changes: 42 additions & 1 deletion lib/iris/tests/unit/tests/test_IrisTest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) British Crown Copyright 2014 - 2015, Met Office
# (C) British Crown Copyright 2014 - 2017, Met Office
#
# This file is part of Iris.
#
Expand Down Expand Up @@ -86,6 +86,47 @@ def _func(self):
return self.assertMaskedArrayEqual


class Test_assertMaskedArrayEqual__Nonmaasked(tests.IrisTest):
def test_nonmasked_same(self):
# Masked test can be used on non-masked arrays.
arr1 = np.array([1, 2])
self.assertMaskedArrayEqual(arr1, arr1)

def test_masked_nonmasked_same(self):
# Masked test can be used between masked + non-masked arrays, and will
# consider them equal, when mask=None.
arr1 = np.ma.masked_array([1, 2])
arr2 = np.array([1, 2])
self.assertMaskedArrayEqual(arr1, arr2)

def test_masked_nonmasked_different(self):
arr1 = np.ma.masked_array([1, 2])
arr2 = np.array([1, 3])
with self.assertRaisesRegexp(AssertionError, 'Arrays are not equal'):
self.assertMaskedArrayEqual(arr1, arr2)

def test_nonmasked_masked_same(self):
# Masked test can be used between masked + non-masked arrays, and will
# consider them equal, when mask=None.
arr1 = np.array([1, 2])
arr2 = np.ma.masked_array([1, 2])
self.assertMaskedArrayEqual(arr1, arr2)

def test_masked_nonmasked_same_falsemask(self):
# Masked test can be used between masked + non-masked arrays, and will
# consider them equal, when mask=False.
arr1 = np.ma.masked_array([1, 2], mask=False)
arr2 = np.array([1, 2])
self.assertMaskedArrayEqual(arr1, arr2)

def test_masked_nonmasked_same_emptymask(self):
# Masked test can be used between masked + non-masked arrays, and will
# consider them equal, when mask=zeros.
arr1 = np.ma.masked_array([1, 2], mask=[False, False])
arr2 = np.array([1, 2])
self.assertMaskedArrayEqual(arr1, arr2)


class Test_assertMaskedArrayAlmostEqual(_MaskedArrayEquality, tests.IrisTest):
@property
def _func(self):
Expand Down