From ea4cc5b2bb55f85faf10323a525a70238aa6736e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jules=20Ch=C3=A9ron?= Date: Tue, 1 Mar 2022 23:39:02 +0100 Subject: [PATCH] Remove most pytest warnings --- pint/__init__.py | 12 --------- pint/testsuite/test_compat_downcast.py | 2 +- pint/testsuite/test_issues.py | 1 + pint/testsuite/test_numpy.py | 8 +++--- pint/testsuite/test_quantity.py | 36 +++++++++++++------------- 5 files changed, 24 insertions(+), 35 deletions(-) diff --git a/pint/__init__.py b/pint/__init__.py index 5ab92f07f..f39f7c852 100644 --- a/pint/__init__.py +++ b/pint/__init__.py @@ -111,18 +111,6 @@ def get_application_registry(): return application_registry -def test(): - """Run all tests. - - Returns - ------- - unittest.TestResult - """ - from .testsuite import run - - return run() - - # Enumerate all user-facing objects # Hint to intersphinx that, when building objects.inv, these objects must be registered # under the top-level module and not in their original submodules diff --git a/pint/testsuite/test_compat_downcast.py b/pint/testsuite/test_compat_downcast.py index 3fcf87110..be2f0583f 100644 --- a/pint/testsuite/test_compat_downcast.py +++ b/pint/testsuite/test_compat_downcast.py @@ -52,7 +52,7 @@ def array(request): elif request.param == "masked_array": # Create sample masked array as an upper triangular matrix. return np.ma.masked_array( - np.arange(25, dtype=np.float).reshape((5, 5)), + np.arange(25, dtype=float).reshape((5, 5)), mask=np.logical_not(np.triu(np.ones((5, 5)))), ) elif request.param == "dask_array": diff --git a/pint/testsuite/test_issues.py b/pint/testsuite/test_issues.py index 43fce0a1a..abca3f7a2 100644 --- a/pint/testsuite/test_issues.py +++ b/pint/testsuite/test_issues.py @@ -862,6 +862,7 @@ def test_issue_1300(self): if np is not None: + @pytest.mark.filterwarnings("ignore::pint.UnitStrippedWarning") @pytest.mark.parametrize( "callable", [ diff --git a/pint/testsuite/test_numpy.py b/pint/testsuite/test_numpy.py index 5e9915bff..069ba4edf 100644 --- a/pint/testsuite/test_numpy.py +++ b/pint/testsuite/test_numpy.py @@ -487,7 +487,7 @@ def test_addition_with_incompatible_scalar(self): op.add(b, a) def test_power(self): - arr = np.array(range(3), dtype=np.float) + arr = np.array(range(3), dtype=float) q = self.Q_(arr, "meter") for op_ in [op.pow, op.ipow, np.power]: @@ -523,7 +523,7 @@ def test_cbrt(self): @pytest.mark.xfail @helpers.requires_numpy def test_exponentiation_array_exp_2(self): - arr = np.array(range(3), dtype=np.float) + arr = np.array(range(3), dtype=float) # q = self.Q_(copy.copy(arr), None) q = self.Q_(copy.copy(arr), "meter") arr_cp = copy.copy(arr) @@ -990,8 +990,8 @@ def test_shape_numpy_func(self): assert np.shape(self.q) == (2, 2) @helpers.requires_array_function_protocol() - def test_alen_numpy_func(self): - assert np.alen(self.q) == 2 + def test_len_numpy_func(self): + assert len(self.q) == 2 @helpers.requires_array_function_protocol() def test_ndim_numpy_func(self): diff --git a/pint/testsuite/test_quantity.py b/pint/testsuite/test_quantity.py index c29fd19f5..bc9fbee49 100644 --- a/pint/testsuite/test_quantity.py +++ b/pint/testsuite/test_quantity.py @@ -1221,8 +1221,8 @@ def test_inplace_addition(self, input_tuple, expected): (q1v, q1u), (q2v, q2u) = input_tuple # update input tuple with new values to have correct values on failure input_tuple = ( - (np.array([q1v] * 2, dtype=np.float), q1u), - (np.array([q2v] * 2, dtype=np.float), q2u), + (np.array([q1v] * 2, dtype=float), q1u), + (np.array([q2v] * 2, dtype=float), q2u), ) Q_ = self.Q_ qin1, qin2 = input_tuple @@ -1232,7 +1232,7 @@ def test_inplace_addition(self, input_tuple, expected): with pytest.raises(OffsetUnitCalculusError): op.iadd(q1_cp, q2) else: - expected = np.array([expected[0]] * 2, dtype=np.float), expected[1] + expected = np.array([expected[0]] * 2, dtype=float), expected[1] assert op.iadd(q1_cp, q2).units == Q_(*expected).units q1_cp = copy.copy(q1) helpers.assert_quantity_almost_equal( @@ -1300,8 +1300,8 @@ def test_inplace_subtraction(self, input_tuple, expected): (q1v, q1u), (q2v, q2u) = input_tuple # update input tuple with new values to have correct values on failure input_tuple = ( - (np.array([q1v] * 2, dtype=np.float), q1u), - (np.array([q2v] * 2, dtype=np.float), q2u), + (np.array([q1v] * 2, dtype=float), q1u), + (np.array([q2v] * 2, dtype=float), q2u), ) Q_ = self.Q_ qin1, qin2 = input_tuple @@ -1311,7 +1311,7 @@ def test_inplace_subtraction(self, input_tuple, expected): with pytest.raises(OffsetUnitCalculusError): op.isub(q1_cp, q2) else: - expected = np.array([expected[0]] * 2, dtype=np.float), expected[1] + expected = np.array([expected[0]] * 2, dtype=float), expected[1] assert op.isub(q1_cp, q2).units == Q_(*expected).units q1_cp = copy.copy(q1) helpers.assert_quantity_almost_equal( @@ -1378,8 +1378,8 @@ def test_inplace_multiplication(self, input_tuple, expected): (q1v, q1u), (q2v, q2u) = input_tuple # update input tuple with new values to have correct values on failure input_tuple = ( - (np.array([q1v] * 2, dtype=np.float), q1u), - (np.array([q2v] * 2, dtype=np.float), q2u), + (np.array([q1v] * 2, dtype=float), q1u), + (np.array([q2v] * 2, dtype=float), q2u), ) Q_ = self.Q_ qin1, qin2 = input_tuple @@ -1389,7 +1389,7 @@ def test_inplace_multiplication(self, input_tuple, expected): with pytest.raises(OffsetUnitCalculusError): op.imul(q1_cp, q2) else: - expected = np.array([expected[0]] * 2, dtype=np.float), expected[1] + expected = np.array([expected[0]] * 2, dtype=float), expected[1] assert op.imul(q1_cp, q2).units == Q_(*expected).units q1_cp = copy.copy(q1) helpers.assert_quantity_almost_equal( @@ -1458,8 +1458,8 @@ def test_inplace_truedivision(self, input_tuple, expected): (q1v, q1u), (q2v, q2u) = input_tuple # update input tuple with new values to have correct values on failure input_tuple = ( - (np.array([q1v] * 2, dtype=np.float), q1u), - (np.array([q2v] * 2, dtype=np.float), q2u), + (np.array([q1v] * 2, dtype=float), q1u), + (np.array([q2v] * 2, dtype=float), q2u), ) Q_ = self.Q_ qin1, qin2 = input_tuple @@ -1469,7 +1469,7 @@ def test_inplace_truedivision(self, input_tuple, expected): with pytest.raises(OffsetUnitCalculusError): op.itruediv(q1_cp, q2) else: - expected = np.array([expected[0]] * 2, dtype=np.float), expected[1] + expected = np.array([expected[0]] * 2, dtype=float), expected[1] assert op.itruediv(q1_cp, q2).units == Q_(*expected).units q1_cp = copy.copy(q1) helpers.assert_quantity_almost_equal( @@ -1524,8 +1524,8 @@ def test_inplace_multiplication_with_autoconvert(self, input_tuple, expected): (q1v, q1u), (q2v, q2u) = input_tuple # update input tuple with new values to have correct values on failure input_tuple = ( - (np.array([q1v] * 2, dtype=np.float), q1u), - (np.array([q2v] * 2, dtype=np.float), q2u), + (np.array([q1v] * 2, dtype=float), q1u), + (np.array([q2v] * 2, dtype=float), q2u), ) Q_ = self.Q_ qin1, qin2 = input_tuple @@ -1535,7 +1535,7 @@ def test_inplace_multiplication_with_autoconvert(self, input_tuple, expected): with pytest.raises(OffsetUnitCalculusError): op.imul(q1_cp, q2) else: - expected = np.array([expected[0]] * 2, dtype=np.float), expected[1] + expected = np.array([expected[0]] * 2, dtype=float), expected[1] assert op.imul(q1_cp, q2).units == Q_(*expected).units q1_cp = copy.copy(q1) helpers.assert_quantity_almost_equal( @@ -1664,7 +1664,7 @@ def test_inplace_exponentiation(self, input_tuple, expected): in1, in2 = input_tuple if type(in1) is tuple and type(in2) is tuple: (q1v, q1u), (q2v, q2u) = in1, in2 - in1 = self.Q_(*(np.array([q1v] * 2, dtype=np.float), q1u)) + in1 = self.Q_(*(np.array([q1v] * 2, dtype=float), q1u)) in2 = self.Q_(q2v, q2u) elif not type(in1) is tuple and type(in2) is tuple: in2 = self.Q_(*in2) @@ -1683,12 +1683,12 @@ def test_inplace_exponentiation(self, input_tuple, expected): else: if type(expected_copy[i]) is tuple: expected = self.Q_( - np.array([expected_copy[i][0]] * 2, dtype=np.float), + np.array([expected_copy[i][0]] * 2, dtype=float), expected_copy[i][1], ) assert op.ipow(in1_cp, in2).units == expected.units else: - expected = np.array([expected_copy[i]] * 2, dtype=np.float) + expected = np.array([expected_copy[i]] * 2, dtype=float) in1_cp = copy.copy(in1) helpers.assert_quantity_almost_equal(op.ipow(in1_cp, in2), expected)