From 07f0add8b173238c671821182e8d0390795d4e94 Mon Sep 17 00:00:00 2001
From: Florent Jaillet <florent.jaillet@lis-lab.fr>
Date: Wed, 17 Oct 2018 15:03:29 +0200
Subject: [PATCH] Update tests to avoid warnings and errors with newer versions
 of the dependencies

---
 VERSION                          |  2 +-
 madarrays/__init__.py            |  2 +-
 madarrays/tests/test_madarray.py | 33 ++++++-----
 madarrays/tests/test_waveform.py | 98 ++++++++++++++++----------------
 4 files changed, 69 insertions(+), 66 deletions(-)

diff --git a/VERSION b/VERSION
index 91c9ea6..cf9fe2e 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-madarrays:1.1.0
+madarrays:1.1.1
diff --git a/madarrays/__init__.py b/madarrays/__init__.py
index 97be4db..55926df 100644
--- a/madarrays/__init__.py
+++ b/madarrays/__init__.py
@@ -51,4 +51,4 @@ from .mad_array import MadArray
 from .waveform import Waveform
 
 __all__ = ['MadArray', 'Waveform']
-__version__ = "1.1.0"
+__version__ = "1.1.1"
diff --git a/madarrays/tests/test_madarray.py b/madarrays/tests/test_madarray.py
index 87d07d5..2a43e42 100644
--- a/madarrays/tests/test_madarray.py
+++ b/madarrays/tests/test_madarray.py
@@ -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(),
diff --git a/madarrays/tests/test_waveform.py b/madarrays/tests/test_waveform.py
index 5ca6de8..2fe268e 100644
--- a/madarrays/tests/test_waveform.py
+++ b/madarrays/tests/test_waveform.py
@@ -195,22 +195,22 @@ class TestWaveform:
 
         # Non-stereo
         with pytest.raises(ValueError,
-                           match='`data` should be either mono or stereo.'):
+                           match=r'`data` should be either mono or stereo.'):
             Waveform(np.random.rand(100, 1000), fs=44100)
 
         # Non 1D or 2D array
         with pytest.raises(ValueError,
-                           match='`data` should be either mono or stereo.'):
+                           match=r'`data` should be either mono or stereo.'):
             Waveform(np.random.rand(2, 100, 1000), fs=44100)
 
         # Negative frequency sampling
-        match = 'fs is not strictly positive \(given: -\d+\)'
+        match = r'fs is not strictly positive \(given: -\d+\)'
         with pytest.raises(ValueError, match=match):
             Waveform(self.x_mono, fs=-self.fs)
 
         # Frequency sampling equal to 0
         with pytest.raises(ValueError,
-                           match='fs is not strictly positive \(given: 0\)'):
+                           match=r'fs is not strictly positive \(given: 0\)'):
             Waveform(self.x_mono, fs=0)
 
     def test_init_from_waveform(self):
@@ -227,9 +227,9 @@ class TestWaveform:
         np.testing.assert_array_equal(w2._mask, w._mask)
 
         w = MadArray(self.x_mono, mask_magnitude=self.m_mono)
-        match = ('Construction of a Waveform from a MadArray with '
-                 'complex masking: the original masking data are '
-                 'discarded and a boolean mask set to False is used.')
+        match = (r'Construction of a Waveform from a MadArray with '
+                 r'complex masking: the original masking data are '
+                 r'discarded and a boolean mask set to False is used.')
         with pytest.warns(UserWarning, match=match):
             w2 = Waveform(w)
             np.testing.assert_array_equal(
@@ -285,18 +285,18 @@ class TestWaveform:
         # Negative frequency sampling
         with pytest.raises(
                 ValueError,
-                match='`fs` should be a positive number \(given: -\d+\)'):
+                match=r'`fs` should be a positive number \(given: -\d+\)'):
             w.resample(fs=-self.fs)
 
         # Frequency sampling equal to 0
         with pytest.raises(
                 ValueError,
-                match='`fs` should be a positive number \(given: 0\)'):
+                match=r'`fs` should be a positive number \(given: 0\)'):
             w.resample(fs=0)
 
         # Masked data
         w = Waveform(self.x_mono, mask=self.m_mono, fs=self.fs)
-        with pytest.raises(ValueError, match='Waveform has missing entries.'):
+        with pytest.raises(ValueError, match=r'Waveform has missing entries.'):
             w.resample(fs=fs)
 
     def test_set_rms(self):
@@ -312,7 +312,7 @@ class TestWaveform:
         # Negative rms
         with pytest.raises(
                 ValueError,
-                match='`rms` should be a positive float \(given: -1\)'):
+                match=r'`rms` should be a positive float \(given: -1\)'):
             w.set_rms(-1)
 
         # Int
@@ -321,7 +321,7 @@ class TestWaveform:
             # Getting RMS
             with pytest.raises(
                     NotImplementedError,
-                    match='RMS is not available for integer data types'):
+                    match=r'RMS is not available for integer data types'):
                 w_int.rms
 
     def test_clip_float(self):
@@ -342,7 +342,7 @@ class TestWaveform:
 
         # Clipping from below
         w = Waveform(x_below_clip)
-        match = 'float\d+ values lower than -\d+.\d+ have been clipped.'
+        match = r'float\d+ values lower than -\d+.\d+ have been clipped.'
         with pytest.warns(UserWarning, match=match):
             w.clip(min_value=min_value)
         assert_clipping(x_clipped=w, x_ref=x_below_clip,
@@ -350,7 +350,7 @@ class TestWaveform:
 
         # Clipping by above
         w = Waveform(x_above_clip)
-        match = 'float\d+ values greater than \d+.\d+ have been clipped.'
+        match = r'float\d+ values greater than \d+.\d+ have been clipped.'
         with pytest.warns(UserWarning, match=match):
             w.clip(max_value=max_value)
 
@@ -379,8 +379,8 @@ class TestWaveform:
                         min_value=min_value, max_value=max_value)
 
         # Clipping from below of the real part
-        match = 'Real part of the complex entries: float\d+ values lower than'\
-                ' -\d+.\d+ have been clipped.'
+        match = r'Real part of the complex entries: float\d+ values lower '\
+                r'than -\d+.\d+ have been clipped.'
         w = Waveform(x_real_below_clip)
 
         with pytest.warns(UserWarning, match=match):
@@ -392,8 +392,8 @@ class TestWaveform:
                         min_value=min_value, max_value=max_value)
 
         # Clipping by above of the imaginary part
-        match = 'Imaginary part of the complex entries: float\d+ values '\
-                'greater than \d+.\d+ have been clipped.'
+        match = r'Imaginary part of the complex entries: float\d+ values '\
+                r'greater than \d+.\d+ have been clipped.'
         w = Waveform(x_imag_above_clip)
 
         with pytest.warns(UserWarning, match=match):
@@ -406,7 +406,7 @@ class TestWaveform:
 
     def test_astype_float_float(self):
 
-        match = 'float\d+ values greater than \d+.\d+ have been clipped.'
+        match = r'float\d+ values greater than \d+.\d+ have been clipped.'
         for dtype_src, w_src in self.w_float_ref.items():
             for dtype_targ, w_targ in self.w_float_ref.items():
                 print('Casting from {} to {}.'.format(dtype_src, dtype_targ))
@@ -451,7 +451,7 @@ class TestWaveform:
 
     def test_astype_complex_complex(self):
 
-        match = 'float\d+ values greater than \d+.\d+ have been clipped.'
+        match = r'float\d+ values greater than \d+.\d+ have been clipped.'
         for dtype_src, w_src in self.w_complex_ref.items():
             for dtype_targ, w_targ in self.w_complex_ref.items():
                 print('Casting from {} to {}.'.format(dtype_src, dtype_targ))
@@ -477,7 +477,7 @@ class TestWaveform:
                         w_est, w_targ, atol=atol, rtol=0)
 
     def test_astype_float_int(self):
-        match = 'float\d+ values greater than \d+.\d+ have been clipped.'
+        match = r'float\d+ values greater than \d+.\d+ have been clipped.'
         for dtype_src, w_src in self.w_float_ref.items():
             for dtype_targ, w_targ in self.w_int_ref.items():
                 print('Casting from {} to {}.'.format(dtype_src, dtype_targ))
@@ -510,7 +510,7 @@ class TestWaveform:
                 assert w_est.dtype == w_targ.dtype
 
     def test_astype_float_complex(self):
-        match = 'float\d+ values greater than \d+.\d+ have been clipped.'
+        match = r'float\d+ values greater than \d+.\d+ have been clipped.'
         for dtype_src, w_src in self.w_float_ref.items():
             for dtype_targ, w_targ in self.w_complex_ref.items():
                 print('Casting from {} to {}.'.format(dtype_src, dtype_targ))
@@ -538,7 +538,7 @@ class TestWaveform:
                                                atol=atol, rtol=0, err_msg=msg)
 
     def test_astype_complex_float(self):
-        match = 'float\d+ values greater than \d+.\d+ have been clipped.'
+        match = r'float\d+ values greater than \d+.\d+ have been clipped.'
         for dtype_src, w_src in self.w_complex_ref.items():
             for dtype_targ, w_targ in self.w_float_ref.items():
                 print('Casting from {} to {}.'.format(dtype_src, dtype_targ))
@@ -577,7 +577,7 @@ class TestWaveform:
                 assert w_est.dtype == w_targ.dtype
 
     def test_astype_invalid(self):
-        match = "Unsupported target type <class 'list'>."
+        match = r"Unsupported target type <class 'list'>."
         with pytest.raises(TypeError, match=match):
             self.w_float_ref[np.float64].astype(list)
 
@@ -586,8 +586,8 @@ class TestWaveform:
 
     def test_to_wavfile_mono(self):
 
-        match = 'Complex values have been stored by keeping only the real '\
-                'part, the imaginary part has been discarded.'
+        match = r'Complex values have been stored by keeping only the real '\
+                r'part, the imaginary part has been discarded.'
 
         for fs in FS:
             for dtype in (INT_DTYPES + FLT_DTYPES + CPX_DTYPES):
@@ -640,8 +640,8 @@ class TestWaveform:
 
     def test_to_wavfile_stereo(self):
 
-        match = 'Complex values have been stored by keeping only the real '\
-            'part, the imaginary part has been discarded.'
+        match = r'Complex values have been stored by keeping only the real '\
+            r'part, the imaginary part has been discarded.'
         for fs in FS:
             for dtype in (INT_DTYPES + FLT_DTYPES + CPX_DTYPES):
                 print('Fs: {:d}, dtype: {}]'.format(fs, dtype))
@@ -707,7 +707,7 @@ class TestWaveform:
         # Unsupported fs
         w = Waveform(self.x_mono, fs=1234)
 
-        match = '`fs` is not a valid sampling frequency \(given: 1234\).'
+        match = r'`fs` is not a valid sampling frequency \(given: 1234\).'
         with pytest.raises(ValueError, match=match):
             w.to_wavfile('')
 
@@ -776,7 +776,7 @@ class TestWaveform:
             assert w_stereo.fs == fs_stereo
             assert w_stereo.is_stereo()
 
-            match = '`conversion_to_mono` in invalid \(given: center\).'
+            match = r'`conversion_to_mono` in invalid \(given: center\).'
             with pytest.raises(ValueError, match=match):
                 Waveform.from_wavfile(
                     tmp_file.name, conversion_to_mono='center')
@@ -808,7 +808,7 @@ class TestWaveform:
         # Unknows complex mode
         with pytest.raises(
                 ValueError,
-                match='Unknown complex mode \(given: realandimag\).'):
+                match=r'Unknown complex mode \(given: realandimag\).'):
             w.plot(cpx_mode='realandimag')
 
     def test_copy(self):
@@ -848,14 +848,14 @@ class TestWaveform:
         w = Waveform(self.x_mono, mask=self.m_mono,
                      fs=self.fs).astype(np.complex128)
 
-        with pytest.warns(UserWarning, match='Only the real part is played.'):
+        with pytest.warns(UserWarning, match=r'Only the real part is played.'):
             player = w.show_player()
         assert isinstance(player, Audio)
 
         # Wrong frequency sampling
         w = Waveform(self.x_mono, mask=self.m_mono, fs=1)
         with pytest.raises(ValueError,
-                           match='Invalid sampling frequency: \d+Hz'):
+                           match=r'Invalid sampling frequency: \d+Hz'):
             w.show_player()
 
         with mock.patch.dict('sys.modules', {'IPython.display': None}):
@@ -892,7 +892,7 @@ class TestWaveform:
 
                 if np.issubdtype(dtype, np.complexfloating):
                     with pytest.warns(UserWarning,
-                                      match='Only the real part is played.'):
+                                      match=r'Only the real part is played.'):
                         w.play()
                 else:
                     w.play()
@@ -902,7 +902,7 @@ class TestWaveform:
 
                 if np.issubdtype(dtype, np.complexfloating):
                     with pytest.warns(UserWarning,
-                                      match='Only the real part is played.'):
+                                      match=r'Only the real part is played.'):
                         w.play(scale=True)
                 else:
                     w.play(scale=True)
@@ -914,7 +914,7 @@ class TestWaveform:
         w = Waveform(np.zeros(1000), fs=1)
 
         with pytest.raises(ValueError,
-                           match='Invalid sampling frequency: 1Hz'):
+                           match=r'Invalid sampling frequency: 1Hz'):
             w.play()
 
         if is_patched:
@@ -938,7 +938,7 @@ class TestWaveform:
 
                 if np.issubdtype(dtype, np.complexfloating):
                     with pytest.warns(UserWarning,
-                                      match='Only the real part is played.'):
+                                      match=r'Only the real part is played.'):
                         try:
                             w.play()
                         except sa._simpleaudio.SimpleaudioError:
@@ -954,7 +954,7 @@ class TestWaveform:
 
                 if np.issubdtype(dtype, np.complexfloating):
                     with pytest.warns(UserWarning,
-                                      match='Only the real part is played.'):
+                                      match=r'Only the real part is played.'):
                         try:
                             w.play(scale=True)
                         except sa._simpleaudio.SimpleaudioError:
@@ -972,7 +972,7 @@ class TestWaveform:
         w = Waveform(np.zeros(1000), fs=1)
 
         with pytest.raises(ValueError,
-                           match='Invalid sampling frequency: 1Hz'):
+                           match=r'Invalid sampling frequency: 1Hz'):
             try:
                 w.play()
             except sa._simpleaudio.SimpleaudioError:
@@ -983,7 +983,7 @@ class TestWaveform:
         for x, m in zip([self.x_mono, self.x_stereo],
                         [self.m_mono, self.m_stereo]):
             with pytest.raises(TypeError,
-                               match='Waveform has missing samples'):
+                               match=r'Waveform has missing samples'):
                 Waveform(x, mask=m, fs=self.fs).get_analytic_signal()
 
             w = Waveform(x, fs=self.fs)
@@ -1023,7 +1023,7 @@ class TestWaveform:
             assert isinstance(ws, Waveform)
             np.testing.assert_equal(ws, xs)
 
-            match = 'Waveforms do not have the same fs: \d+ and \d+'
+            match = r'Waveforms do not have the same fs: \d+ and \d+'
             with pytest.raises(ValueError, match=match):
                 eval('w1 {} w3'.format(operator))
 
@@ -1059,7 +1059,7 @@ class TestWaveform:
 
         assert np.all(w1 == w2)
 
-        match = 'Waveforms do not have the same fs: \d+ and \d+'
+        match = r'Waveforms do not have the same fs: \d+ and \d+'
         with pytest.raises(ValueError, match=match):
             w1 == w3
 
@@ -1123,30 +1123,30 @@ class TestWaveform:
         w = dict()
         for mode in all_modes:
             w[mode] = Waveform(self.x_mono, mask=self.m_mono, fs=self.fs)
-            match = 'Either `fade_duration` or `fade_length` must be given.'
+            match = r'Either `fade_duration` or `fade_length` must be given.'
             with pytest.raises(ValueError, match=match):
                 w[mode].fade(mode=mode)
 
-            match = '`fade_duration` and `fade_length` cannot be given '\
-                'simultaneously.'
+            match = r'`fade_duration` and `fade_length` cannot be given '\
+                r'simultaneously.'
             with pytest.raises(ValueError, match=match):
                 w[mode].fade(mode=mode,
                              fade_length=fade_len,
                              fade_duration=fade_dur)
 
-            match = 'Fade length \(\d+\) is greater than data length \(\d+\)'
+            match = r'Fade length \(\d+\) is greater than data length \(\d+\)'
             with pytest.raises(ValueError, match=match):
                 w[mode].fade(mode=mode, fade_length=self.length + 1)
 
             with pytest.raises(ValueError,
-                               match='Fade length cannot be negative.'):
+                               match=r'Fade length cannot be negative.'):
                 w[mode].fade(mode=mode, fade_length=-1)
 
             with pytest.raises(ValueError,
-                               match='Fade length cannot be negative.'):
+                               match=r'Fade length cannot be negative.'):
                 w[mode].fade(mode=mode, fade_duration=-1 / self.fs)
 
-        with pytest.raises(ValueError, match='Mode is unknown: stereo.'):
+        with pytest.raises(ValueError, match=r'Mode is unknown: stereo.'):
             w[mode].fade(mode='stereo', fade_length=fade_len)
 
     def test_pickle(self):
-- 
GitLab