Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions doc/changes/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@

## Summary

Raised the minimum supported Python version from 3.11 to 3.11.5, as later versions of
`soupsieve` no longer support earlier patch releases and the vulnerability in
`soupsieve` for Python 3.11 could not otherwise be resolved.
In this major release, we:

* Dropped the Nox sessions `test:coverage` and `project:check`
* Modified the Nox sessions `test:unit` and `test:integration` to accept one or more
files or directories via `--paths`
* Raised the minimum supported Python version from 3.11 to 3.11.5, as later versions of
`soupsieve` no longer support earlier patch releases and the vulnerability in
`soupsieve` for Python 3.11 could not otherwise be resolved.

## Refactoring

* #998: Raised `requires-python` to `>=3.11.5,<4.0`
* #939:
* Removed Nox session `test:coverage`
* Removed Nox session `project:check`
* Modified Nox sessions `test:unit` and `test:integration` to accept one or more files or directories via `--paths`, overriding the default test directory
1 change: 0 additions & 1 deletion doc/user_guide/features/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ Use :code:`nox -l` to show the current list of sessions for your project
Common examples are as follows:

* :code:`nox -s format:fix` applies formatting changes.
* :code:`nox -s project:check` runs the main local quality gate.
* :code:`nox -s test:unit` runs unit tests.
* :code:`nox -s workflow:generate -- all` updates PTB workflow files.

Expand Down
60 changes: 0 additions & 60 deletions exasol/toolbox/nox/_shared.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
from __future__ import annotations

import argparse
from collections import ChainMap
from collections.abc import (
MutableMapping,
)
from enum import (
Enum,
auto,
)
from pathlib import Path
from typing import Any

from nox import Session

from noxconfig import (
PROJECT_CONFIG,
Expand Down Expand Up @@ -53,55 +45,3 @@ def validate_path_within_root(path: Path) -> Path:
)

return resolved_path


def _context_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
return parser


def _context(
session: Session,
parser: argparse.ArgumentParser,
default_context: dict[str, Any],
**kwargs: Any,
) -> MutableMapping[str, Any]:
namespace, args = parser.parse_known_args(session.posargs)
cli_context: MutableMapping[str, Any] = vars(namespace)
cli_context["fwd-args"] = args
# Note: ChainMap scans last to first
return ChainMap(kwargs, cli_context, default_context)


def _unit_test_context(session: Session, **kwargs: Any) -> MutableMapping[str, Any]:
parser = _context_parser()
parser.add_argument(
"--coverage", action="store_true", help="Enable the collection of coverage data"
)
return _context(session, parser, {"coverage": False}, **kwargs)


def _integration_test_context(
session: Session,
**kwargs: Any,
) -> MutableMapping[str, Any]:
parser = _context_parser()
parser.add_argument(
"--coverage", action="store_true", help="Enable the collection of coverage data"
)
parser.add_argument(
"--db-version",
default=PROJECT_CONFIG.minimum_exasol_version,
help="Specify the Exasol DB version to be used",
)
return _context(
session,
parser,
{
"coverage": False,
"db_version": PROJECT_CONFIG.minimum_exasol_version,
},
**kwargs,
)
133 changes: 81 additions & 52 deletions exasol/toolbox/nox/_test.py
Original file line number Diff line number Diff line change
@@ -1,104 +1,133 @@
from __future__ import annotations

import argparse
from collections.abc import (
Iterable,
MutableMapping,
)
from dataclasses import dataclass
from pathlib import Path
from typing import Any

import nox
from nox import Session

from exasol.toolbox.config import BaseConfig
from exasol.toolbox.nox._shared import (
_integration_test_context,
_unit_test_context,
)
from exasol.toolbox.nox.plugin import NoxTasks
from noxconfig import (
PROJECT_CONFIG,
)
from noxconfig import PROJECT_CONFIG

UNIT_TESTS_DIRECTORY = PROJECT_CONFIG.root_path / "test" / "unit"
INTEGRATION_TESTS_DIRECTORY = PROJECT_CONFIG.root_path / "test" / "integration"


@dataclass
class ArgparseResults:
Comment thread
ArBridgeman marked this conversation as resolved.
Resolved
"""
Records the results from the parsed session parameters.
Argparse separates these based on which arguments are expected (`known`)
and which are unknown (`other`).
"""

known: argparse.Namespace
other: list[str]


def _unit_test_context(session: Session) -> ArgparseResults:
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument(
"--paths",
nargs="+",
type=Path,
default=[UNIT_TESTS_DIRECTORY],
help="Paths (files or directories) to be tested",
)
parser.add_argument(
"--coverage", action="store_true", help="Enable the collection of coverage data"
)
return ArgparseResults(*parser.parse_known_args(session.posargs))


def _integration_test_context(session: Session) -> ArgparseResults:
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument(
"--paths",
nargs="+",
type=Path,
default=[INTEGRATION_TESTS_DIRECTORY],
help="Paths (files or directories) to be tested",
)
parser.add_argument(
"--coverage", action="store_true", help="Enable the collection of coverage data"
)
parser.add_argument(
"--db-version",
default=PROJECT_CONFIG.minimum_exasol_version,
help="Specify the Exasol DB version to be used",
)
return ArgparseResults(*parser.parse_known_args(session.posargs))


def _test_command(
path: Path, config: BaseConfig, context: MutableMapping[str, Any]
config: BaseConfig, argparse_results: ArgparseResults
) -> Iterable[str]:
coverage_command = (
[
coverage_command = []
if argparse_results.known.coverage:
coverage_command = [
"coverage",
"run",
"-a",
f"--rcfile={config.root_path / 'pyproject.toml'}",
"-m",
]
if context["coverage"]
else []
return (
coverage_command
+ ["pytest", *argparse_results.known.paths]
+ argparse_results.other
)
pytest_command = ["pytest", "-v", f"{path}"]
return coverage_command + pytest_command + context["fwd-args"]


def _unit_tests(
session: Session, config: BaseConfig, context: MutableMapping[str, Any]
) -> None:
command = _test_command(config.root_path / "test" / "unit", config, context)
session.run(*command)


def _integration_tests(
session: Session, config: BaseConfig, context: MutableMapping[str, Any]
session: Session, config: BaseConfig, argparse_results: ArgparseResults
) -> None:
pm = NoxTasks.plugin_manager(config)

# run pre integration test plugins
pm.hook.pre_integration_tests_hook(session=session, config=config, context=context)
pm.hook.pre_integration_tests_hook(
session=session, config=config, context=argparse_results
)

# Notes:
# - Catch exceptions and ensure post-hooks run before exiting
# - Consider making the executed command(s) configurable via a plugin hook
# (The default implementation of the hook could provide the current implementation)
command = _test_command(config.root_path / "test" / "integration", config, context)
command = _test_command(config, argparse_results)
session.run(*command)

# run post integration test plugins
pm.hook.post_integration_tests_hook(session=session, config=config, context=context)


def _coverage(
session: Session, config: BaseConfig, context: MutableMapping[str, Any]
) -> None:
command = ["coverage", "report", "-m"]
coverage_file = config.root_path / ".coverage"
coverage_file.unlink(missing_ok=True)
_unit_tests(session, config, context)
_integration_tests(session, config, context)
session.run(*command)
pm.hook.post_integration_tests_hook(
session=session, config=config, context=argparse_results
)


@nox.session(name="test:unit", python=False)
def unit_tests(session: Session) -> None:
"""Runs all unit tests"""
context = _unit_test_context(session)
_unit_tests(session, PROJECT_CONFIG, context)
argparse_results = _unit_test_context(session)
command = _test_command(PROJECT_CONFIG, argparse_results)
session.run(*command)


@nox.session(name="test:integration", python=False)
def integration_tests(session: Session) -> None:
"""
Runs the all integration tests
Runs all integration tests

If a project needs to execute code pre-/post the test execution,
it should provide appropriate hooks on their config object.
* pre_integration_tests_hook(session: Session, config: Config, context: MutableMapping[str, Any]) -> bool:
* post_integration_tests_hook(session: Session, config: Config, context: MutableMapping[str, Any]) -> bool:
* pre_integration_tests_hook
* post_integration_tests_hook
"""
context = _integration_test_context(session)
_integration_tests(session, PROJECT_CONFIG, context)


@nox.session(name="test:coverage", python=False)
def coverage(session: Session) -> None:
"""Runs all tests (unit + integration) and reports the code coverage"""
context = _integration_test_context(session, coverage=True)
_coverage(session, PROJECT_CONFIG, context)
argparse_results = _integration_test_context(session)
_integration_tests(session, PROJECT_CONFIG, argparse_results)
15 changes: 1 addition & 14 deletions exasol/toolbox/nox/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
__all__ = [
"Mode",
"build_docs",
"check",
"clean_docs",
"coverage",
"fix_format",
"integration_tests",
"lint",
Expand All @@ -32,19 +30,9 @@
from noxconfig import PROJECT_CONFIG


@nox.session(name="project:check", python=False)
def check(session: Session) -> None:
"""Runs all available checks on the project"""
context = _integration_test_context(session, coverage=True)
py_files = get_filtered_python_files(PROJECT_CONFIG.root_path)
_code_format(session, Mode.Check, py_files)
_pylint(session, py_files)
_type_check(session, py_files)
_coverage(session, PROJECT_CONFIG, context)


from exasol.toolbox.nox._test import (
_coverage,
coverage,
integration_tests,
unit_tests,
)
Expand All @@ -64,7 +52,6 @@ def check(session: Session) -> None:
from exasol.toolbox.nox._skills import check_skills, install_skills
from exasol.toolbox.nox._shared import (
Mode,
_integration_test_context,
get_filtered_python_files,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ replace it with configuration, a plugin hook, or a PTB extension point later.
2. Read the related tool sections in `pyproject.toml`.
3. Make the requested code change, document change, or configuration change.
4. Run the smallest PTB session that checks the change.
5. Run `project:check` when the change affects shared operation.
6. Run `project:check` when the change affects release readiness.
7. Run `project:check` when the change affects CI operation.

When you remove or rename a documentation file, update each Sphinx `toctree`
that points to it. Then run `docs:build`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ The sessions below match the PTB version that includes this skill.

| Session | Use | Notes |
| --- | --- | --- |
| `project:check` | Run large local checks or CI checks. | It runs format check, Pylint, Mypy, and coverage for unit and integration tests. |
| `format:fix` | Apply Python format changes. | It runs pyupgrade, Ruff fixes, isort, and Black. |
| `format:check` | Check Python format. | It runs Ruff check, isort check, and Black check. |
| `lint:code` | Run static code analysis. | It runs Pylint on `PROJECT_CONFIG.source_code_path` and writes `.lint.json`. |
Expand All @@ -32,7 +31,6 @@ The sessions below match the PTB version that includes this skill.
| --- | --- | --- |
| `test:unit` | Run unit tests. | It runs `pytest -v test/unit`. Put Pytest options after `--`; use `-k` to select tests by name. |
| `test:integration` | Run integration tests. | It runs `pytest -v test/integration`. It supports PTB integration test hooks. |
| `test:coverage` | Run all tests with coverage. | It runs unit and integration tests with coverage. It prints `coverage report -m`. |

Test command examples:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ Read the source file before you explain a detailed rule.
- `exasol/toolbox/nox/_package.py`: package validation.
- `exasol/toolbox/nox/_release.py`: release preparation, release update, and
release trigger sessions.
- `exasol/toolbox/nox/_test.py`: `test:unit`, `test:integration`, and
`test:coverage`.
- `exasol/toolbox/nox/_test.py`: `test:unit` and `test:integration`
- `exasol/toolbox/nox/_workflow.py`: workflow check, generation, and audit
sessions.

Expand Down
2 changes: 0 additions & 2 deletions test/integration/project-template/nox_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
EXPECTED_NOX_SESSIONS = {
"format:fix",
"format:check",
"project:check",
"test:unit",
"test:integration",
"test:coverage",
"lint:code",
"lint:typing",
"lint:security",
Expand Down
1 change: 0 additions & 1 deletion test/resources/skills/exasol-python-toolbox/eval_cases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ cases:
- ".pre-commit-config.yaml"
- "pre-commit"
- "pre-push"
- "project:check"
- "nox-sessions.md"
must_not_include:
- "run Pytest directly"
Expand Down
Loading