From d31c59329b4c18acc44213d9e9c7500aecb0783f Mon Sep 17 00:00:00 2001 From: John Hennig Date: Thu, 20 May 2021 16:22:09 +0200 Subject: [PATCH] Added reporting of code coverage by test suite. Code coverage by the test suite is measured via pyTest and its pyTest-cov plug-in. The script `coverage.py` runs the coverage test, renders the coverage report, and also creates the coverage badge, unless that file already exists in the `tests` folder. --- .coverage | Bin 0 -> 53248 bytes .gitignore | 2 ++ ReadMe.md | 16 ++++++++-------- deploy/build.py | 7 +------ deploy/clean.py | 8 ++++---- deploy/coverage.py | 24 ++++++++++++++++++++++++ deploy/notes.txt | 14 -------------- deploy/publish.py | 3 +-- deploy/release.md | 11 +++++++++++ deploy/render.py | 10 ++++++++++ pyproject.toml | 4 ++-- tests/coverage.svg | 21 +++++++++++++++++++++ tests/test_1d.py | 22 +++++++++++++++++++--- tests/test_2d.py | 44 +++++++++++++++++++++++++++++++++++++++++--- tox.ini | 13 +++++++++++++ 15 files changed, 157 insertions(+), 42 deletions(-) create mode 100644 .coverage create mode 100644 deploy/coverage.py delete mode 100644 deploy/notes.txt create mode 100644 deploy/release.md create mode 100644 deploy/render.py create mode 100644 tests/coverage.svg diff --git a/.coverage b/.coverage new file mode 100644 index 0000000000000000000000000000000000000000..49d7f523cae2f571013646e78e0ada8cedd8cc20 GIT binary patch literal 53248 zcmeI)&2QW09S3ky4@FtFoF`poXsH+EIjm6JSdNvK4)HK7S>r>|0$tl+7%*)rB|Vba zN~A(kNqi_Wx5KjIh5|(g?B%jyr(OCNwC5EokkhbBu^!d|+YWodF71~6eh*2@N^B!8 z+BGS@ghlb?c^*E`=Xs$>$$ajar~E{#UKkC%M4hn?TefXoP|C8bGQH;Ml}{yFaPk#; zw|6Y>wOF=Ro_=Xwe$%SBuUYcD^WT#7%CF{6&HbTrwfySbuS+kK2ebnd1Rwwb2tdFH zY&}ycRgWIEUw$d^+5??LUPnjieE#ug*DqdPSC=n-{i$`8Zc`^_6;1WJx~QV?ni}ay z_56WWe$e$hUg8IRm2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##AOHafKmY;|fB*y_@UaRA`mw+~fB$dG4=wt`1OW&@00Izz00bZa z0SG_<0uX?}XHY?;F^zYu<`Q^X53_O$hT=C^&Q%z + + + + + + + + + + + + + + + coverage + coverage + 100% + 100% + + diff --git a/tests/test_1d.py b/tests/test_1d.py index dd256a5..3a2a17b 100644 --- a/tests/test_1d.py +++ b/tests/test_1d.py @@ -27,7 +27,7 @@ def setup_module(): # Tests # ######################################## -def test_density(): +def test_reference(): x = reference['x'] N = reference['N'] assert N == len(x) @@ -40,11 +40,27 @@ def test_density(): assert isclose(bandwidth, reference['bandwidth']).all() +def test_arguments(): + (density, grid, bandwidth) = kde1d([-2, -1, 0, +1, +2]*20, 4) + assert len(grid) == 4 + assert isclose(grid.min(), -2.4) + assert isclose(grid.max(), +1.2) + (density, grid, bandwidth) = kde1d([-2, -1, 0, +1, +2]*20, 4, 2) + assert isclose(grid.min(), -2) + assert isclose(grid.max(), +1) + try: + kde1d([-2, -1, 0, +1, +2]*10, 4) + raised_error = False + except ValueError: + raised_error = True + assert raised_error + + ######################################## # Main # ######################################## if __name__ == '__main__': - # Runs if test script is executed directly, and not via pytest. setup_module() - test_density() + test_reference() + test_arguments() diff --git a/tests/test_2d.py b/tests/test_2d.py index 57c2021..709a0d7 100644 --- a/tests/test_2d.py +++ b/tests/test_2d.py @@ -27,7 +27,7 @@ def setup_module(): # Test # ######################################## -def test_density(): +def test_reference(): x = reference['x'] y = reference['y'] N = reference['N'] @@ -47,11 +47,49 @@ def test_density(): assert isclose(bandwidth, reference['bandwidth']).all() +def test_arguments(): + samples = [-2, -1, 0, +1, +2] + (density, grid, bandwith) = kde2d(samples*5, samples*5, 16) + assert len(grid[0]) == 16 + assert len(grid[1]) == 16 + assert isclose(grid[0].min(), -3.0) + assert isclose(grid[0].max(), +2.625) + assert isclose(grid[1].min(), -3.0) + assert isclose(grid[1].max(), +2.625) + (density, grid, bandwidth) = kde2d(samples*5, samples*5, 16, (2, None)) + assert isclose(grid[0].min(), -2) + assert isclose(grid[0].max(), +1.75) + assert isclose(grid[1].min(), -3) + assert isclose(grid[1].max(), +2.625) + (density, grid, bandwidth) = kde2d(samples*5, samples*5, 16, (None, 2)) + assert isclose(grid[0].min(), -3) + assert isclose(grid[0].max(), +2.625) + assert isclose(grid[1].min(), -2) + assert isclose(grid[1].max(), +1.75) + (density, grid, bandwidth) = kde2d(samples*5, samples*5, 16, 2) + assert isclose(grid[0].min(), -2) + assert isclose(grid[0].max(), +1.75) + assert isclose(grid[1].min(), -2) + assert isclose(grid[1].max(), +1.75) + try: + kde2d(samples, samples*2, 16) + raised_error = False + except ValueError: + raised_error = True + assert raised_error + try: + kde2d(samples, samples, 16) + raised_error = False + except ValueError: + raised_error = True + assert raised_error + + ######################################## # Main # ######################################## if __name__ == '__main__': - # Runs if test script is executed directly, and not via pytest. setup_module() - test_density() + test_reference() + test_arguments() diff --git a/tox.ini b/tox.ini index f2b92c3..f27c2c9 100644 --- a/tox.ini +++ b/tox.ini @@ -18,3 +18,16 @@ ignore = E741 per-file-ignores = kde_diffusion/__init__.py:F401 + + +[pytest] +addopts = --verbose +testpaths = + tests +filterwarnings = + ignore::UserWarning + + +[coverage:run] +source = kde_diffusion/ +data_file = deploy/coverage.sqlite