From 0bce795a1031c41020b800d257c8d9362d283da1 Mon Sep 17 00:00:00 2001 From: macbre Date: Thu, 10 Jun 2021 17:07:17 +0100 Subject: [PATCH 1/7] Use pytest-cov and simplify "make coverage" --- Makefile | 15 +++------------ setup.py | 1 + 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 163b47f..83ee07d 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,14 @@ -project_name = indexdigest -coverage_options = --include='$(project_name)/*' --omit='$(project_name)/test/*' - install: pip install -U -e .[dev] test: - pytest -x $(project_name) -o log_cli=true -o log_cli_level=warning + pytest -vv -o log_cli=true -o log_cli_level=warning coverage: - rm -f .coverage* - rm -rf htmlcov/* - coverage run -p -m pytest -x $(project_name) - coverage combine - coverage html -d htmlcov $(coverage_options) - coverage xml -i - coverage report $(coverage_options) + pytest -vv --cov=indexdigest --cov-report=term --cov-report=xml lint: - pylint $(project_name)/ --ignore=test + pylint indexdigest/ --ignore=test demo: docker run --network=host -t macbre/index-digest:latest mysql://index_digest:qwerty@127.0.0.1/index_digest --analyze-data --skip-checks=non_utf_columns --skip-tables=0028_no_time diff --git a/setup.py b/setup.py index 109b3e5..fba2d16 100644 --- a/setup.py +++ b/setup.py @@ -52,6 +52,7 @@ 'coverage==5.5', 'pylint==2.8.3', 'pytest==6.2.4', + 'pytest-cov==2.12.1', 'twine==3.4.1', ] }, From 189d8554b3cfe743dfb9315ed0c0ad0949817e35 Mon Sep 17 00:00:00 2001 From: macbre Date: Thu, 10 Jun 2021 17:10:20 +0100 Subject: [PATCH 2/7] Set the coverage threshold to 93% --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 83ee07d..6fb646d 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ test: pytest -vv -o log_cli=true -o log_cli_level=warning coverage: - pytest -vv --cov=indexdigest --cov-report=term --cov-report=xml + pytest -vv --cov=indexdigest --cov-report=term --cov-report=html --cov-fail-under=93 lint: pylint indexdigest/ --ignore=test From 6826f13f0e861f69554bdb3f689eaf35c8c602b3 Mon Sep 17 00:00:00 2001 From: macbre Date: Thu, 10 Jun 2021 17:16:13 +0100 Subject: [PATCH 3/7] coveralls: install Python package + add a badge --- Makefile | 2 +- README.md | 1 + setup.py | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6fb646d..b574f0b 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ test: pytest -vv -o log_cli=true -o log_cli_level=warning coverage: - pytest -vv --cov=indexdigest --cov-report=term --cov-report=html --cov-fail-under=93 + pytest -vv --cov=indexdigest --cov-report=term --cov-report=xml --cov-report=html --cov-fail-under=93 lint: pylint indexdigest/ --ignore=test diff --git a/README.md b/README.md index 1f05747..9590f7f 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![PyPI](https://img.shields.io/pypi/v/indexdigest.svg)](https://pypi.python.org/pypi/indexdigest) [![Docker Hub](https://img.shields.io/docker/pulls/macbre/index-digest.svg)](https://hub.docker.com/r/macbre/index-digest/) +[![Coverage Status](https://coveralls.io/repos/github/macbre/index-digest/badge.svg?branch=master)](https://coveralls.io/github/macbre/index-digest?branch=master) Analyses your database queries and schema and suggests indices improvements. You can use `index-digest` as **your database linter**. The goal is to **provide the user with actionable reports** instead of just a list of statistics and schema details. Inspired by [Percona's `pt-index-usage`](https://www.percona.com/doc/percona-toolkit/LATEST/pt-index-usage.html). diff --git a/setup.py b/setup.py index fba2d16..fe58a8c 100644 --- a/setup.py +++ b/setup.py @@ -50,6 +50,7 @@ extras_require={ 'dev': [ 'coverage==5.5', + 'coveralls==3.1.0', 'pylint==2.8.3', 'pytest==6.2.4', 'pytest-cov==2.12.1', From 97fac459bcd2456093cee494b183ab88226bdc90 Mon Sep 17 00:00:00 2001 From: macbre Date: Thu, 10 Jun 2021 17:19:34 +0100 Subject: [PATCH 4/7] Submit coverage report to coveralls --- .github/workflows/python.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 08dc49e..7f6645d 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -77,3 +77,11 @@ jobs: - name: Tests run: make test + + # https://coveralls-python.readthedocs.io/en/latest/usage/index.html + # upload coverage report for just one of Python version matrix runs + - name: Upload coverage report to Coveralls + if: matrix.python-version == '3.9' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: coveralls --service=github From b86f38b5b2177dc790e1f30c057499fa7d4f8c0e Mon Sep 17 00:00:00 2001 From: macbre Date: Thu, 10 Jun 2021 17:22:00 +0100 Subject: [PATCH 5/7] Fix GitHub workflows YAML files to match the schema --- .github/workflows/python.yml | 3 +-- .github/workflows/tests.yml | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 7f6645d..bd6db78 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -2,9 +2,8 @@ name: Test against different Python version on: push: - branches: master - pull_request: branches: [ master ] + pull_request: jobs: python_tests: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 75e4e9e..580d8f0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,7 +2,7 @@ name: Integration tests on: push: - branches: master + branches: [ master ] pull_request: jobs: From f36564ddb1e3e163072159994736765c96a728c6 Mon Sep 17 00:00:00 2001 From: macbre Date: Thu, 10 Jun 2021 17:23:13 +0100 Subject: [PATCH 6/7] .github/workflows/python.yml: unify matrix entry name --- .github/workflows/python.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index bd6db78..8688b63 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -16,7 +16,7 @@ jobs: matrix: # Python version(s) to use when running the tests # # https://github.com/actions/python-versions/blob/main/versions-manifest.json - python: + python-version: - "3.6" - "3.7" - "3.8" @@ -42,7 +42,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: ${{ matrix.python }} + python-version: ${{ matrix.python-version }} # https://github.com/actions/cache/blob/main/examples.md#using-pip-to-get-cache-location - name: Get pip cache dir From 6710ebb9f8d309f6b03b0d821f9d5604c03913b1 Mon Sep 17 00:00:00 2001 From: macbre Date: Thu, 10 Jun 2021 17:24:47 +0100 Subject: [PATCH 7/7] Run tests with code coverage --- .github/workflows/python.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 8688b63..84a8e58 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -74,8 +74,8 @@ jobs: "./sql/populate.sh" mysql --protocol=tcp --port=53306 -uindex_digest -pqwerty index_digest -v -e '\s; SHOW TABLES; SHOW DATABASES;' - - name: Tests - run: make test + - name: Tests with code coverage + run: make coverage # https://coveralls-python.readthedocs.io/en/latest/usage/index.html # upload coverage report for just one of Python version matrix runs