From 3324b0aa07046463a65a607f3bba69f08878dde3 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Tue, 7 Dec 2021 08:37:33 +0000 Subject: [PATCH 1/5] docs: CONTRIBUTING extended --- CONTRIBUTING.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cc4b5132..df206c99 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,14 +20,15 @@ Please add docstrings to any new function, class or method you implement. The do ### Tests When implementing a new feature or fixing a bug please add meaningful tests to the files in the `tests` directory which cover the new code. - -### Continous integration For all pull requests tests are executed for the most recent python releases via ``` pytest --cov=pyerrors -vv ``` -requiring `pytest`, `pytest-cov` and `pytest-benchmark` -and the linter `flake8` is executed with the command +requiring `pytest`, `pytest-cov` and `pytest-benchmark`. To get a coverage report in html run +``` +pytest --cov=pyerrors --cov-report html +``` +The linter `flake8` is executed with the command ``` flake8 --ignore=E501,E722 --exclude=__init__.py pyerrors ``` From ec4bb393990199f75e950a03624097c1198c9631 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Tue, 7 Dec 2021 17:11:50 +0000 Subject: [PATCH 2/5] test: test for dirac gamma added --- tests/dirac_test.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/dirac_test.py b/tests/dirac_test.py index 28222da6..719490f4 100644 --- a/tests/dirac_test.py +++ b/tests/dirac_test.py @@ -10,3 +10,23 @@ def test_gamma_matrices(): assert np.allclose(matrix @ matrix, np.identity(4)) assert np.allclose(matrix, matrix.T.conj()) assert np.allclose(pe.dirac.gamma5, pe.dirac.gamma[0] @ pe.dirac.gamma[1] @ pe.dirac.gamma[2] @ pe.dirac.gamma[3]) + + +def test_grid_dirac(): + for gamma in ['Identity', + 'Gamma5', + 'GammaX', + 'GammaY', + 'GammaZ', + 'GammaT', + 'GammaXGamma5', + 'GammaYGamma5', + 'GammaZGamma5', + 'GammaTGamma5', + 'SigmaXT', + 'SigmaXY', + 'SigmaXZ', + 'SigmaYT', + 'SigmaYZ', + 'SigmaZT']: + pe.dirac.Grid_gamma(gamma) From fa7702a4adac901520b3500026293cff89114ca7 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Tue, 7 Dec 2021 17:14:21 +0000 Subject: [PATCH 3/5] test: dirac test extended to last missing line --- tests/dirac_test.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/dirac_test.py b/tests/dirac_test.py index 719490f4..0a2c0379 100644 --- a/tests/dirac_test.py +++ b/tests/dirac_test.py @@ -30,3 +30,5 @@ def test_grid_dirac(): 'SigmaYZ', 'SigmaZT']: pe.dirac.Grid_gamma(gamma) + with pytest.raises(Exception): + pe.dirac.Grid_gamma('Not a gamma matrix') From a7363fb88e9d9569880345a998184bbee086a8a0 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Tue, 7 Dec 2021 17:31:40 +0000 Subject: [PATCH 4/5] test: tests for exceptional cases extended --- tests/covobs_test.py | 3 +++ tests/obs_test.py | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/tests/covobs_test.py b/tests/covobs_test.py index c098bd73..bfb21dbf 100644 --- a/tests/covobs_test.py +++ b/tests/covobs_test.py @@ -62,6 +62,9 @@ def test_covobs_name_collision(): my_obs = pe.pseudo_Obs(2.3, 0.2, 'test') with pytest.raises(Exception): summed_obs = my_obs + covobs + covobs2 = pe.cov_Obs(0.3, 0.001, 'test') + with pytest.raises(Exception): + summed_obs = covobs + covobs2 def test_covobs_replica_separator(): diff --git a/tests/obs_test.py b/tests/obs_test.py index ce9d7f41..f5d04832 100644 --- a/tests/obs_test.py +++ b/tests/obs_test.py @@ -9,6 +9,43 @@ import pytest np.random.seed(0) +def test_Obs_exceptions(): + with pytest.raises(Exception): + pe.Obs([np.random.rand(10)], ['1', '2']) + with pytest.raises(Exception): + pe.Obs([np.random.rand(10)], ['1'], idl=[]) + with pytest.raises(Exception): + pe.Obs([np.random.rand(10), np.random.rand(10)], ['1', '1']) + with pytest.raises(Exception): + pe.Obs([np.random.rand(10), np.random.rand(10)], ['1', 1]) + with pytest.raises(Exception): + pe.Obs([np.random.rand(10)], [1]) + with pytest.raises(Exception): + pe.Obs([np.random.rand(4)], ['name']) + + my_obs = pe.Obs([np.random.rand(6)], ['name']) + my_obs._value = 0.0 + my_obs.details() + with pytest.raises(Exception): + my_obs.plot_tauint() + with pytest.raises(Exception): + my_obs.plot_rho() + with pytest.raises(Exception): + my_obs.plot_rep_dist() + with pytest.raises(Exception): + my_obs.plot_piechart() + with pytest.raises(Exception): + my_obs.gamma_method(S='2.3') + with pytest.raises(Exception): + my_obs.gamma_method(tau_exp=2.3) + my_obs.gamma_method() + my_obs.details() + + my_obs += pe.Obs([np.random.rand(6)], ['name2|r1']) + my_obs += pe.Obs([np.random.rand(6)], ['name2|r2']) + my_obs.gamma_method() + my_obs.details() + def test_dump(): value = np.random.normal(5, 10) dvalue = np.abs(np.random.normal(0, 1)) @@ -311,6 +348,7 @@ def test_overloaded_functions(): def test_utils(): my_obs = pe.pseudo_Obs(1.0, 0.5, 't|r01') my_obs += pe.pseudo_Obs(1.0, 0.5, 't|r02') + str(my_obs) for tau_exp in [0, 5]: my_obs.gamma_method(tau_exp=tau_exp) my_obs.tag = "Test description" @@ -325,6 +363,8 @@ def test_utils(): my_obs.plot_piechart() assert my_obs > (my_obs - 1) assert my_obs < (my_obs + 1) + float(my_obs) + str(my_obs) def test_cobs(): From 968cdf31812835a832edd4fed248d0cb187b76fa Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Tue, 7 Dec 2021 17:34:02 +0000 Subject: [PATCH 5/5] fix: deprecated get_fmin call removed in fits --- pyerrors/fits.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyerrors/fits.py b/pyerrors/fits.py index 1651cd93..a08dfa64 100644 --- a/pyerrors/fits.py +++ b/pyerrors/fits.py @@ -402,7 +402,7 @@ def _prior_fit(x, y, func, priors, silent=False, **kwargs): if not silent: print('chisquare/d.o.f.:', output.chisquare_by_dof) - if not m.get_fmin().is_valid: + if not m.fmin.is_valid: raise Exception('The minimization procedure did not converge.') hess_inv = np.linalg.pinv(jacobian(jacobian(chisqfunc))(params))