Commit 07f0add8 authored by Florent Jaillet's avatar Florent Jaillet

Update tests to avoid warnings and errors with newer versions of the dependencies

parent 295ea36a
Pipeline #1375 passed with stage
in 35 seconds
madarrays:1.1.0
madarrays:1.1.1
......@@ -51,4 +51,4 @@ from .mad_array import MadArray
from .waveform import Waveform
__all__ = ['MadArray', 'Waveform']
__version__ = "1.1.0"
__version__ = "1.1.1"
......@@ -64,7 +64,7 @@ from .utils import generate_mask_50
def get_data(request):
# Dimension and shape of data
n_dims = np.random.randint(1, 3)
request.cls.shape = 2 * np.random.randint(20, 50, n_dims)
request.cls.shape = tuple(2 * np.random.randint(20, 50, n_dims))
# For each dtype, generate two sets of data
request.cls.x_float = np.random.random(request.cls.shape)
......@@ -89,9 +89,10 @@ def get_data(request):
request.cls.mm2 = generate_mask_50(request.cls.shape)
# List of indices for the indexation
request.cls.indexes = [slice(item, np.random.randint(item + 1, dim_size))
for dim_size in request.cls.shape
for item in [np.random.randint(0, dim_size - 1)]]
request.cls.indexes = tuple(
slice(item, np.random.randint(item + 1, dim_size))
for dim_size in request.cls.shape
for item in [np.random.randint(0, dim_size - 1)])
request.cls.empty_mask = np.zeros(request.cls.shape, dtype=np.bool)
request.cls.full_mask = np.ones(request.cls.shape, dtype=np.bool)
......@@ -157,8 +158,8 @@ class TestMadArray:
bad_shape = [item + np.random.randint(1, 100) for item in self.shape]
match = 'Mask shape \(\d+,( \d+)?\) and data shape \(\d+,( \d+)?\) '\
'not compatible.'
match = r'Mask shape \(\d+,( \d+)?\) and data shape \(\d+,( \d+)?\) '\
r'not compatible.'
with pytest.raises(ValueError, match=match):
MadArray(self.x_float, np.random.random(bad_shape) < 0.3)
......@@ -277,14 +278,14 @@ class TestMadArray:
bad_shape = [item + np.random.randint(1, 100) for item in self.shape]
match = 'Phase mask shape \(\d+,( \d+)?\) and data shape '\
'\(\d+,( \d+)?\) not compatible.'
match = r'Phase mask shape \(\d+,( \d+)?\) and data shape '\
r'\(\d+,( \d+)?\) not compatible.'
with pytest.raises(ValueError, match=match):
MadArray(self.x_complex,
mask_phase=np.random.random(bad_shape) < 0.8)
match = 'Magnitude mask shape \(\d+,( \d+)?\) and data shape '\
'\(\d+,( \d+)?\) not compatible.'
match = r'Magnitude mask shape \(\d+,( \d+)?\) and data shape '\
r'\(\d+,( \d+)?\) not compatible.'
with pytest.raises(ValueError, match=match):
MadArray(self.x_complex,
mask_magnitude=np.random.random(bad_shape) < 0.8)
......@@ -396,8 +397,10 @@ class TestMadArray:
assert isinstance(ma_slice, MadArray)
np.testing.assert_equal(ma_slice, self.x_float[self.indexes])
np.testing.assert_equal(ma_slice.get_unknown_mask(), self.m[self.indexes])
np.testing.assert_equal(ma_slice.get_known_mask(), ~self.m[self.indexes])
np.testing.assert_equal(ma_slice.get_unknown_mask(),
self.m[self.indexes])
np.testing.assert_equal(ma_slice.get_known_mask(),
~self.m[self.indexes])
assert ma_slice.ratio_missing_data == np.mean(self.m[self.indexes])
assert ma_slice.n_missing_data == np.sum(self.m[self.indexes])
assert ma.is_masked()
......@@ -406,13 +409,13 @@ class TestMadArray:
ma = MadArray(self.x_float, mask=self.m, masked_indexing=True)
m_index = np.zeros(self.shape, dtype=np.bool)
m_index[self.indexes] = 1
m_index[self.indexes] = True
ma_slice = ma[self.indexes]
assert isinstance(ma_slice, MadArray)
np.testing.assert_equal(ma_slice.shape, self.shape)
np.testing.assert_equal(ma_slice, self.x_float)
assert ma_slice.shape == self.shape
assert np.all(ma_slice == self.x_float)
np.testing.assert_equal(ma_slice.get_unknown_mask(),
np.logical_or(~m_index, self.m))
np.testing.assert_equal(ma_slice.get_known_mask(),
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment