-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/#426 #457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feature/#426 #457
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
192541d
#426: Allowed configuring the python version used for coverage
ckunki 2963ae4
Added first test
ckunki b48a0fd
Added tests
ckunki 774cd0d
Merge branch 'main' into feature/#426-Enhance_PTB_to_allow_configurin…
ckunki d6470ab
project:fix
ckunki c49b4c4
Updated workflows and templates
ckunki a0990e3
Added user guide
ckunki 44328fa
Apply suggestions from code review
ckunki 778833f
Fixed review findings.
ckunki 90fe8b8
Changes "Python" to upper case in user guide
ckunki 4820067
Moved MINIMUM_PYTHON_VERSION to _shared.py
ckunki e641440
project:fix
ckunki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,7 @@ | ||
| # Unreleased | ||
|
|
||
| ## Summary | ||
|
|
||
| ## ✨ Features | ||
|
|
||
| * #426: Allowed configuring the python version used for coverage |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| Collecting Metrics | ||
| ================== | ||
|
|
||
| PTB allows you to collect various metrics on the quality of your project | ||
| regarding Coverage, Security, and Static Code Analysis. | ||
|
|
||
| For each metric, there is a dedicated nox task, generating one or multiple | ||
| files and based on a selected external Python tool. | ||
|
|
||
| +-----------------------------+-----------------------------+--------------+ | ||
| | Nox Task | Generated Files | Based on | | ||
| +=============================+=============================+==============+ | ||
| | ``lint:code`` | ``lint.txt``, ``lint.json`` | ``pylint`` | | ||
| +-----------------------------+-----------------------------+--------------+ | ||
| | ``lint:security`` | ``.security.json`` | ``bandit`` | | ||
| +-----------------------------+-----------------------------+--------------+ | ||
| | ``test:unit -- --coverage`` | ``.coverage`` | ``coverage`` | | ||
| +-----------------------------+-----------------------------+--------------+ | ||
|
|
||
| The metrics are computed for each point in your build matrix, e.g. for each | ||
| Python version defined in file ``noxconfig.py``: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| @dataclass(frozen=True) | ||
| class Config: | ||
| python_versions = ["3.9", "3.10", "3.11", "3.12", "3.13"] | ||
|
|
||
| The GitHub workflows of your project can: | ||
|
|
||
| * Use a build matrix, e.g. using different Python versions as shown above | ||
| * Define multiple test sessions, e.g. for distinguishing fast vs. slow or expensive tests. | ||
|
|
||
| PTB combines the coverage data of all test sessions but using only the Python | ||
| version named first in attribute ``python_versions`` of class ``Config``. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,3 +12,4 @@ | |
| customization | ||
| migrating | ||
| how_to_release | ||
| collecting_metrics | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import contextlib | ||
| import re | ||
| from dataclasses import dataclass | ||
| from inspect import cleandoc | ||
| from pathlib import Path | ||
| from unittest.mock import ( | ||
| Mock, | ||
| call, | ||
| patch, | ||
| ) | ||
|
|
||
| import pytest | ||
|
|
||
| from exasol.toolbox.nox._artifacts import copy_artifacts | ||
|
|
||
|
|
||
| @contextlib.contextmanager | ||
| def mock_session(path: Path, python_version: str, *files: str): | ||
| with patch("exasol.toolbox.nox._artifacts.PROJECT_CONFIG") as config: | ||
| config.python_versions = [python_version] | ||
| for rel in files: | ||
| file = path / rel | ||
| file.parent.mkdir(parents=True, exist_ok=True) | ||
| file.write_text(rel) | ||
| yield Mock(posargs=[str(path)]) | ||
|
|
||
|
|
||
| def test_missing_files(tmp_path, capsys): | ||
| with mock_session(tmp_path, "9.9") as session: | ||
| copy_artifacts(session) | ||
| captured = capsys.readouterr() | ||
| assert re.match( | ||
| cleandoc( | ||
| f""" | ||
| Could not find any file .*/coverage-python9.9\\*/.coverage | ||
| File not found .*/lint-python9.9/.lint.txt | ||
| File not found .*/lint-python9.9/.lint.json | ||
| File not found .*/security-python9.9/.security.json | ||
| """ | ||
| ), | ||
| captured.err, | ||
| ) | ||
|
|
||
|
|
||
| @dataclass | ||
| class endswith: | ||
| """ | ||
| Assert that the str representation of the argument ends with the | ||
| specified suffix. | ||
| """ | ||
|
|
||
| suffix: str | ||
|
|
||
| def __eq__(self, actual): | ||
| return str(actual).endswith(self.suffix) | ||
|
|
||
|
|
||
| def test_all_files(tmp_path, capsys): | ||
| with mock_session( | ||
| tmp_path / "artifacts", | ||
| "9.9", | ||
| "coverage-python9.9-fast/.coverage", | ||
| "coverage-python9.9-slow/.coverage", | ||
| "lint-python9.9/.lint.txt", | ||
| "lint-python9.9/.lint.json", | ||
| "security-python9.9/.security.json", | ||
| ) as session: | ||
| copy_artifacts(session) | ||
|
|
||
| captured = capsys.readouterr() | ||
| assert session.run.call_args == call( | ||
| "coverage", | ||
| "combine", | ||
| "--keep", | ||
| endswith("coverage-python9.9-fast/.coverage"), | ||
| endswith("coverage-python9.9-slow/.coverage"), | ||
| ) | ||
| assert re.match( | ||
| cleandoc( | ||
| f""" | ||
| Copying file .*/lint-python9.9/.lint.txt | ||
| Copying file .*/lint-python9.9/.lint.json | ||
| Copying file .*/security-python9.9/.security.json | ||
| """ | ||
| ), | ||
| captured.err, | ||
| ) | ||
| for f in [".lint.txt", ".lint.json", ".security.json"]: | ||
| assert (tmp_path / f).exists() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,5 @@ | ||
| import subprocess | ||
| from unittest.mock import ( | ||
| patch, | ||
| ) | ||
| from unittest.mock import patch | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.