From f29599abb5e51c1af2b89931db73a8e450682f5a Mon Sep 17 00:00:00 2001
From: Valentin Emiya <23557104+valentin-emiya@users.noreply.github.com>
Date: Thu, 11 Jul 2024 16:21:46 +0200
Subject: [PATCH] update tests

---
 .../tests/comp/test_assert_sigreshape_post.py | 23 ++++++++---------
 .../tests/comp/test_assert_sigreshape_pre.py  | 25 +++++++++----------
 ltfatpy/tests/comp/test_comp_sigreshape.py    | 23 +++++++++--------
 ltfatpy/tests/datasets/read_ref_mat.py        | 17 +++++++------
 4 files changed, 45 insertions(+), 43 deletions(-)

diff --git a/ltfatpy/tests/comp/test_assert_sigreshape_post.py b/ltfatpy/tests/comp/test_assert_sigreshape_post.py
index 27020e6..cf50d01 100644
--- a/ltfatpy/tests/comp/test_assert_sigreshape_post.py
+++ b/ltfatpy/tests/comp/test_assert_sigreshape_post.py
@@ -65,8 +65,7 @@ import unittest
 import random
 import numpy as np
 from ltfatpy.comp.assert_sigreshape_pre import assert_sigreshape_pre as aspre
-from ltfatpy.comp.assert_sigreshape_post import assert_sigreshape_post\
-                                                as aspost
+from ltfatpy.comp.assert_sigreshape_post import assert_sigreshape_post as aspost
 import functools
 
 
@@ -74,16 +73,16 @@ class TestAssertSigReshapePost(unittest.TestCase):
 
     # Called before the tests.
     def setUp(self):
-        print('Start TestAssertSigReshapePost')
+        print("Start TestAssertSigReshapePost")
 
     # Called after the tests.
     def tearDown(self):
-        print('Test done')
+        print("Test done")
 
     def test_default(self):
-        """ Basic usual cases """
+        """Basic usual cases"""
         L = random.randint(5, 200)
-        f = np.arange(0, L, dtype=np.float_)
+        f = np.arange(0, L, dtype=np.float64)
         (g, L, Ls, W, dim, permutedshape, order) = aspre(f)
         fres = aspost(f, dim, permutedshape, order)
         mess = "\nL = {0:d}, Ls = {1:d}, W = {2:d}, dim = {3:d}, g.shape = "
@@ -93,10 +92,10 @@ class TestAssertSigReshapePost(unittest.TestCase):
         np.testing.assert_array_equal(f, fres, mess)
 
     def test_twodim(self):
-        """ Many channels signals """
+        """Many channels signals"""
         shapef = tuple([random.randint(5, 20) for _ in range(2)])
-        L = functools.reduce(lambda x, y: x*y, shapef)
-        f = np.arange(0, L, dtype=np.complex_)
+        L = functools.reduce(lambda x, y: x * y, shapef)
+        f = np.arange(0, L, dtype=np.complex128)
         f = f.reshape(shapef)
         (g, L, Ls, W, dim, permutedshape, order) = aspre(f)
         fres = aspost(f, dim, permutedshape, order)
@@ -106,7 +105,7 @@ class TestAssertSigReshapePost(unittest.TestCase):
         mess = mess.format(L, Ls, W, dim)
         np.testing.assert_array_equal(f, fres, mess)
 
-if __name__ == '__main__':
-    suite = unittest.TestLoader().loadTestsFromTestCase(
-                                  TestAssertSigReshapePost)
+
+if __name__ == "__main__":
+    suite = unittest.TestLoader().loadTestsFromTestCase(TestAssertSigReshapePost)
     unittest.TextTestRunner(verbosity=2).run(suite)
diff --git a/ltfatpy/tests/comp/test_assert_sigreshape_pre.py b/ltfatpy/tests/comp/test_assert_sigreshape_pre.py
index 4acddc4..09c77a5 100644
--- a/ltfatpy/tests/comp/test_assert_sigreshape_pre.py
+++ b/ltfatpy/tests/comp/test_assert_sigreshape_pre.py
@@ -72,16 +72,16 @@ class TestAssertSigReshapePre(unittest.TestCase):
 
     # Called before the tests.
     def setUp(self):
-        print('Start TestAssertSigReshapePre')
+        print("Start TestAssertSigReshapePre")
 
     # Called after the tests.
     def tearDown(self):
-        print('Test done')
+        print("Test done")
 
     def test_default(self):
-        """ Basic usual cases """
+        """Basic usual cases"""
         L = random.randint(5, 200)
-        f = np.arange(0, L, dtype=np.float_)
+        f = np.arange(0, L, dtype=np.float64)
         (g, L, Ls, W, dim, _permutedshape, _order) = asp(f)
         mess = "\nL = {0:d}, Ls = {1:d}, W = {2:d}, dim = {3:d}, g.shape = "
         mess += str(g.shape) + ", f.shape = " + str(f.shape)
@@ -102,7 +102,7 @@ class TestAssertSigReshapePre(unittest.TestCase):
         self.assertEqual(dim, 0, mess)
 
     def test_list(self):
-        """ Basic signal in a list """
+        """Basic signal in a list"""
         L = random.randint(5, 200)
         f = [x for x in range(0, L)]
         (g, L, Ls, W, dim, _permutedshape, _order) = asp(f)
@@ -113,16 +113,16 @@ class TestAssertSigReshapePre(unittest.TestCase):
         self.assertEqual(L, L, mess)
         self.assertEqual(W, 1, mess)
         self.assertEqual(dim, 0, mess)
-        self.assertRaises(TypeError, asp, {'a': 1})
+        self.assertRaises(TypeError, asp, {"a": 1})
         self.assertRaises(TypeError, asp, f, L, (1, 0))
         self.assertRaises(TypeError, asp, f, L, -4)
         self.assertRaises(TypeError, asp, f, 5.5)
 
     def test_twodim(self):
-        """ Many channels signals """
+        """Many channels signals"""
         shapef = tuple([random.randint(5, 20) for _ in range(2)])
-        L = functools.reduce(lambda x, y: x*y, shapef)
-        f = np.arange(0, L, dtype=np.complex_)
+        L = functools.reduce(lambda x, y: x * y, shapef)
+        f = np.arange(0, L, dtype=np.complex128)
         f = f.reshape(shapef)
         (g, L, Ls, W, dim, _permutedshape, _order) = asp(f)
         mess = "\nL = {0:d}, Ls = {1:d}, W = {2:d}, dim = {3:d}, g.shape = "
@@ -133,7 +133,7 @@ class TestAssertSigReshapePre(unittest.TestCase):
         self.assertEqual(W, shapef[1], mess)
         self.assertEqual(dim, 0, mess)
         L = random.randint(5, 200)
-        f = np.arange(0, L, dtype=np.float_)
+        f = np.arange(0, L, dtype=np.float64)
         fcol = f.reshape((1, L))
         (g, L, Ls, W, dim, _permutedshape, _order) = asp(fcol)
         mess = "\nL = {0:d}, Ls = {1:d}, W = {2:d}, dim = {3:d}, g.shape = "
@@ -145,7 +145,6 @@ class TestAssertSigReshapePre(unittest.TestCase):
         self.assertEqual(dim, 1, mess)
 
 
-if __name__ == '__main__':
-    suite = unittest.TestLoader().loadTestsFromTestCase(
-                                  TestAssertSigReshapePre)
+if __name__ == "__main__":
+    suite = unittest.TestLoader().loadTestsFromTestCase(TestAssertSigReshapePre)
     unittest.TextTestRunner(verbosity=2).run(suite)
diff --git a/ltfatpy/tests/comp/test_comp_sigreshape.py b/ltfatpy/tests/comp/test_comp_sigreshape.py
index 63fa1ea..b77aff3 100644
--- a/ltfatpy/tests/comp/test_comp_sigreshape.py
+++ b/ltfatpy/tests/comp/test_comp_sigreshape.py
@@ -73,11 +73,11 @@ class TestCompSigReshape(unittest.TestCase):
 
     # Called before the tests.
     def setUp(self):
-        print('Start TestCompSigReshape')
+        print("Start TestCompSigReshape")
 
     # Called after the tests.
     def tearDown(self):
-        print('Test done')
+        print("Test done")
 
     def test_default(self):
         self.assertRaises(ValueError, cpre, "toto", 10)
@@ -85,9 +85,9 @@ class TestCompSigReshape(unittest.TestCase):
         self.assertRaises(ValueError, cpre, np.ones((10, 10, 2)), 1)
 
     def test_onedim(self):
-        """ One channel """
+        """One channel"""
         L = random.randint(5, 200)
-        f = np.arange(0, L, dtype=np.float_)
+        f = np.arange(0, L, dtype=np.float64)
         (fin, fl, W, wasrow, remembershape) = cpre(f, 0)
         fres = cpost(fin, fl, wasrow, remembershape)
         mess = "\nfl = {:d}, W = {:d}, wasrow = {:d},remembershape.shape = "
@@ -96,7 +96,7 @@ class TestCompSigReshape(unittest.TestCase):
         mess = mess.format(fl, W, wasrow)
         np.testing.assert_array_equal(f, fres, mess)
         L = random.randint(5, 200)
-        f = np.arange(0, L, dtype=np.float_)
+        f = np.arange(0, L, dtype=np.float64)
         f.resize((1, L))
         (fin, fl, W, wasrow, remembershape) = cpre(f, 0)
         fres = cpost(fin, fl, wasrow, remembershape)
@@ -107,10 +107,10 @@ class TestCompSigReshape(unittest.TestCase):
         np.testing.assert_array_equal(f, fres, mess)
 
     def test_twodim(self):
-        """ Many channels signals """
+        """Many channels signals"""
         shapef = tuple([random.randint(5, 20) for _ in range(2)])
-        L = functools.reduce(lambda x, y: x*y, shapef)
-        f = np.arange(0, L, dtype=np.complex_)
+        L = functools.reduce(lambda x, y: x * y, shapef)
+        f = np.arange(0, L, dtype=np.complex128)
         f = f.reshape(shapef)
         (fin, fl, W, wasrow, remembershape) = cpre(f, 1)
         fres = cpost(fin, fl, wasrow, remembershape)
@@ -121,10 +121,10 @@ class TestCompSigReshape(unittest.TestCase):
         np.testing.assert_array_equal(f, fres, mess)
 
     def test_multidim(self):
-        """ Multidimensionnal signals """
+        """Multidimensionnal signals"""
         shapef = tuple([random.randint(5, 20) for _ in range(4)])
         L = np.prod(shapef)
-        f = np.arange(0, L, dtype=np.complex_)
+        f = np.arange(0, L, dtype=np.complex128)
         f = f.reshape(shapef)
         (fin, fl, W, wasrow, remembershape) = cpre(f, 5)
         fres = cpost(fin, fl, wasrow, remembershape)
@@ -134,6 +134,7 @@ class TestCompSigReshape(unittest.TestCase):
         mess = mess.format(fl, W, wasrow)
         np.testing.assert_array_equal(f, fres, mess)
 
-if __name__ == '__main__':
+
+if __name__ == "__main__":
     suite = unittest.TestLoader().loadTestsFromTestCase(TestCompSigReshape)
     unittest.TextTestRunner(verbosity=2).run(suite)
diff --git a/ltfatpy/tests/datasets/read_ref_mat.py b/ltfatpy/tests/datasets/read_ref_mat.py
index 528f867..26db8f3 100644
--- a/ltfatpy/tests/datasets/read_ref_mat.py
+++ b/ltfatpy/tests/datasets/read_ref_mat.py
@@ -115,13 +115,13 @@ def _adapt_type(val):
     """
     res = val
     if isinstance(val, np.ndarray):
-        if np.issubdtype(val.dtype, np.unicode_):
+        if np.issubdtype(val.dtype, np.str_):
             # convert the unicode numpy arrays to standard unicode strings
             res = val.tolist()
             # convert boolean values
-            if val == u'_bool_True_':
+            if val == "_bool_True_":
                 res = True
-            elif val == u'_bool_False_':
+            elif val == "_bool_False_":
                 res = False
         elif val.size == 1:
             # convert the single value in the array to the corresponding
@@ -199,15 +199,18 @@ def read_ref_mat(filename, squeeze_arrays=True, adapt_types=True):
       having an integer value, it is converted to int.
 
     """
-    data = scipy.io.loadmat(filename, chars_as_strings=True)['data']
+    data = scipy.io.loadmat(filename, chars_as_strings=True)["data"]
     res = list()
     for item in data[0, :]:
         if item[0, 0].size > 0:
             # the tolist in the following is used to convert the unicode array
             # to standard unicode string
-            inputs = dict(((key[0].tolist(), val)
-                           for key, val in zip(item[0, 0][0, :],
-                                               item[0, 1][0, :])))
+            inputs = dict(
+                (
+                    (key[0].tolist(), val)
+                    for key, val in zip(item[0, 0][0, :], item[0, 1][0, :])
+                )
+            )
         else:
             inputs = dict()
 
-- 
GitLab