From 25479a1dfd73e4b34493688b4460149a3786707f Mon Sep 17 00:00:00 2001 From: Alan Chen Date: Sat, 9 Apr 2022 15:36:37 -0400 Subject: [PATCH] fix pylint line-too-long errors in tests (#697) * fix pylint line-too-long errors in tests * fix linebreak in error message issues and tox line * fix failed checks on problinsolve.py * fix small CI/CD with black and isort --- .../test_approx_strategies/test_ek.py | 3 +- .../test_utils/test_problem_utils.py | 4 +-- tests/test_linalg/test_problinsolve.py | 35 ++++++++++++++----- .../test_matrix_based_linear_belief_update.py | 8 +++-- ...etric_matrix_based_linear_belief_update.py | 8 +++-- tests/test_linops/test_arithmetics.py | 3 +- .../test_linops/test_arithmetics_fallbacks.py | 5 ++- tests/test_randvars/test_normal.py | 10 ++++-- tests/testing/statistics.py | 12 ++++--- tox.ini | 2 +- 10 files changed, 62 insertions(+), 28 deletions(-) diff --git a/tests/test_diffeq/test_odefilter/test_approx_strategies/test_ek.py b/tests/test_diffeq/test_odefilter/test_approx_strategies/test_ek.py index be4186ac9..1d1c3bb39 100644 --- a/tests/test_diffeq/test_odefilter/test_approx_strategies/test_ek.py +++ b/tests/test_diffeq/test_odefilter/test_approx_strategies/test_ek.py @@ -45,7 +45,8 @@ def _setup(self): def test_call(self, fitzhughnagumo): - # not-yet-registered ODE raises errors as soon as the approximate info operator is called. + # not-yet-registered ODE raises errors as soon as the approximate + # info operator is called. with pytest.raises(ValueError): approx_transition = self.approx_strategy(self.info_op).as_transition() approx_transition.forward_realization( diff --git a/tests/test_diffeq/test_odefilter/test_utils/test_problem_utils.py b/tests/test_diffeq/test_odefilter/test_utils/test_problem_utils.py index aa3db2197..317f1e22c 100644 --- a/tests/test_diffeq/test_odefilter/test_utils/test_problem_utils.py +++ b/tests/test_diffeq/test_odefilter/test_utils/test_problem_utils.py @@ -92,8 +92,8 @@ def test_ivp_to_regression_problem( # If an approximation strategy is passed, the output should be an EKF component # which should suppoert forward_rv(). - # If not, the output is a generic NonlinearGaussian (which has been tested for above. - # Recall that DiscreteEKFComponent implements NonlinearGaussian.) + # If not, the output is a generic NonlinearGaussian(which has been + # tested for above. Recall that DiscreteEKFComponent implements NonlinearGaussian.) if approx_strategy is not None: assert isinstance( regprob.measurement_models[1], diff --git a/tests/test_linalg/test_problinsolve.py b/tests/test_linalg/test_problinsolve.py index 99d60ec3f..7f95d9292 100644 --- a/tests/test_linalg/test_problinsolve.py +++ b/tests/test_linalg/test_problinsolve.py @@ -108,7 +108,10 @@ def test_randvar_output(self): self.assertIsInstance( rv, randvars.RandomVariable, - msg="Output of probabilistic linear solver is not a random variable.", + msg=( + "Output of probabilistic linear solver " + "is not a random variable." + ), ) def test_symmetric_posterior_params(self): @@ -209,11 +212,15 @@ def test_residual_matches_error(self): self.assertAlmostEqual( info["resid_l2norm"], np.linalg.norm(A @ x_est.mean - b), - msg="Residual in output info does not match l2-error of solution estimate.", + msg=( + "Residual in output info does not match " + "l2-error of solution estimate." + ), ) # def test_solution_equivalence(self): - # """The iteratively computed solution should match the induced solution estimate: x_k = E[A^-1] b""" + # """The iteratively computed solution should match the induced + # solution estimate: x_k = E[A^-1] b""" # A, f = self.poisson_linear_system # # for matblinsolve in self.matblinsolvers: @@ -222,9 +229,13 @@ def test_residual_matches_error(self): # u_solver, Ahat, Ainvhat, info = matblinsolve(A=A, b=f) # # # E[x] = E[A^-1] b - # self.assertAllClose(u_solver.mean, (Ainvhat @ f[:, None]).mean.ravel(), rtol=1e-5, - # msg="Solution from matrix-based probabilistic linear solver does not match the " + - # "estimated inverse, i.e. x =/= Ainv @ b ") + # self.assertAllClose(u_solver.mean, + # (Ainvhat @ f[:, None]).mean.ravel(), + # rtol=1e-5, + # msg=( + # "Solution from matrix-based probabilistic linear solver " + # does not match the estimated inverse, i.e. x =/= Ainv @ b " + # )) def test_posterior_uncertainty_zero_in_explored_space(self): """Test whether the posterior uncertainty over the matrices A and Ainv is zero @@ -316,11 +327,14 @@ def test_matrixprior(self): x_true, rtol=1e-6, atol=1e-6, - msg="Solution for matrixvariate prior does not match true solution.", + msg=( + "Solution for matrixvariate prior does not match true solution." + ), ) def test_searchdir_conjugacy(self): - """Search directions should remain A-conjugate up to machine precision, i.e. s_i^T A s_j = 0 for i != j.""" + """Search directions should remain A-conjugate up to machine precision, + i.e. s_i^T A s_j = 0 for i != j.""" searchdirs = [] # Define callback function to obtain search directions @@ -424,7 +438,10 @@ def test_iterative_covariance_trace_update(self): self.assertAlmostEqual( info["trace_sol_cov"], x_est.cov.trace(), - msg="Iteratively computed trace not equal to trace of solution covariance.", + msg=( + "Iteratively computed trace not equal to " + "trace of solution covariance." + ), ) def test_uncertainty_calibration_error(self): diff --git a/tests/test_linalg/test_solvers/test_belief_updates/test_matrix_based/test_matrix_based_linear_belief_update.py b/tests/test_linalg/test_solvers/test_belief_updates/test_matrix_based/test_matrix_based_linear_belief_update.py index ca1a6661d..28c2bec01 100644 --- a/tests/test_linalg/test_solvers/test_belief_updates/test_matrix_based/test_matrix_based_linear_belief_update.py +++ b/tests/test_linalg/test_solvers/test_belief_updates/test_matrix_based/test_matrix_based_linear_belief_update.py @@ -93,7 +93,9 @@ def dense_matrix_based_update( np.testing.assert_allclose( updated_belief.A.cov.todense(), A_naive.cov.todense(), - err_msg="Covariance of system matrix estimate does not match naive implementation.", + err_msg=( + "Covariance of system matrix estimate does not match naive implementation." + ), ) # Inverse @@ -105,5 +107,7 @@ def dense_matrix_based_update( np.testing.assert_allclose( updated_belief.Ainv.cov.todense(), Ainv_naive.cov.todense(), - err_msg="Covariance of matrix inverse estimate does not match naive implementation.", + err_msg=( + "Covariance of matrix inverse estimate does not match naive implementation." + ), ) diff --git a/tests/test_linalg/test_solvers/test_belief_updates/test_matrix_based/test_symmetric_matrix_based_linear_belief_update.py b/tests/test_linalg/test_solvers/test_belief_updates/test_matrix_based/test_symmetric_matrix_based_linear_belief_update.py index 1c2c20510..de45f883d 100644 --- a/tests/test_linalg/test_solvers/test_belief_updates/test_matrix_based/test_symmetric_matrix_based_linear_belief_update.py +++ b/tests/test_linalg/test_solvers/test_belief_updates/test_matrix_based/test_symmetric_matrix_based_linear_belief_update.py @@ -99,7 +99,9 @@ def dense_matrix_based_update( np.testing.assert_allclose( updated_belief.A.cov.todense(), A_naive.cov.todense(), - err_msg="Covariance of system matrix estimate does not match naive implementation.", + err_msg=( + "Covariance of system matrix estimate does not match naive implementation." + ), ) # Inverse @@ -111,5 +113,7 @@ def dense_matrix_based_update( np.testing.assert_allclose( updated_belief.Ainv.cov.todense(), Ainv_naive.cov.todense(), - err_msg="Covariance of matrix inverse estimate does not match naive implementation.", + err_msg=( + "Covariance of matrix inverse estimate does not match naive implementation." + ), ) diff --git a/tests/test_linops/test_arithmetics.py b/tests/test_linops/test_arithmetics.py index 907583c04..8b3b1313d 100644 --- a/tests/test_linops/test_arithmetics.py +++ b/tests/test_linops/test_arithmetics.py @@ -238,7 +238,8 @@ def test_idkronecker_matmul(): k1 = IdentityKronecker(4, np.random.rand(2, 3)) # (8, 12) k2 = IdentityKronecker(2, np.random.rand(6, 2)) # (12, 4) - # Even though the shapes fit, and IdentityKronecker @ IdentityKronecker = IdentityKronecker .... + # Even though the shapes fit, and + # IdentityKronecker @ IdentityKronecker = IdentityKronecker .... assert k1.shape[1] == k2.shape[0] # The result does not have a IdentityKronecker structure diff --git a/tests/test_linops/test_arithmetics_fallbacks.py b/tests/test_linops/test_arithmetics_fallbacks.py index f2d9138ab..d74fba490 100644 --- a/tests/test_linops/test_arithmetics_fallbacks.py +++ b/tests/test_linops/test_arithmetics_fallbacks.py @@ -3,9 +3,8 @@ import numpy as np import pytest -from probnum.linops._arithmetic_fallbacks import ( # NegatedLinearOperator,; ProductLinearOperator,; SumLinearOperator, - ScaledLinearOperator, -) +# NegatedLinearOperator,; ProductLinearOperator,; SumLinearOperator,; +from probnum.linops._arithmetic_fallbacks import ScaledLinearOperator from probnum.linops._linear_operator import Matrix from probnum.problems.zoo.linalg import random_spd_matrix diff --git a/tests/test_randvars/test_normal.py b/tests/test_randvars/test_normal.py index e8467a5fb..173fe5f88 100644 --- a/tests/test_randvars/test_normal.py +++ b/tests/test_randvars/test_normal.py @@ -138,7 +138,10 @@ def test_normal_dimension_mismatch(self): (np.array([[-1, 0], [2, 1]]), np.eye(3)), ]: with self.subTest(): - err_msg = "Mean and kernels mismatch in normal distribution did not raise a ValueError." + err_msg = ( + "Mean and kernels mismatch in normal distribution " + "did not raise a ValueError." + ) with self.assertRaises(ValueError, msg=err_msg): assert randvars.Normal(mean=mean, cov=cov) @@ -204,8 +207,9 @@ def test_symmetric_samples(self): B.T, atol=1e-5, rtol=1e-5, - msg="Sample {} from symmetric Kronecker distribution is not symmetric.".format( - i + msg=( + f"Sample {i} from symmetric Kronecker " + "distribution is not symmetric." ), ) diff --git a/tests/testing/statistics.py b/tests/testing/statistics.py index 1d6ff1766..4907224d4 100644 --- a/tests/testing/statistics.py +++ b/tests/testing/statistics.py @@ -14,18 +14,22 @@ def chi_squared_statistic(realisations, means, covs): with (assumed) means :math:`m_1, ..., m_N` and covariances :math:`C_1, ..., C_N`, compute the value - .. math:`\\chi^2 = \\frac{1}{Nd} \\sum_{n=1}^N (x_n - m_n)^\\top C_n^{-1}(x_n - m_n).` + .. math:`\\chi^2 + = \\frac{1}{Nd} \\sum_{n=1}^N (x_n - m_n)^\\top C_n^{-1}(x_n - m_n).` - If it is roughly equal to 1, the samples are likely to correspond to given mean and covariance. + If it is roughly equal to 1, the samples are likely to correspond to given + mean and covariance. Parameters ---------- realisations : array_like :math:`N` realisations of a :math:`d`-dimensional random variable. Shape (N, d). means : array_like - :math:`N`, :math:`d`-dimensional (assumed) means of a random variable. Shape (N, d). + :math:`N`, :math:`d`-dimensional (assumed) means of a random variable. + Shape (N, d). realisations : array_like - :math:`N`, :math:`d \\times d`-dimensional (assumed) covariances of a random variable. Shape (N, d, d). + :math:`N`, :math:`d \\times d`-dimensional (assumed) covariances of a random + variable. Shape (N, d, d). """ if not realisations.shape == means.shape == covs.shape[:-1]: print(realisations.shape, means.shape, covs.shape) diff --git a/tox.ini b/tox.ini index b0762e5a2..201abac0e 100644 --- a/tox.ini +++ b/tox.ini @@ -80,4 +80,4 @@ commands = # pylint benchmarks --disable="unused-argument,attribute-defined-outside-init,missing-function-docstring" --jobs=0 # not a work in progress, but final pylint benchmarks --disable="unused-argument,attribute-defined-outside-init,no-else-return,no-self-use,consider-using-from-import,missing-module-docstring,missing-class-docstring,missing-function-docstring" --jobs=0 # pylint tests --disable="missing-function-docstring" --jobs=0 # not a work in progress, but final - pylint tests --disable="arguments-differ,redefined-outer-name,too-many-instance-attributes,too-many-arguments,too-many-locals,too-few-public-methods,protected-access,unnecessary-pass,unused-variable,unused-argument,unused-private-member,attribute-defined-outside-init,no-else-return,no-self-use,consider-using-from-import,duplicate-code,line-too-long,missing-module-docstring,missing-class-docstring,missing-function-docstring,missing-param-doc,missing-type-doc,missing-raises-doc,missing-return-type-doc,redundant-returns-doc" --jobs=0 + pylint tests --disable="arguments-differ,redefined-outer-name,too-many-instance-attributes,too-many-arguments,too-many-locals,too-few-public-methods,protected-access,unnecessary-pass,unused-variable,unused-argument,unused-private-member,attribute-defined-outside-init,no-else-return,no-self-use,consider-using-from-import,duplicate-code,missing-module-docstring,missing-class-docstring,missing-function-docstring,missing-param-doc,missing-type-doc,missing-raises-doc,missing-return-type-doc,redundant-returns-doc" --jobs=0