From de1406456f1604dd30919ad13eb1e5c3d8a5df06 Mon Sep 17 00:00:00 2001 From: Nick Moore Date: Wed, 8 Nov 2023 11:28:30 +1100 Subject: [PATCH] add some tests, activate coverage report (hopefully) --- .github/workflows/run-tests-push.yml | 9 +++++-- pyproject.toml | 1 + tests/utils/test_pandas.py | 39 ++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 tests/utils/test_pandas.py diff --git a/.github/workflows/run-tests-push.yml b/.github/workflows/run-tests-push.yml index 35e5b23..0c5cc71 100644 --- a/.github/workflows/run-tests-push.yml +++ b/.github/workflows/run-tests-push.yml @@ -17,7 +17,7 @@ jobs: # - run: xvfb-run pytest tests/ - run: tests/cmd_tests.sh - run-tests-ubuntu-22_04-python-3_10: + run-tests-ubuntu-22_04-python-3_10-with-coverage: runs-on: ubuntu-22.04 name: Ubuntu 22.04, Python 3.10 steps: @@ -28,8 +28,13 @@ jobs: - run: sudo apt install xvfb - run: pip install --upgrade pip - run: pip install .[dev] - - run: xvfb-run pytest tests/ + - run: xvfb-run coverage run --source countess -m pytest tests/ + - run: coverage html - run: tests/cmd_tests.sh + - uses: actions/upload-artifact@v3 + with: + name: test coverage report + path: htmlcov/index.html # run-tests-ubuntu-22_04-python-3_11_0rc2: # runs-on: ubuntu-22.04 diff --git a/pyproject.toml b/pyproject.toml index b4500e6..72fb42b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,7 @@ dependencies = [ dev = [ 'black<24', 'build==0.10.0', + 'coverage==7.3.2', 'mypy~=1.0.1', 'pylint~=2.17', 'types-psutil~=5.9.5', diff --git a/tests/utils/test_pandas.py b/tests/utils/test_pandas.py new file mode 100644 index 0000000..38f596d --- /dev/null +++ b/tests/utils/test_pandas.py @@ -0,0 +1,39 @@ +import pytest + +import pandas as pd + +from countess.utils.pandas import * + +df0 = pd.DataFrame([]) +df1 = pd.DataFrame([ {'a': n, 'b': n*100 } for n in range(0,100) ]).set_index('a') +df2 = pd.DataFrame([ {'a': n, 'b': n*100 } for n in range(100,1000) ]).set_index('a') +df3 = pd.DataFrame([ {'a': n, 'b': n*100 } for n in range(1000,10000) ]).set_index('a') +df4 = pd.DataFrame([ {'a': n, 'b': n*100 } for n in range(10000,10100) ]).set_index('a') +df5 = pd.DataFrame([ {'a': n, 'b': n*100 } for n in range(10100,10200) ]).set_index('a') +df6 = pd.DataFrame([ {'a': n, 'b': n*100 } for n in range(10200,10300) ]).set_index('a') + +def assert_iterable_of_dataframes_equal(a,b): + + assert pd.concat(a).sort_index().equals( + pd.concat(b).sort_index() + ) + +def test_collect_dataframes_0(): + + x = list(collect_dataframes([df0,df0,None,df0].__iter__())) + assert len(x) == 0 + +def test_collect_dataframes_1(): + x = list(collect_dataframes([df1,df4,df5].__iter__(), 300)) + assert_iterable_of_dataframes_equal([df1,df4,df5], x) + assert min(len(y) for y in x) > 100 + +def test_collect_dataframes_2(): + x = list(collect_dataframes([df1,df2,df4,df5].__iter__(), 300)) + assert_iterable_of_dataframes_equal([df1,df2,df4,df5], x) + assert min(len(y) for y in x) > 100 + +def test_collect_dataframes_3(): + x = list(collect_dataframes([df1,df2,df4,df5,df6].__iter__(), 300)) + assert_iterable_of_dataframes_equal([df1,df2,df4,df5,df6], x) + assert len(x) < 5