From f13205ca3e7a13d2594006a8404d7c4c7175848d Mon Sep 17 00:00:00 2001 From: Malcolm Smith Date: Wed, 9 Nov 2022 17:01:57 +0000 Subject: [PATCH 1/8] Clarify split between coverage configurations in root and subdirectories --- android/pyproject.toml | 20 ++----------- cocoa/pyproject.toml | 20 ++----------- core/pyproject.toml | 20 ++----------- gtk/pyproject.toml | 20 ++----------- iOS/pyproject.toml | 20 ++----------- pyproject.toml | 62 ++++++++++++++++++++--------------------- web/pyproject.toml | 20 ++----------- winforms/pyproject.toml | 20 ++----------- 8 files changed, 52 insertions(+), 150 deletions(-) diff --git a/android/pyproject.toml b/android/pyproject.toml index b2b3b63080..4d45102abf 100644 --- a/android/pyproject.toml +++ b/android/pyproject.toml @@ -6,21 +6,7 @@ build-backend = "setuptools.build_meta" parallel = true branch = true relative_files = true -source_pkgs = ["toga_android"] - -[tool.coverage.paths] -source = [ - "src", - "**/site-packages" -] -[tool.coverage.report] -show_missing = true -skip_covered = true -skip_empty = true -precision = 1 -exclude_lines = [ - "pragma: no cover", - "@(abc\\.)?abstractmethod", - "NotImplementedError\\(\\)" -] +# See notes in the root pyproject.toml file. +source = ["src"] +source_pkgs = ["toga_android"] diff --git a/cocoa/pyproject.toml b/cocoa/pyproject.toml index 3e68bbbf75..67d6d91367 100644 --- a/cocoa/pyproject.toml +++ b/cocoa/pyproject.toml @@ -6,21 +6,7 @@ build-backend = "setuptools.build_meta" parallel = true branch = true relative_files = true -source_pkgs = ["toga_cocoa"] - -[tool.coverage.paths] -source = [ - "src", - "**/site-packages" -] -[tool.coverage.report] -show_missing = true -skip_covered = true -skip_empty = true -precision = 1 -exclude_lines = [ - "pragma: no cover", - "@(abc\\.)?abstractmethod", - "NotImplementedError\\(\\)" -] +# See notes in the root pyproject.toml file. +source = ["src"] +source_pkgs = ["toga_cocoa"] diff --git a/core/pyproject.toml b/core/pyproject.toml index 4a8eda76ab..d7995e4537 100644 --- a/core/pyproject.toml +++ b/core/pyproject.toml @@ -6,21 +6,7 @@ build-backend = "setuptools.build_meta" parallel = true branch = true relative_files = true -source_pkgs = ["toga", "toga_dummy"] - -[tool.coverage.paths] -source = [ - "src", - "**/site-packages" -] -[tool.coverage.report] -show_missing = true -skip_covered = true -skip_empty = true -precision = 1 -exclude_lines = [ - "pragma: no cover", - "@(abc\\.)?abstractmethod", - "NotImplementedError\\(\\)" -] +# See notes in the root pyproject.toml file. +source = ["src", "../dummy/src"] +source_pkgs = ["toga", "toga_dummy"] diff --git a/gtk/pyproject.toml b/gtk/pyproject.toml index fc7d2a60f4..b650778c8c 100644 --- a/gtk/pyproject.toml +++ b/gtk/pyproject.toml @@ -6,21 +6,7 @@ build-backend = "setuptools.build_meta" parallel = true branch = true relative_files = true -source_pkgs = ["toga_gtk"] - -[tool.coverage.paths] -source = [ - "src", - "**/site-packages" -] -[tool.coverage.report] -show_missing = true -skip_covered = true -skip_empty = true -precision = 1 -exclude_lines = [ - "pragma: no cover", - "@(abc\\.)?abstractmethod", - "NotImplementedError\\(\\)" -] +# See notes in the root pyproject.toml file. +source = ["src"] +source_pkgs = ["toga_gtk"] diff --git a/iOS/pyproject.toml b/iOS/pyproject.toml index 836b0bb1ca..2362a4f25c 100644 --- a/iOS/pyproject.toml +++ b/iOS/pyproject.toml @@ -6,21 +6,7 @@ build-backend = "setuptools.build_meta" parallel = true branch = true relative_files = true -source_pkgs = ["toga_iOS"] - -[tool.coverage.paths] -source = [ - "src", - "**/site-packages" -] -[tool.coverage.report] -show_missing = true -skip_covered = true -skip_empty = true -precision = 1 -exclude_lines = [ - "pragma: no cover", - "@(abc\\.)?abstractmethod", - "NotImplementedError\\(\\)" -] +# See notes in the root pyproject.toml file. +source = ["src"] +source_pkgs = ["toga_iOS"] diff --git a/pyproject.toml b/pyproject.toml index 20990d16aa..4548122ab7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,58 +1,58 @@ +# The coverage settings in this file only control `coverage combine` and `coverage report`. +# `coverage run` is controlled by the pyproject.toml files in each package's subdirectory. +# +# To view coverage reports locally, run something like this in the repository root +# directory: +# +# tox -c core -e py && coverage combine core/.coverage* && coverage report + [tool.coverage.run] -parallel = true -branch = true relative_files = true -source = [ - "android", - "cocoa", - "core", - "dummy", - "gtk", - "iOS", - "web", - "winforms", -] +# In each subdirectory's pyproject.toml, we use both of the following settings: +# * `source_pkgs`: detects the given packages no matter where they're imported from. +# * `source`: detects all files in the given directory, including files that are +# never imported by the tests. +# +# When running through `tox`, this will produce duplicate entries which must be merged +# with `coverage combine` using the lists below. In each list, the first item is a path to +# a source code directory, and the other items are paths in the coverage data which will +# be mapped to that directory. The order of the lists is significant, but their names are +# not. [tool.coverage.paths] android = [ "android/src/toga_android", - "src/toga_android", - "**/site-packages/toga_android", + "**/toga_android", ] cocoa = [ "cocoa/src/toga_cocoa", - "src/toga_cocoa", - "**/site-packages/toga_cocoa", -] -core = [ - "core/src/toga", - "src/toga", - "**/site-packages/toga", + "**/toga_cocoa", ] dummy = [ "dummy/src/toga_dummy", - "src/toga_dummy", - "**/site-packages/toga_dummy", + "**/toga_dummy", ] gtk = [ "gtk/src/toga_gtk", - "src/toga_gtk", - "**/site-packages/toga_gtk", + "**/toga_gtk", ] iOS = [ "iOS/src/toga_iOS", - "src/toga_iOS", - "**/site-packages/toga_iOS", + "**/toga_iOS", ] web = [ "web/src/toga_web", - "src/toga_web", - "**/site-packages/toga_web", + "**/toga_web", ] winforms = [ "winforms/src/toga_winforms", - "src/toga_winforms", - "**/site-packages/toga_winforms", + "**/toga_winforms", +] +# This one must come last, otherwise the wildcard would match too much, because the +# repository root directory is probably also called "toga". +core = [ + "core/src/toga", + "**/toga", ] [tool.coverage.report] diff --git a/web/pyproject.toml b/web/pyproject.toml index a8da535969..029344b9d8 100644 --- a/web/pyproject.toml +++ b/web/pyproject.toml @@ -6,21 +6,7 @@ build-backend = "setuptools.build_meta" parallel = true branch = true relative_files = true -source_pkgs = ["toga_web"] - -[tool.coverage.paths] -source = [ - "src", - "**/site-packages" -] -[tool.coverage.report] -show_missing = true -skip_covered = true -skip_empty = true -precision = 1 -exclude_lines = [ - "pragma: no cover", - "@(abc\\.)?abstractmethod", - "NotImplementedError\\(\\)" -] +# See notes in the root pyproject.toml file. +source = ["src"] +source_pkgs = ["toga_web"] diff --git a/winforms/pyproject.toml b/winforms/pyproject.toml index 8c0e295804..08a4ad7f3a 100644 --- a/winforms/pyproject.toml +++ b/winforms/pyproject.toml @@ -6,21 +6,7 @@ build-backend = "setuptools.build_meta" parallel = true branch = true relative_files = true -source_pkgs = ["toga_winforms"] - -[tool.coverage.paths] -source = [ - "src", - "**/site-packages" -] -[tool.coverage.report] -show_missing = true -skip_covered = true -skip_empty = true -precision = 1 -exclude_lines = [ - "pragma: no cover", - "@(abc\\.)?abstractmethod", - "NotImplementedError\\(\\)" -] +# See notes in the root pyproject.toml file. +source = ["src"] +source_pkgs = ["toga_winforms"] From 1ee69f683acf1a3e39e1a00a7f56991f6ebbe635 Mon Sep 17 00:00:00 2001 From: Malcolm Smith Date: Wed, 9 Nov 2022 17:03:25 +0000 Subject: [PATCH 2/8] Update coverage version used by CI to fix Windows path issues --- .github/workflows/ci.yml | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6c2b3029c1..2e5110282c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,7 +77,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - python -m pip install tox coverage[toml] + python -m pip install tox coverage[toml]~=6.6.0b1 - name: Get packages uses: actions/download-artifact@v3 with: @@ -123,17 +123,11 @@ jobs: python-version: ${{ env.max_python_version }} - name: Install dependencies run: | - python -m pip install coverage[toml] + python -m pip install coverage[toml]~=6.6.0b1 - name: Retrieve coverage data uses: actions/download-artifact@v3 with: name: core-coverage-data - - name: Normalize paths in coverage data - run: | - # See https://github.com/nedbat/coveragepy/issues/991 - for coverage in `ls .coverage.*`; do - sqlite3 $coverage "update file set path = replace(path, '\\', '/')" - done - name: Combine coverage run: | python -m coverage combine @@ -186,7 +180,7 @@ jobs: - name: Install dependencies run: | ${{ matrix.pre-command }} - python -m pip install tox coverage[toml] + python -m pip install tox coverage[toml]~=6.6.0b1 - name: Test env: TOGA_INSTALL_COMMAND: 'bash -c "pip install ../{core,dummy,${{ matrix.backend }}}/dist/*.whl"' @@ -220,17 +214,11 @@ jobs: python-version: ${{ env.max_python_version }} - name: Install dependencies run: | - python -m pip install coverage[toml] + python -m pip install coverage[toml]~=6.6.0b1 - name: Retrieve coverage data uses: actions/download-artifact@v3 with: name: backend-coverage-data - - name: Normalize paths in coverage data - run: | - # See https://github.com/nedbat/coveragepy/issues/991 - for coverage in `ls .coverage.*`; do - sqlite3 $coverage "update file set path = replace(path, '\\', '/')" - done - name: Combine coverage run: | python -m coverage combine From 29268f3c3e8744e432c6665516a8e5b89345fe6d Mon Sep 17 00:00:00 2001 From: Malcolm Smith Date: Wed, 9 Nov 2022 17:06:52 +0000 Subject: [PATCH 3/8] Add changenote --- changes/1673.misc.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/1673.misc.rst diff --git a/changes/1673.misc.rst b/changes/1673.misc.rst new file mode 100644 index 0000000000..64ea19c26a --- /dev/null +++ b/changes/1673.misc.rst @@ -0,0 +1 @@ +Corrected coverage path mapping. From 38db0329a3ae8ec3738cc6b990479c428a641c2f Mon Sep 17 00:00:00 2001 From: Malcolm Smith Date: Thu, 10 Nov 2022 21:30:29 +0000 Subject: [PATCH 4/8] Make `tox -e py` run `coverage combine` and `coverage report` automatically --- .github/workflows/ci.yml | 64 +++++----------------------------------- android/tox.ini | 3 +- cocoa/tox.ini | 3 +- core/tox.ini | 3 +- gtk/tox.ini | 3 +- iOS/tox.ini | 3 +- pyproject.toml | 5 ---- web/tox.ini | 3 +- winforms/tox.ini | 3 +- 9 files changed, 21 insertions(+), 69 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2e5110282c..7d880ff8d1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,22 +86,18 @@ jobs: env: TOGA_INSTALL_COMMAND: 'bash -c "pip install ../{core,dummy}/dist/*.whl"' run: | - cd core - tox -e py - mv .coverage.* .. + tox -c core -e py + mv .coverage .coverage.${{ matrix.platform }}.${{ matrix.python-version }} - name: Store coverage data uses: actions/upload-artifact@v3 with: name: core-coverage-data path: ".coverage.*" - if-no-files-found: ignore - - name: Report platform coverage + if-no-files-found: error + - name: Create CodeCov report run: | - python -m coverage combine - python -m coverage report - # Generate XML report for CodeCov python -m coverage xml - - name: Upload coverage data to CodeCov + - name: Upload CodeCov report uses: codecov/codecov-action@v3 with: token: ${{ secrets.CODECOV_TOKEN }} @@ -180,55 +176,9 @@ jobs: - name: Install dependencies run: | ${{ matrix.pre-command }} - python -m pip install tox coverage[toml]~=6.6.0b1 + python -m pip install tox - name: Test env: TOGA_INSTALL_COMMAND: 'bash -c "pip install ../{core,dummy,${{ matrix.backend }}}/dist/*.whl"' run: | - cd ${{ matrix.backend }} - tox -e py - mv .coverage.* .. - - name: Store coverage data - uses: actions/upload-artifact@v3 - with: - name: backend-coverage-data - path: ".coverage.*" - if-no-files-found: ignore - - name: Report platform coverage - run: | - python -m coverage combine - python -m coverage report - - backend-coverage: - name: Combine & check backend coverage. - runs-on: ubuntu-latest - needs: - - backend - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - uses: actions/setup-python@v4.3.0 - with: - # Use latest, so it understands all syntax. - python-version: ${{ env.max_python_version }} - - name: Install dependencies - run: | - python -m pip install coverage[toml]~=6.6.0b1 - - name: Retrieve coverage data - uses: actions/download-artifact@v3 - with: - name: backend-coverage-data - - name: Combine coverage - run: | - python -m coverage combine - - name: Generate coverage report - run: | - python -m coverage html --skip-covered --skip-empty - python -m coverage report # --fail-under=100 - - name: Upload HTML report if check failed. - uses: actions/upload-artifact@v3 - with: - name: html-coverage-report - path: htmlcov - if: ${{ failure() }} + tox -c ${{ matrix.backend }} -e py diff --git a/android/tox.ini b/android/tox.ini index e5f89ac43e..f8263677da 100644 --- a/android/tox.ini +++ b/android/tox.ini @@ -12,7 +12,7 @@ skip_install = True deps = pytest pytest-tldr - coverage + coverage[toml]~=6.6.0b1 setenv = TOGA_BACKEND = toga_android allowlist_externals = bash @@ -20,3 +20,4 @@ allowlist_externals = commands = {env:TOGA_INSTALL_COMMAND:pip install ../core ../dummy .} python -m coverage run -m pytest -vv + bash -c "cd .. && coverage combine android && coverage report" diff --git a/cocoa/tox.ini b/cocoa/tox.ini index 88c61b2c45..76b6b8f0e3 100644 --- a/cocoa/tox.ini +++ b/cocoa/tox.ini @@ -12,7 +12,7 @@ skip_install = True deps = pytest pytest-tldr - coverage + coverage[toml]~=6.6.0b1 setenv = TOGA_BACKEND = toga_cocoa allowlist_externals = bash @@ -20,3 +20,4 @@ allowlist_externals = commands = {env:TOGA_INSTALL_COMMAND:pip install ../core ../dummy .} python -m coverage run -m pytest -vv + bash -c "cd .. && coverage combine cocoa && coverage report" diff --git a/core/tox.ini b/core/tox.ini index 11fa843984..7a7f172dec 100644 --- a/core/tox.ini +++ b/core/tox.ini @@ -12,7 +12,7 @@ skip_install = True deps = pytest pytest-tldr - coverage + coverage[toml]~=6.6.0b1 setenv = TOGA_BACKEND = toga_dummy allowlist_externals = bash @@ -20,3 +20,4 @@ allowlist_externals = commands = {env:TOGA_INSTALL_COMMAND:pip install . ../dummy} python -m coverage run -m pytest -vv + bash -c "cd .. && coverage combine core && coverage report" diff --git a/gtk/tox.ini b/gtk/tox.ini index d1d0066f92..dae4d5d4a8 100644 --- a/gtk/tox.ini +++ b/gtk/tox.ini @@ -12,7 +12,7 @@ skip_install = True deps = pytest pytest-tldr - coverage + coverage[toml]~=6.6.0b1 setenv = TOGA_BACKEND = toga_gtk allowlist_externals = bash @@ -21,3 +21,4 @@ allowlist_externals = commands = {env:TOGA_INSTALL_COMMAND:pip install ../core ../dummy .} xvfb-run -a -s '-screen 0 2048x1536x24' python -m coverage run -m pytest -vv + bash -c "cd .. && coverage combine gtk && coverage report" diff --git a/iOS/tox.ini b/iOS/tox.ini index f58fd66128..ab132ccf83 100644 --- a/iOS/tox.ini +++ b/iOS/tox.ini @@ -12,7 +12,7 @@ skip_install = True deps = pytest pytest-tldr - coverage + coverage[toml]~=6.6.0b1 setenv = TOGA_BACKEND = toga_iOS allowlist_externals = bash @@ -20,3 +20,4 @@ allowlist_externals = commands = {env:TOGA_INSTALL_COMMAND:pip install ../core ../dummy .} python -m coverage run -m pytest -vv + bash -c "cd .. && coverage combine iOS && coverage report" diff --git a/pyproject.toml b/pyproject.toml index 4548122ab7..eee5137412 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,5 @@ # The coverage settings in this file only control `coverage combine` and `coverage report`. # `coverage run` is controlled by the pyproject.toml files in each package's subdirectory. -# -# To view coverage reports locally, run something like this in the repository root -# directory: -# -# tox -c core -e py && coverage combine core/.coverage* && coverage report [tool.coverage.run] relative_files = true diff --git a/web/tox.ini b/web/tox.ini index 5adf5b7612..01ade696fa 100644 --- a/web/tox.ini +++ b/web/tox.ini @@ -12,7 +12,7 @@ skip_install = True deps = pytest pytest-tldr - coverage + coverage[toml]~=6.6.0b1 setenv = TOGA_BACKEND = toga_web allowlist_externals = bash @@ -20,3 +20,4 @@ allowlist_externals = commands = {env:TOGA_INSTALL_COMMAND:pip install ../core ../dummy .} python -m coverage run -m pytest -vv + bash -c "cd .. && coverage combine web && coverage report" diff --git a/winforms/tox.ini b/winforms/tox.ini index c8979d07ba..1dc2c2bb01 100644 --- a/winforms/tox.ini +++ b/winforms/tox.ini @@ -12,7 +12,7 @@ skip_install = True deps = pytest pytest-tldr - coverage + coverage[toml]~=6.6.0b1 setenv = TOGA_BACKEND = toga_winforms allowlist_externals = bash @@ -20,3 +20,4 @@ allowlist_externals = commands = {env:TOGA_INSTALL_COMMAND:pip install ../core ../dummy .} python -m coverage run -m pytest -vv + bash -c "cd .. && coverage combine winforms && coverage report" From c4f481ec941afc00f53c795e6c03782ede40e997 Mon Sep 17 00:00:00 2001 From: Malcolm Smith Date: Thu, 10 Nov 2022 21:39:40 +0000 Subject: [PATCH 5/8] Correct ordering of coverage rename and xml --- .github/workflows/ci.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7d880ff8d1..ebd0ccb2ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -87,6 +87,7 @@ jobs: TOGA_INSTALL_COMMAND: 'bash -c "pip install ../{core,dummy}/dist/*.whl"' run: | tox -c core -e py + python -m coverage xml mv .coverage .coverage.${{ matrix.platform }}.${{ matrix.python-version }} - name: Store coverage data uses: actions/upload-artifact@v3 @@ -94,10 +95,7 @@ jobs: name: core-coverage-data path: ".coverage.*" if-no-files-found: error - - name: Create CodeCov report - run: | - python -m coverage xml - - name: Upload CodeCov report + - name: Upload coverage data to CodeCov uses: codecov/codecov-action@v3 with: token: ${{ secrets.CODECOV_TOKEN }} From e971fd6f8ec3f16df05881a11278dd906b2b7537 Mon Sep 17 00:00:00 2001 From: Malcolm Smith Date: Sun, 13 Nov 2022 19:11:44 +0000 Subject: [PATCH 6/8] Merge tox.ini files into the repository root --- .github/workflows/ci.yml | 4 +-- android/pyproject.toml | 6 +++++ android/tox.ini | 23 ----------------- cocoa/pyproject.toml | 6 +++++ cocoa/tox.ini | 23 ----------------- core/pyproject.toml | 10 ++++++-- core/tox.ini | 23 ----------------- gtk/pyproject.toml | 6 +++++ gtk/tox.ini | 24 ------------------ iOS/pyproject.toml | 6 +++++ iOS/tox.ini | 23 ----------------- pyproject.toml | 53 ++++++---------------------------------- tox.ini | 35 ++++++++++++++++++++------ web/pyproject.toml | 6 +++++ web/tox.ini | 23 ----------------- winforms/pyproject.toml | 6 +++++ winforms/tox.ini | 23 ----------------- 17 files changed, 82 insertions(+), 218 deletions(-) delete mode 100644 android/tox.ini delete mode 100644 cocoa/tox.ini delete mode 100644 core/tox.ini delete mode 100644 gtk/tox.ini delete mode 100644 iOS/tox.ini delete mode 100644 web/tox.ini delete mode 100644 winforms/tox.ini diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ebd0ccb2ec..1fd889513e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,7 +86,7 @@ jobs: env: TOGA_INSTALL_COMMAND: 'bash -c "pip install ../{core,dummy}/dist/*.whl"' run: | - tox -c core -e py + tox -e py-core python -m coverage xml mv .coverage .coverage.${{ matrix.platform }}.${{ matrix.python-version }} - name: Store coverage data @@ -179,4 +179,4 @@ jobs: env: TOGA_INSTALL_COMMAND: 'bash -c "pip install ../{core,dummy,${{ matrix.backend }}}/dist/*.whl"' run: | - tox -c ${{ matrix.backend }} -e py + tox -e py-${{ matrix.backend }} diff --git a/android/pyproject.toml b/android/pyproject.toml index 4d45102abf..b6b018aac3 100644 --- a/android/pyproject.toml +++ b/android/pyproject.toml @@ -10,3 +10,9 @@ relative_files = true # See notes in the root pyproject.toml file. source = ["src"] source_pkgs = ["toga_android"] + +[tool.coverage.paths] +source = [ + "src/toga_android", + "**/toga_android", +] diff --git a/android/tox.ini b/android/tox.ini deleted file mode 100644 index f8263677da..0000000000 --- a/android/tox.ini +++ /dev/null @@ -1,23 +0,0 @@ -# Tox (http://tox.testrun.org/) is a tool for running tests -# in multiple virtualenvs. This configuration file will run the -# test suite on all supported python versions. To use it, "pip install tox" -# and then run "tox" from this directory. - -[tox] -envlist = py{37,38,39,310,311} -skip_missing_interpreters = true - -[testenv] -skip_install = True -deps = - pytest - pytest-tldr - coverage[toml]~=6.6.0b1 -setenv = TOGA_BACKEND = toga_android -allowlist_externals = - bash -# TOGA_INSTALL_COMMAND is set to a bash command by the CI workflow. -commands = - {env:TOGA_INSTALL_COMMAND:pip install ../core ../dummy .} - python -m coverage run -m pytest -vv - bash -c "cd .. && coverage combine android && coverage report" diff --git a/cocoa/pyproject.toml b/cocoa/pyproject.toml index 67d6d91367..45e68aa73f 100644 --- a/cocoa/pyproject.toml +++ b/cocoa/pyproject.toml @@ -10,3 +10,9 @@ relative_files = true # See notes in the root pyproject.toml file. source = ["src"] source_pkgs = ["toga_cocoa"] + +[tool.coverage.paths] +source = [ + "src/toga_cocoa", + "**/toga_cocoa", +] diff --git a/cocoa/tox.ini b/cocoa/tox.ini deleted file mode 100644 index 76b6b8f0e3..0000000000 --- a/cocoa/tox.ini +++ /dev/null @@ -1,23 +0,0 @@ -# Tox (http://tox.testrun.org/) is a tool for running tests -# in multiple virtualenvs. This configuration file will run the -# test suite on all supported python versions. To use it, "pip install tox" -# and then run "tox" from this directory. - -[tox] -envlist = py{37,38,39,310,311} -skip_missing_interpreters = true - -[testenv] -skip_install = True -deps = - pytest - pytest-tldr - coverage[toml]~=6.6.0b1 -setenv = TOGA_BACKEND = toga_cocoa -allowlist_externals = - bash -# TOGA_INSTALL_COMMAND is set to a bash command by the CI workflow. -commands = - {env:TOGA_INSTALL_COMMAND:pip install ../core ../dummy .} - python -m coverage run -m pytest -vv - bash -c "cd .. && coverage combine cocoa && coverage report" diff --git a/core/pyproject.toml b/core/pyproject.toml index d7995e4537..ff12ce7437 100644 --- a/core/pyproject.toml +++ b/core/pyproject.toml @@ -8,5 +8,11 @@ branch = true relative_files = true # See notes in the root pyproject.toml file. -source = ["src", "../dummy/src"] -source_pkgs = ["toga", "toga_dummy"] +source = ["src"] +source_pkgs = ["toga"] + +[tool.coverage.paths] +source = [ + "src/toga", + "**/toga", +] diff --git a/core/tox.ini b/core/tox.ini deleted file mode 100644 index 7a7f172dec..0000000000 --- a/core/tox.ini +++ /dev/null @@ -1,23 +0,0 @@ -# Tox (http://tox.testrun.org/) is a tool for running tests -# in multiple virtualenvs. This configuration file will run the -# test suite on all supported python versions. To use it, "pip install tox" -# and then run "tox" from this directory. - -[tox] -envlist = py{37,38,39,310,311} -skip_missing_interpreters = true - -[testenv] -skip_install = True -deps = - pytest - pytest-tldr - coverage[toml]~=6.6.0b1 -setenv = TOGA_BACKEND = toga_dummy -allowlist_externals = - bash -# TOGA_INSTALL_COMMAND is set to a bash command by the CI workflow. -commands = - {env:TOGA_INSTALL_COMMAND:pip install . ../dummy} - python -m coverage run -m pytest -vv - bash -c "cd .. && coverage combine core && coverage report" diff --git a/gtk/pyproject.toml b/gtk/pyproject.toml index b650778c8c..51e3e34788 100644 --- a/gtk/pyproject.toml +++ b/gtk/pyproject.toml @@ -10,3 +10,9 @@ relative_files = true # See notes in the root pyproject.toml file. source = ["src"] source_pkgs = ["toga_gtk"] + +[tool.coverage.paths] +source = [ + "src/toga_gtk", + "**/toga_gtk", +] diff --git a/gtk/tox.ini b/gtk/tox.ini deleted file mode 100644 index dae4d5d4a8..0000000000 --- a/gtk/tox.ini +++ /dev/null @@ -1,24 +0,0 @@ -# Tox (http://tox.testrun.org/) is a tool for running tests -# in multiple virtualenvs. This configuration file will run the -# test suite on all supported python versions. To use it, "pip install tox" -# and then run "tox" from this directory. - -[tox] -envlist = py{37,38,39,310,311} -skip_missing_interpreters = true - -[testenv] -skip_install = True -deps = - pytest - pytest-tldr - coverage[toml]~=6.6.0b1 -setenv = TOGA_BACKEND = toga_gtk -allowlist_externals = - bash - xvfb-run -# TOGA_INSTALL_COMMAND is set to a bash command by the CI workflow. -commands = - {env:TOGA_INSTALL_COMMAND:pip install ../core ../dummy .} - xvfb-run -a -s '-screen 0 2048x1536x24' python -m coverage run -m pytest -vv - bash -c "cd .. && coverage combine gtk && coverage report" diff --git a/iOS/pyproject.toml b/iOS/pyproject.toml index 2362a4f25c..3d5244464d 100644 --- a/iOS/pyproject.toml +++ b/iOS/pyproject.toml @@ -10,3 +10,9 @@ relative_files = true # See notes in the root pyproject.toml file. source = ["src"] source_pkgs = ["toga_iOS"] + +[tool.coverage.paths] +source = [ + "src/toga_iOS", + "**/toga_iOS", +] diff --git a/iOS/tox.ini b/iOS/tox.ini deleted file mode 100644 index ab132ccf83..0000000000 --- a/iOS/tox.ini +++ /dev/null @@ -1,23 +0,0 @@ -# Tox (http://tox.testrun.org/) is a tool for running tests -# in multiple virtualenvs. This configuration file will run the -# test suite on all supported python versions. To use it, "pip install tox" -# and then run "tox" from this directory. - -[tox] -envlist = py{37,38,39,310,311} -skip_missing_interpreters = true - -[testenv] -skip_install = True -deps = - pytest - pytest-tldr - coverage[toml]~=6.6.0b1 -setenv = TOGA_BACKEND = toga_iOS -allowlist_externals = - bash -# TOGA_INSTALL_COMMAND is set to a bash command by the CI workflow. -commands = - {env:TOGA_INSTALL_COMMAND:pip install ../core ../dummy .} - python -m coverage run -m pytest -vv - bash -c "cd .. && coverage combine iOS && coverage report" diff --git a/pyproject.toml b/pyproject.toml index eee5137412..90f22ecd40 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,54 +1,17 @@ -# The coverage settings in this file only control `coverage combine` and `coverage report`. -# `coverage run` is controlled by the pyproject.toml files in each package's subdirectory. - -[tool.coverage.run] -relative_files = true - +# The coverage settings in this file only control `coverage report`. `coverage run` and +# `coverage combine` are controlled by the pyproject.toml files in each package's +# subdirectory. +# # In each subdirectory's pyproject.toml, we use both of the following settings: # * `source_pkgs`: detects the given packages no matter where they're imported from. # * `source`: detects all files in the given directory, including files that are # never imported by the tests. # # When running through `tox`, this will produce duplicate entries which must be merged -# with `coverage combine` using the lists below. In each list, the first item is a path to -# a source code directory, and the other items are paths in the coverage data which will -# be mapped to that directory. The order of the lists is significant, but their names are -# not. -[tool.coverage.paths] -android = [ - "android/src/toga_android", - "**/toga_android", -] -cocoa = [ - "cocoa/src/toga_cocoa", - "**/toga_cocoa", -] -dummy = [ - "dummy/src/toga_dummy", - "**/toga_dummy", -] -gtk = [ - "gtk/src/toga_gtk", - "**/toga_gtk", -] -iOS = [ - "iOS/src/toga_iOS", - "**/toga_iOS", -] -web = [ - "web/src/toga_web", - "**/toga_web", -] -winforms = [ - "winforms/src/toga_winforms", - "**/toga_winforms", -] -# This one must come last, otherwise the wildcard would match too much, because the -# repository root directory is probably also called "toga". -core = [ - "core/src/toga", - "**/toga", -] +# with `coverage combine`. + +[tool.coverage.run] +relative_files = true [tool.coverage.report] show_missing = true diff --git a/tox.ini b/tox.ini index ca97c09a6d..170ea2948b 100644 --- a/tox.ini +++ b/tox.ini @@ -1,11 +1,32 @@ -# Tox (http://tox.testrun.org/) is a tool for running tests -# in multiple virtualenvs. This configuration file will run the -# test suite on all supported python versions. To use it, "pip install tox" -# and then run "tox" from this directory. +# The leading comma generates the "py-..." environments. +[testenv:py{,37,38,39,310,311,312}-{android,cocoa,core,gtk,iOS,web,winforms}] +skip_install = True +deps = + pytest + pytest-tldr + coverage[toml]~=6.6.0b1 +setenv = + android: subdir = android + cocoa: subdir = cocoa + core: subdir = core + gtk: subdir = gtk + iOS: subdir = iOS + web: subdir = web + winforms: subdir = winforms -[tox] -envlist = towncrier-check,docs,package -skip_missing_interpreters = true + core: TOGA_BACKEND = toga_dummy + !core: TOGA_BACKEND = toga_{env:subdir} + gtk: test_command_prefix = xvfb-run -a -s "-screen 0 2048x1536x24" +changedir = {env:subdir} +allowlist_externals = + bash + gtk: xvfb-run +commands = + # TOGA_INSTALL_COMMAND is set to a bash command by the CI workflow. + {env:TOGA_INSTALL_COMMAND:pip install . ../core ../dummy} + {env:test_command_prefix:} coverage run -m pytest -vv + coverage combine --keep + coverage report --rcfile ../pyproject.toml [testenv:towncrier-check] skip_install = True diff --git a/web/pyproject.toml b/web/pyproject.toml index 029344b9d8..911406014c 100644 --- a/web/pyproject.toml +++ b/web/pyproject.toml @@ -10,3 +10,9 @@ relative_files = true # See notes in the root pyproject.toml file. source = ["src"] source_pkgs = ["toga_web"] + +[tool.coverage.paths] +source = [ + "src/toga_web", + "**/toga_web", +] diff --git a/web/tox.ini b/web/tox.ini deleted file mode 100644 index 01ade696fa..0000000000 --- a/web/tox.ini +++ /dev/null @@ -1,23 +0,0 @@ -# Tox (http://tox.testrun.org/) is a tool for running tests -# in multiple virtualenvs. This configuration file will run the -# test suite on all supported python versions. To use it, "pip install tox" -# and then run "tox" from this directory. - -[tox] -envlist = py{37,38,39,310,311} -skip_missing_interpreters = true - -[testenv] -skip_install = True -deps = - pytest - pytest-tldr - coverage[toml]~=6.6.0b1 -setenv = TOGA_BACKEND = toga_web -allowlist_externals = - bash -# TOGA_INSTALL_COMMAND is set to a bash command by the CI workflow. -commands = - {env:TOGA_INSTALL_COMMAND:pip install ../core ../dummy .} - python -m coverage run -m pytest -vv - bash -c "cd .. && coverage combine web && coverage report" diff --git a/winforms/pyproject.toml b/winforms/pyproject.toml index 08a4ad7f3a..16281bcf4d 100644 --- a/winforms/pyproject.toml +++ b/winforms/pyproject.toml @@ -10,3 +10,9 @@ relative_files = true # See notes in the root pyproject.toml file. source = ["src"] source_pkgs = ["toga_winforms"] + +[tool.coverage.paths] +source = [ + "src/toga_winforms", + "**/toga_winforms", +] diff --git a/winforms/tox.ini b/winforms/tox.ini deleted file mode 100644 index 1dc2c2bb01..0000000000 --- a/winforms/tox.ini +++ /dev/null @@ -1,23 +0,0 @@ -# Tox (http://tox.testrun.org/) is a tool for running tests -# in multiple virtualenvs. This configuration file will run the -# test suite on all supported python versions. To use it, "pip install tox" -# and then run "tox" from this directory. - -[tox] -envlist = py{37,38,39,310,311} -skip_missing_interpreters = true - -[testenv] -skip_install = True -deps = - pytest - pytest-tldr - coverage[toml]~=6.6.0b1 -setenv = TOGA_BACKEND = toga_winforms -allowlist_externals = - bash -# TOGA_INSTALL_COMMAND is set to a bash command by the CI workflow. -commands = - {env:TOGA_INSTALL_COMMAND:pip install ../core ../dummy .} - python -m coverage run -m pytest -vv - bash -c "cd .. && coverage combine winforms && coverage report" From 0a9335a34583213ebffd0a75ff2146ede934afbb Mon Sep 17 00:00:00 2001 From: Malcolm Smith Date: Sun, 13 Nov 2022 21:04:21 +0000 Subject: [PATCH 7/8] Fix coverage paths in CI --- .github/workflows/ci.yml | 17 ++++++++++------- tox.ini | 3 ++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a1705d5d47..746dfa3aed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,6 +84,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | + # See https://github.com/nedbat/coveragepy/issues/991 python -m pip install tox coverage[toml]~=6.6.0b1 - name: Get packages uses: actions/download-artifact@v3 @@ -94,19 +95,20 @@ jobs: TOGA_INSTALL_COMMAND: 'bash -c "pip install ../{core,dummy}/dist/*.whl"' run: | tox -e py-core + cd core python -m coverage xml mv .coverage .coverage.${{ matrix.platform }}.${{ matrix.python-version }} - name: Store coverage data uses: actions/upload-artifact@v3 with: name: core-coverage-data - path: ".coverage.*" + path: "core/.coverage.*" if-no-files-found: error - name: Upload coverage data to CodeCov uses: codecov/codecov-action@v3 with: token: ${{ secrets.CODECOV_TOKEN }} - file: ./coverage.xml + file: core/coverage.xml flags: unittests fail_ci_if_error: true @@ -124,23 +126,24 @@ jobs: python-version: ${{ env.max_python_version }} - name: Install dependencies run: | + # See https://github.com/nedbat/coveragepy/issues/991 python -m pip install coverage[toml]~=6.6.0b1 - name: Retrieve coverage data uses: actions/download-artifact@v3 with: name: core-coverage-data - - name: Combine coverage - run: | - python -m coverage combine + path: core - name: Generate coverage report run: | + cd core + python -m coverage combine python -m coverage html --skip-covered --skip-empty - python -m coverage report # --fail-under=100 + python -m coverage report --rcfile ../pyproject.toml # --fail-under=100 - name: Upload HTML report if check failed. uses: actions/upload-artifact@v3 with: name: html-coverage-report - path: htmlcov + path: core/htmlcov if: ${{ failure() }} backend: diff --git a/tox.ini b/tox.ini index 170ea2948b..a3da155e0d 100644 --- a/tox.ini +++ b/tox.ini @@ -4,6 +4,7 @@ skip_install = True deps = pytest pytest-tldr + # See https://github.com/nedbat/coveragepy/issues/991 coverage[toml]~=6.6.0b1 setenv = android: subdir = android @@ -25,7 +26,7 @@ commands = # TOGA_INSTALL_COMMAND is set to a bash command by the CI workflow. {env:TOGA_INSTALL_COMMAND:pip install . ../core ../dummy} {env:test_command_prefix:} coverage run -m pytest -vv - coverage combine --keep + coverage combine coverage report --rcfile ../pyproject.toml [testenv:towncrier-check] From d16fe0dc6d5eb79e554ff9e117ceb64fb9badc83 Mon Sep 17 00:00:00 2001 From: Malcolm Smith Date: Sun, 13 Nov 2022 21:34:17 +0000 Subject: [PATCH 8/8] Update documentation to recommend running tests through tox --- docs/how-to/contribute-code.rst | 143 ++------------------------------ 1 file changed, 6 insertions(+), 137 deletions(-) diff --git a/docs/how-to/contribute-code.rst b/docs/how-to/contribute-code.rst index cbb429ed64..2d00d11ed4 100644 --- a/docs/how-to/contribute-code.rst +++ b/docs/how-to/contribute-code.rst @@ -362,39 +362,19 @@ Start by running the core test suite: .. code-block:: bash - (venv) $ cd core - (venv) $ TOGA_BACKEND=toga_dummy python setup.py test - ... - ---------------------------------------------------------------------- - Ran 181 tests in 0.343s - - OK (skipped=1) + (venv) $ tox -e py-core .. group-tab:: Linux .. code-block:: bash - (venv) $ cd core - (venv) $ TOGA_BACKEND=toga_dummy python setup.py test - ... - ---------------------------------------------------------------------- - Ran 181 tests in 0.343s - - OK (skipped=1) + (venv) $ tox -e py-core .. group-tab:: Windows .. code-block:: doscon - (venv) C:\...>cd core - (venv) C:\...>set TOGA_BACKEND=toga_dummy - (venv) C:\...>python setup.py test - (venv) C:\...>set TOGA_BACKEND= - ... - ---------------------------------------------------------------------- - Ran 181 tests in 0.343s - - OK (skipped=1) + (venv) C:\...>tox -e py-core You should get some output indicating that tests have been run. You shouldn't ever get any FAIL or ERROR test results. We run our full test suite before @@ -403,14 +383,6 @@ the patch. If you do find a test error or failure, either there's something odd in your test environment, or you've found an edge case that we haven't seen before - either way, let us know! -Note that when we run the test suite, we set the environment variable -``TOGA_BACKEND``. Under normal operation, Toga will automatically choose the -appropriate backend for your platform. However, when running the tests for -the core platform, we need to use a special "dummy" backend. This dummy backend -satisfies the interface contract of a Toga backend, but doesn't acutally -display any widgets. This allows us to test the behavior of the core library -independent of the behavior of a specific backend. - Although the tests should all pass, the test suite itself is still incomplete. There are many aspects of the Toga Core API that aren't currently tested (or aren't tested thoroughly). To work out what *isn't* tested, we're @@ -419,53 +391,9 @@ going to use a tool called `coverage check which lines of code have (and haven't) been executed - which then gives you an idea of what code has (and hasn't) been tested. -Install coverage, and then re-run the test suite -- this time, in a slightly -different way so that we can gather some data about the test run. Then we can -ask coverage to generate a report of the data that was gathered: - -.. tabs:: - - .. group-tab:: macOS - - .. code-block:: bash - - (venv) $ pip install coverage - (venv) $ TOGA_BACKEND=toga_dummy coverage run setup.py test - (venv) $ coverage report -m --include="toga/*" - Name Stmts Miss Cover Missing - ------------------------------------------------------------------ - toga/__init__.py 29 0 100% - toga/app.py 50 0 100% - ... - toga/window.py 79 18 77% 58, 75, 87, 92, 104, 141, 155, 164, 168, 172-173, 176, 192, 204, 216, 228, 243, 257 - ------------------------------------------------------------------ - TOTAL 1034 258 75% - - .. group-tab:: Linux - - .. code-block:: bash - - (venv) $ pip install coverage - (venv) $ TOGA_BACKEND=toga_dummy coverage run setup.py test - (venv) $ coverage report -m --include="toga/*" - Name Stmts Miss Cover Missing - ------------------------------------------------------------------ - toga/__init__.py 29 0 100% - toga/app.py 50 0 100% - ... - toga/window.py 79 18 77% 58, 75, 87, 92, 104, 141, 155, 164, 168, 172-173, 176, 192, 204, 216, 228, 243, 257 - ------------------------------------------------------------------ - TOTAL 1034 258 75% - - .. group-tab:: Windows - - .. code-block:: doscon +At the end of the test output there should be a report of the coverage data that +was gathered:: - (venv) C:\...>pip install coverage - (venv) C:\...>set TOGA_BACKEND=toga_dummy - (venv) C:\...>coverage run setup.py test - (venv) C:\...>set TOGA_BACKEND= - (venv) C:\...>coverage report -m --include=toga/* Name Stmts Miss Cover Missing ------------------------------------------------------------------ toga/__init__.py 29 0 100% @@ -491,22 +419,8 @@ Your task: create a test that improves coverage - even by one more line. Once you've written a test, re-run the test suite to generate fresh coverage data. Let's say we added a test for line 58 of ``toga/window.py`` - we'd -expect to see something like: +expect to see something like:: -.. tabs:: - - .. group-tab:: macOS - - .. code-block:: bash - - (venv) $ TOGA_BACKEND=toga_dummy coverage run setup.py test - running test - ... - ---------------------------------------------------------------------- - Ran 101 tests in 0.343s - - OK (skipped=1) - (venv) $ coverage report -m --include="toga/*" Name Stmts Miss Cover Missing ------------------------------------------------------------------ toga/__init__.py 29 0 100% @@ -516,51 +430,6 @@ expect to see something like: ------------------------------------------------------------------ TOTAL 1034 257 75% - .. group-tab:: Linux - - .. code-block:: bash - - (venv) $ TOGA_BACKEND=toga_dummy coverage run setup.py test - running test - ... - ---------------------------------------------------------------------- - Ran 101 tests in 0.343s - - OK (skipped=1) - (venv) $ coverage report -m --include="toga/*" - Name Stmts Miss Cover Missing - ------------------------------------------------------------------ - toga/__init__.py 29 0 100% - toga/app.py 50 0 100% - ... - toga/window.py 79 17 78% 75, 87, 92, 104, 141, 155, 164, 168, 172-173, 176, 192, 204, 216, 228, 243, 257 - ------------------------------------------------------------------ - TOTAL 1034 257 75% - - .. group-tab:: Windows - - .. code-block:: doscon - - (venv) C:\...>set TOGA_BACKEND=toga_dummy - (venv) C:\...>coverage run setup.py test - (venv) C:\...>set TOGA_BACKEND= - running test - ... - ---------------------------------------------------------------------- - Ran 101 tests in 0.343s - - OK (skipped=1) - (venv) $ coverage report -m --include=toga/* - Name Stmts Miss Cover Missing - ------------------------------------------------------------------ - toga/__init__.py 29 0 100% - toga/app.py 50 0 100% - ... - toga/window.py 79 17 78% 75, 87, 92, 104, 141, 155, 164, 168, 172-173, 176, 192, 204, 216, 228, 243, 257 - ------------------------------------------------------------------ - TOTAL 1034 257 75% - - That is, one more test has been executed, resulting in one less missing line in the coverage results.