pytest-remaster 0.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pytest_remaster-0.0.0/.github/FUNDING.yml +12 -0
- pytest_remaster-0.0.0/.github/SECURITY.md +3 -0
- pytest_remaster-0.0.0/.github/dependabot.yml +15 -0
- pytest_remaster-0.0.0/.github/workflows/ci.yaml +24 -0
- pytest_remaster-0.0.0/.github/workflows/release.yaml +65 -0
- pytest_remaster-0.0.0/.gitignore +4 -0
- pytest_remaster-0.0.0/.pre-commit-config.yaml +40 -0
- pytest_remaster-0.0.0/LICENSE +21 -0
- pytest_remaster-0.0.0/PKG-INFO +48 -0
- pytest_remaster-0.0.0/README.md +20 -0
- pytest_remaster-0.0.0/pyproject.toml +45 -0
- pytest_remaster-0.0.0/setup.cfg +4 -0
- pytest_remaster-0.0.0/src/pytest_remaster/__init__.py +13 -0
- pytest_remaster-0.0.0/src/pytest_remaster/core.py +143 -0
- pytest_remaster-0.0.0/src/pytest_remaster/plugin.py +54 -0
- pytest_remaster-0.0.0/src/pytest_remaster.egg-info/PKG-INFO +48 -0
- pytest_remaster-0.0.0/src/pytest_remaster.egg-info/SOURCES.txt +34 -0
- pytest_remaster-0.0.0/src/pytest_remaster.egg-info/dependency_links.txt +1 -0
- pytest_remaster-0.0.0/src/pytest_remaster.egg-info/entry_points.txt +2 -0
- pytest_remaster-0.0.0/src/pytest_remaster.egg-info/requires.txt +6 -0
- pytest_remaster-0.0.0/src/pytest_remaster.egg-info/top_level.txt +1 -0
- pytest_remaster-0.0.0/tests/__init__.py +0 -0
- pytest_remaster-0.0.0/tests/conftest.py +1 -0
- pytest_remaster-0.0.0/tests/demo/__init__.py +0 -0
- pytest_remaster-0.0.0/tests/demo/cases/greet/goodbye/command +1 -0
- pytest_remaster-0.0.0/tests/demo/cases/greet/goodbye/result_0 +1 -0
- pytest_remaster-0.0.0/tests/demo/cases/greet/goodbye/result_1 +1 -0
- pytest_remaster-0.0.0/tests/demo/cases/greet/hello/command +1 -0
- pytest_remaster-0.0.0/tests/demo/cases/greet/hello/result_0 +1 -0
- pytest_remaster-0.0.0/tests/demo/cases/help/unknown-command/command +1 -0
- pytest_remaster-0.0.0/tests/demo/cases/help/unknown-command/result_0 +1 -0
- pytest_remaster-0.0.0/tests/demo/cases/help/unknown-command/result_1 +1 -0
- pytest_remaster-0.0.0/tests/demo/chatbot.py +43 -0
- pytest_remaster-0.0.0/tests/demo/test_chatbot.py +22 -0
- pytest_remaster-0.0.0/tests/test_core.py +253 -0
- pytest_remaster-0.0.0/tests/test_plugin.py +95 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# These are supported funding model platforms
|
|
2
|
+
|
|
3
|
+
github: [Pierre-Sassoulas]
|
|
4
|
+
patreon: # Replace with a single Patreon username
|
|
5
|
+
open_collective: # Replace with a single Open Collective username
|
|
6
|
+
ko_fi: # Replace with a single Ko-fi username
|
|
7
|
+
tidelift: "pypi/pytest-remaster"
|
|
8
|
+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
|
9
|
+
liberapay: # Replace with a single Liberapay username
|
|
10
|
+
issuehunt: Pierre-Sassoulas
|
|
11
|
+
otechie: # Replace with a single Otechie username
|
|
12
|
+
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# To get started with Dependabot version updates, you'll need to specify which
|
|
2
|
+
# package ecosystems to update and where the package manifests are located.
|
|
3
|
+
# Please see the documentation for all configuration options:
|
|
4
|
+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
|
5
|
+
|
|
6
|
+
version: 2
|
|
7
|
+
updates:
|
|
8
|
+
- package-ecosystem: "github-actions" # See documentation for possible values
|
|
9
|
+
directory: "/" # Location of package manifests
|
|
10
|
+
schedule:
|
|
11
|
+
interval: "monthly"
|
|
12
|
+
- package-ecosystem: "pip"
|
|
13
|
+
directory: "/"
|
|
14
|
+
schedule:
|
|
15
|
+
interval: "monthly"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request: ~
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
tests:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.15-dev"]
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
|
17
|
+
- name: Python-${{ matrix.python-version }}
|
|
18
|
+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
|
|
19
|
+
with:
|
|
20
|
+
python-version: ${{ matrix.python-version }}
|
|
21
|
+
- name: Install dependencies
|
|
22
|
+
run: pip3 install -e ".[dev]"
|
|
23
|
+
- name: Test
|
|
24
|
+
run: pytest
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types:
|
|
6
|
+
- published
|
|
7
|
+
|
|
8
|
+
env:
|
|
9
|
+
DEFAULT_PYTHON: "3.13"
|
|
10
|
+
|
|
11
|
+
permissions:
|
|
12
|
+
contents: read
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
build:
|
|
16
|
+
name: Build release assets
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
if: github.event_name == 'release'
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
|
21
|
+
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
|
|
22
|
+
with:
|
|
23
|
+
python-version: ${{ env.DEFAULT_PYTHON }}
|
|
24
|
+
check-latest: true
|
|
25
|
+
- run: python -m pip install build
|
|
26
|
+
- run: python -m build
|
|
27
|
+
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
|
|
28
|
+
with:
|
|
29
|
+
name: release-assets
|
|
30
|
+
path: dist/
|
|
31
|
+
|
|
32
|
+
release-pypi:
|
|
33
|
+
name: Upload release to PyPI
|
|
34
|
+
runs-on: ubuntu-latest
|
|
35
|
+
needs: ["build"]
|
|
36
|
+
environment:
|
|
37
|
+
name: PyPI
|
|
38
|
+
url: https://pypi.org/project/pytest-remaster/
|
|
39
|
+
permissions:
|
|
40
|
+
id-token: write
|
|
41
|
+
steps:
|
|
42
|
+
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
|
43
|
+
with:
|
|
44
|
+
name: release-assets
|
|
45
|
+
path: dist/
|
|
46
|
+
- uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
|
|
47
|
+
|
|
48
|
+
release-github:
|
|
49
|
+
name: Upload assets to Github release
|
|
50
|
+
runs-on: ubuntu-latest
|
|
51
|
+
needs: ["build"]
|
|
52
|
+
permissions:
|
|
53
|
+
contents: write
|
|
54
|
+
id-token: write
|
|
55
|
+
steps:
|
|
56
|
+
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
|
57
|
+
with:
|
|
58
|
+
name: release-assets
|
|
59
|
+
path: dist/
|
|
60
|
+
- uses: sigstore/gh-action-sigstore-python@a5caf349bc536fbef3668a10ed7f5cd309a4b53d # v3.2.0
|
|
61
|
+
if: github.event_name == 'release'
|
|
62
|
+
with:
|
|
63
|
+
inputs: |
|
|
64
|
+
./dist/*.tar.gz
|
|
65
|
+
./dist/*.whl
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
ci:
|
|
2
|
+
skip: [pylint]
|
|
3
|
+
|
|
4
|
+
repos:
|
|
5
|
+
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
|
6
|
+
rev: "v0.15.7"
|
|
7
|
+
hooks:
|
|
8
|
+
- id: ruff-check
|
|
9
|
+
args: ["--fix"]
|
|
10
|
+
- id: ruff-format
|
|
11
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
12
|
+
rev: v6.0.0
|
|
13
|
+
hooks:
|
|
14
|
+
- id: check-merge-conflict
|
|
15
|
+
- id: trailing-whitespace
|
|
16
|
+
args: [--markdown-linebreak-ext=md]
|
|
17
|
+
- id: end-of-file-fixer
|
|
18
|
+
- repo: https://github.com/tox-dev/pyproject-fmt
|
|
19
|
+
rev: "v2.20.0"
|
|
20
|
+
hooks:
|
|
21
|
+
- id: pyproject-fmt
|
|
22
|
+
- repo: local
|
|
23
|
+
hooks:
|
|
24
|
+
- id: pylint
|
|
25
|
+
name: pylint
|
|
26
|
+
entry: pylint
|
|
27
|
+
language: system
|
|
28
|
+
args: ["-sn", "-rn", "--enable-all-extensions"]
|
|
29
|
+
types: [python]
|
|
30
|
+
- repo: https://github.com/pre-commit/mirrors-mypy
|
|
31
|
+
rev: v1.19.1
|
|
32
|
+
hooks:
|
|
33
|
+
- id: mypy
|
|
34
|
+
args: ["--strict"]
|
|
35
|
+
additional_dependencies: [pytest>=7.0]
|
|
36
|
+
- repo: https://github.com/rbubley/mirrors-prettier
|
|
37
|
+
rev: v3.8.1
|
|
38
|
+
hooks:
|
|
39
|
+
- id: prettier
|
|
40
|
+
args: [--prose-wrap=always, --print-width=88]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pierre Sassoulas
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pytest-remaster
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: Golden master testing for pytest with automatic regeneration.
|
|
5
|
+
Author: Pierre Sassoulas
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Pierre-Sassoulas/pytest-remaster
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Framework :: Pytest
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Topic :: Software Development :: Testing
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: pytest>=7
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pre-commit; extra == "dev"
|
|
25
|
+
Requires-Dist: pylint>4; extra == "dev"
|
|
26
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
[](https://badge.fury.io/py/pytest-remaster)
|
|
30
|
+
[](https://pypi.org/project/pytest-remaster/)
|
|
31
|
+
[](https://pypi.org/project/pytest-remaster/)
|
|
32
|
+
|
|
33
|
+
# pytest-remaster
|
|
34
|
+
|
|
35
|
+
Framework for golden master testing for pytest with automatic regeneration of the golden
|
|
36
|
+
master.
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
By default, golden master files are automatically regenerated when a comparison fails.
|
|
41
|
+
Use `--no-remaster` to get strict failures instead.
|
|
42
|
+
|
|
43
|
+
The default can be changed in `pyproject.toml`:
|
|
44
|
+
|
|
45
|
+
```toml
|
|
46
|
+
[tool.pytest.ini_options]
|
|
47
|
+
remaster-by-default = false
|
|
48
|
+
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[](https://badge.fury.io/py/pytest-remaster)
|
|
2
|
+
[](https://pypi.org/project/pytest-remaster/)
|
|
3
|
+
[](https://pypi.org/project/pytest-remaster/)
|
|
4
|
+
|
|
5
|
+
# pytest-remaster
|
|
6
|
+
|
|
7
|
+
Framework for golden master testing for pytest with automatic regeneration of the golden
|
|
8
|
+
master.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
By default, golden master files are automatically regenerated when a comparison fails.
|
|
13
|
+
Use `--no-remaster` to get strict failures instead.
|
|
14
|
+
|
|
15
|
+
The default can be changed in `pyproject.toml`:
|
|
16
|
+
|
|
17
|
+
```toml
|
|
18
|
+
[tool.pytest.ini_options]
|
|
19
|
+
remaster-by-default = false
|
|
20
|
+
```
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
build-backend = "setuptools.build_meta"
|
|
3
|
+
requires = [ "setuptools>=77", "setuptools-scm>=8" ]
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pytest-remaster"
|
|
7
|
+
description = "Golden master testing for pytest with automatic regeneration."
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
license = "MIT"
|
|
10
|
+
authors = [ { name = "Pierre Sassoulas" } ]
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Development Status :: 3 - Alpha",
|
|
14
|
+
"Framework :: Pytest",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
17
|
+
"Programming Language :: Python :: 3.9",
|
|
18
|
+
"Programming Language :: Python :: 3.10",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Programming Language :: Python :: 3.14",
|
|
23
|
+
"Topic :: Software Development :: Testing",
|
|
24
|
+
]
|
|
25
|
+
dynamic = [ "version" ]
|
|
26
|
+
dependencies = [ "pytest>=7" ]
|
|
27
|
+
optional-dependencies.dev = [ "pre-commit", "pylint>4", "pytest-cov" ]
|
|
28
|
+
urls.Homepage = "https://github.com/Pierre-Sassoulas/pytest-remaster"
|
|
29
|
+
entry-points.pytest11.remaster = "pytest_remaster.plugin"
|
|
30
|
+
|
|
31
|
+
[tool.setuptools_scm]
|
|
32
|
+
|
|
33
|
+
[tool.pylint]
|
|
34
|
+
messages_control.disable = [
|
|
35
|
+
"magic-value-comparison",
|
|
36
|
+
"missing-docstring",
|
|
37
|
+
"duplicate-code",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[tool.pytest]
|
|
41
|
+
ini_options.testpaths = [ "tests" ]
|
|
42
|
+
ini_options.addopts = "--cov --cov-report=term-missing"
|
|
43
|
+
|
|
44
|
+
[tool.coverage]
|
|
45
|
+
run.source = [ "pytest_remaster" ]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Golden master testing for pytest with automatic regeneration."""
|
|
2
|
+
|
|
3
|
+
from pytest_remaster.core import ( # pragma: no cover
|
|
4
|
+
GoldenMaster,
|
|
5
|
+
discover_test_cases,
|
|
6
|
+
discover_test_files,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"GoldenMaster",
|
|
11
|
+
"discover_test_cases",
|
|
12
|
+
"discover_test_files",
|
|
13
|
+
] # pragma: no cover
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"""Core golden master comparison and discovery logic."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations # pragma: no cover
|
|
4
|
+
|
|
5
|
+
import difflib # pragma: no cover
|
|
6
|
+
import re # pragma: no cover
|
|
7
|
+
from collections.abc import Callable # pragma: no cover
|
|
8
|
+
from pathlib import Path # pragma: no cover
|
|
9
|
+
from typing import Any # pragma: no cover
|
|
10
|
+
|
|
11
|
+
import pytest # pragma: no cover
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class GoldenMaster: # pragma: no cover
|
|
15
|
+
"""Golden master comparison with optional auto-regeneration."""
|
|
16
|
+
|
|
17
|
+
def __init__(self, remaster: bool) -> None: # pragma: no cover
|
|
18
|
+
self._remaster = remaster
|
|
19
|
+
|
|
20
|
+
def check( # pragma: no cover
|
|
21
|
+
self,
|
|
22
|
+
actual: Any | Callable[[], Any],
|
|
23
|
+
expected_path: str | Path,
|
|
24
|
+
serializer: Callable[[Any], str] = str,
|
|
25
|
+
) -> None:
|
|
26
|
+
"""Compare actual output against an expected file.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
actual: The actual value, or a callable that produces it.
|
|
30
|
+
expected_path: Path to the expected output file.
|
|
31
|
+
serializer: Converts actual value to string. Default: str().
|
|
32
|
+
"""
|
|
33
|
+
expected_path = Path(expected_path)
|
|
34
|
+
if callable(actual) and not isinstance(actual, str):
|
|
35
|
+
actual = actual()
|
|
36
|
+
actual_str = serializer(actual).rstrip()
|
|
37
|
+
|
|
38
|
+
try:
|
|
39
|
+
expected_str = expected_path.read_text(encoding="utf-8").rstrip()
|
|
40
|
+
except FileNotFoundError:
|
|
41
|
+
expected_str = None
|
|
42
|
+
|
|
43
|
+
if expected_str is not None and actual_str == expected_str:
|
|
44
|
+
return
|
|
45
|
+
|
|
46
|
+
if self._remaster:
|
|
47
|
+
expected_path.parent.mkdir(parents=True, exist_ok=True)
|
|
48
|
+
expected_path.write_text(actual_str + "\n", encoding="utf-8")
|
|
49
|
+
action = "created" if expected_str is None else "updated"
|
|
50
|
+
pytest.fail(
|
|
51
|
+
f"Golden master {action} at {expected_path}, "
|
|
52
|
+
f"please review and relaunch.",
|
|
53
|
+
pytrace=False,
|
|
54
|
+
)
|
|
55
|
+
else:
|
|
56
|
+
if expected_str is None:
|
|
57
|
+
pytest.fail(
|
|
58
|
+
f"Expected file {expected_path} does not exist. "
|
|
59
|
+
f"Run with --remaster to create it.",
|
|
60
|
+
pytrace=False,
|
|
61
|
+
)
|
|
62
|
+
diff = difflib.unified_diff(
|
|
63
|
+
expected_str.splitlines(keepends=True),
|
|
64
|
+
actual_str.splitlines(keepends=True),
|
|
65
|
+
fromfile=str(expected_path),
|
|
66
|
+
tofile="actual",
|
|
67
|
+
)
|
|
68
|
+
pytest.fail(
|
|
69
|
+
f"Golden master mismatch at {expected_path}:\n{''.join(diff)}",
|
|
70
|
+
pytrace=False,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
def check_all( # pragma: no cover
|
|
74
|
+
self,
|
|
75
|
+
*actuals: Any | Callable[[], list[Any]],
|
|
76
|
+
directory: str | Path,
|
|
77
|
+
serializer: Callable[[Any], str] = str,
|
|
78
|
+
) -> None:
|
|
79
|
+
"""Compare multiple actuals against result_0, result_1, ... files.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
*actuals: Values to compare, or a single callable returning a list.
|
|
83
|
+
directory: Directory containing result_N files.
|
|
84
|
+
serializer: Converts each value to string. Default: str().
|
|
85
|
+
"""
|
|
86
|
+
directory = Path(directory)
|
|
87
|
+
|
|
88
|
+
if (
|
|
89
|
+
len(actuals) == 1
|
|
90
|
+
and callable(actuals[0])
|
|
91
|
+
and not isinstance(actuals[0], str)
|
|
92
|
+
):
|
|
93
|
+
actuals = tuple(actuals[0]())
|
|
94
|
+
|
|
95
|
+
existing = sorted(
|
|
96
|
+
(p for p in directory.iterdir() if re.match(r"result_\d+$", p.name)),
|
|
97
|
+
key=lambda p: int(p.name.split("_")[1]),
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
if self._remaster and len(actuals) != len(existing):
|
|
101
|
+
for extra in existing[len(actuals) :]:
|
|
102
|
+
extra.unlink()
|
|
103
|
+
|
|
104
|
+
for i, actual in enumerate(actuals):
|
|
105
|
+
self.check(actual, directory / f"result_{i}", serializer=serializer)
|
|
106
|
+
|
|
107
|
+
if not self._remaster and len(actuals) < len(existing):
|
|
108
|
+
extra_files = [p.name for p in existing[len(actuals) :]]
|
|
109
|
+
pytest.fail(
|
|
110
|
+
f"Expected {len(existing)} results but got {len(actuals)}. "
|
|
111
|
+
f"Extra files: {extra_files}. Run with --remaster to clean up.",
|
|
112
|
+
pytrace=False,
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def discover_test_cases(base_dir: str | Path) -> list[Path]: # pragma: no cover
|
|
117
|
+
"""Find leaf directories (containing only files) under base_dir.
|
|
118
|
+
|
|
119
|
+
Suitable for use with ``@pytest.mark.parametrize``.
|
|
120
|
+
Returns absolute paths sorted alphabetically.
|
|
121
|
+
"""
|
|
122
|
+
base_dir = Path(base_dir)
|
|
123
|
+
result: list[Path] = []
|
|
124
|
+
for entry in sorted(base_dir.iterdir()):
|
|
125
|
+
if not entry.is_dir(): # pragma: no cover
|
|
126
|
+
continue
|
|
127
|
+
if all(f.is_file() for f in entry.iterdir()):
|
|
128
|
+
result.append(entry)
|
|
129
|
+
else:
|
|
130
|
+
result.extend(discover_test_cases(entry))
|
|
131
|
+
return result
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def discover_test_files(
|
|
135
|
+
base_dir: str | Path, pattern: str = "*.py"
|
|
136
|
+
) -> list[Path]: # pragma: no cover
|
|
137
|
+
"""Find files matching a glob pattern under base_dir.
|
|
138
|
+
|
|
139
|
+
Suitable for use with ``@pytest.mark.parametrize``.
|
|
140
|
+
Returns absolute paths sorted alphabetically.
|
|
141
|
+
"""
|
|
142
|
+
base_dir = Path(base_dir)
|
|
143
|
+
return sorted(base_dir.rglob(pattern))
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""Pytest plugin for golden master testing with automatic regeneration."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations # pragma: no cover
|
|
4
|
+
|
|
5
|
+
from typing import TYPE_CHECKING # pragma: no cover
|
|
6
|
+
|
|
7
|
+
import pytest # pragma: no cover
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING: # pragma: no cover
|
|
10
|
+
from pytest_remaster.core import GoldenMaster
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def pytest_addoption(parser: pytest.Parser) -> None: # pragma: no cover
|
|
14
|
+
group = parser.getgroup(
|
|
15
|
+
"remaster", "Golden master testing with automatic regeneration"
|
|
16
|
+
)
|
|
17
|
+
group.addoption(
|
|
18
|
+
"--remaster",
|
|
19
|
+
action="store_true",
|
|
20
|
+
dest="remaster",
|
|
21
|
+
default=None,
|
|
22
|
+
help="Regenerate golden master files when comparison fails.",
|
|
23
|
+
)
|
|
24
|
+
group.addoption(
|
|
25
|
+
"--no-remaster",
|
|
26
|
+
action="store_false",
|
|
27
|
+
dest="remaster",
|
|
28
|
+
help="Compare against golden master files without regenerating.",
|
|
29
|
+
)
|
|
30
|
+
parser.addini(
|
|
31
|
+
"remaster-by-default",
|
|
32
|
+
type="bool",
|
|
33
|
+
default=True,
|
|
34
|
+
help="Whether to regenerate golden master files by default (default: True).",
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@pytest.fixture # pragma: no cover
|
|
39
|
+
def remaster(request: pytest.FixtureRequest) -> bool: # pragma: no cover
|
|
40
|
+
"""Whether tests should regenerate golden master files."""
|
|
41
|
+
if (cli := request.config.getoption("remaster")) is not None:
|
|
42
|
+
return bool(cli)
|
|
43
|
+
result: bool = request.config.getini("remaster-by-default")
|
|
44
|
+
return result
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@pytest.fixture # pragma: no cover
|
|
48
|
+
def golden_master(
|
|
49
|
+
remaster: bool, # pylint: disable=redefined-outer-name
|
|
50
|
+
) -> GoldenMaster: # pragma: no cover
|
|
51
|
+
"""Golden master comparison fixture."""
|
|
52
|
+
from pytest_remaster.core import GoldenMaster # pylint: disable=import-outside-toplevel
|
|
53
|
+
|
|
54
|
+
return GoldenMaster(remaster=remaster)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pytest-remaster
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: Golden master testing for pytest with automatic regeneration.
|
|
5
|
+
Author: Pierre Sassoulas
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Pierre-Sassoulas/pytest-remaster
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Framework :: Pytest
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Topic :: Software Development :: Testing
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: pytest>=7
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pre-commit; extra == "dev"
|
|
25
|
+
Requires-Dist: pylint>4; extra == "dev"
|
|
26
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
[](https://badge.fury.io/py/pytest-remaster)
|
|
30
|
+
[](https://pypi.org/project/pytest-remaster/)
|
|
31
|
+
[](https://pypi.org/project/pytest-remaster/)
|
|
32
|
+
|
|
33
|
+
# pytest-remaster
|
|
34
|
+
|
|
35
|
+
Framework for golden master testing for pytest with automatic regeneration of the golden
|
|
36
|
+
master.
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
By default, golden master files are automatically regenerated when a comparison fails.
|
|
41
|
+
Use `--no-remaster` to get strict failures instead.
|
|
42
|
+
|
|
43
|
+
The default can be changed in `pyproject.toml`:
|
|
44
|
+
|
|
45
|
+
```toml
|
|
46
|
+
[tool.pytest.ini_options]
|
|
47
|
+
remaster-by-default = false
|
|
48
|
+
```
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
.gitignore
|
|
2
|
+
.pre-commit-config.yaml
|
|
3
|
+
LICENSE
|
|
4
|
+
README.md
|
|
5
|
+
pyproject.toml
|
|
6
|
+
.github/FUNDING.yml
|
|
7
|
+
.github/SECURITY.md
|
|
8
|
+
.github/dependabot.yml
|
|
9
|
+
.github/workflows/ci.yaml
|
|
10
|
+
.github/workflows/release.yaml
|
|
11
|
+
src/pytest_remaster/__init__.py
|
|
12
|
+
src/pytest_remaster/core.py
|
|
13
|
+
src/pytest_remaster/plugin.py
|
|
14
|
+
src/pytest_remaster.egg-info/PKG-INFO
|
|
15
|
+
src/pytest_remaster.egg-info/SOURCES.txt
|
|
16
|
+
src/pytest_remaster.egg-info/dependency_links.txt
|
|
17
|
+
src/pytest_remaster.egg-info/entry_points.txt
|
|
18
|
+
src/pytest_remaster.egg-info/requires.txt
|
|
19
|
+
src/pytest_remaster.egg-info/top_level.txt
|
|
20
|
+
tests/__init__.py
|
|
21
|
+
tests/conftest.py
|
|
22
|
+
tests/test_core.py
|
|
23
|
+
tests/test_plugin.py
|
|
24
|
+
tests/demo/__init__.py
|
|
25
|
+
tests/demo/chatbot.py
|
|
26
|
+
tests/demo/test_chatbot.py
|
|
27
|
+
tests/demo/cases/greet/goodbye/command
|
|
28
|
+
tests/demo/cases/greet/goodbye/result_0
|
|
29
|
+
tests/demo/cases/greet/goodbye/result_1
|
|
30
|
+
tests/demo/cases/greet/hello/command
|
|
31
|
+
tests/demo/cases/greet/hello/result_0
|
|
32
|
+
tests/demo/cases/help/unknown-command/command
|
|
33
|
+
tests/demo/cases/help/unknown-command/result_0
|
|
34
|
+
tests/demo/cases/help/unknown-command/result_1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pytest_remaster
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pytest_plugins = ["pytester"]
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
goodbye Bob
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[#general] :wave: Goodbye, Bob!
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[#general] :door: Bob has left the chat.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hello Alice
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[#general] :wave: Hello, Alice!
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
xyzzy
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[#errors] :x: Unknown command: xyzzy
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[#general] :info: Available commands: hello, goodbye
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""Fake Slack-like chatbot for demonstrating pytest-remaster."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass
|
|
9
|
+
class ChatMessage:
|
|
10
|
+
channel: str
|
|
11
|
+
text: str
|
|
12
|
+
emoji: str | None = None
|
|
13
|
+
|
|
14
|
+
def __str__(self) -> str:
|
|
15
|
+
prefix = f"{self.emoji} " if self.emoji else ""
|
|
16
|
+
return f"[{self.channel}] {prefix}{self.text}"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def handle_command(command: str) -> list[ChatMessage]:
|
|
20
|
+
"""Process a chat command and return response messages."""
|
|
21
|
+
parts = command.split(maxsplit=1)
|
|
22
|
+
verb = parts[0] if parts else ""
|
|
23
|
+
arg = parts[1] if len(parts) > 1 else ""
|
|
24
|
+
|
|
25
|
+
if verb == "hello":
|
|
26
|
+
return [
|
|
27
|
+
ChatMessage(channel="#general", text=f"Hello, {arg}!", emoji=":wave:"),
|
|
28
|
+
]
|
|
29
|
+
if verb == "goodbye":
|
|
30
|
+
return [
|
|
31
|
+
ChatMessage(channel="#general", text=f"Goodbye, {arg}!", emoji=":wave:"),
|
|
32
|
+
ChatMessage(
|
|
33
|
+
channel="#general", text=f"{arg} has left the chat.", emoji=":door:"
|
|
34
|
+
),
|
|
35
|
+
]
|
|
36
|
+
return [
|
|
37
|
+
ChatMessage(channel="#errors", text=f"Unknown command: {verb}", emoji=":x:"),
|
|
38
|
+
ChatMessage(
|
|
39
|
+
channel="#general",
|
|
40
|
+
text="Available commands: hello, goodbye",
|
|
41
|
+
emoji=":info:",
|
|
42
|
+
),
|
|
43
|
+
]
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Demo test showing pytest-remaster with a fake chatbot."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
from pytest_remaster import GoldenMaster, discover_test_cases
|
|
10
|
+
from tests.demo.chatbot import handle_command
|
|
11
|
+
|
|
12
|
+
CASES_DIR = Path(__file__).parent / "cases"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@pytest.mark.parametrize(
|
|
16
|
+
"case",
|
|
17
|
+
discover_test_cases(CASES_DIR),
|
|
18
|
+
ids=[str(d.relative_to(CASES_DIR)) for d in discover_test_cases(CASES_DIR)],
|
|
19
|
+
)
|
|
20
|
+
def test_chatbot_response(case: Path, golden_master: GoldenMaster) -> None:
|
|
21
|
+
cmd = (case / "command").read_text().strip()
|
|
22
|
+
golden_master.check_all(lambda: handle_command(cmd), directory=case)
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"""Tests for the core golden master logic."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def test_check_match(pytester: pytest.Pytester) -> None:
|
|
9
|
+
"""check() passes when actual matches expected."""
|
|
10
|
+
pytester.makepyfile(
|
|
11
|
+
"""
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
def test_match(golden_master, tmp_path):
|
|
15
|
+
expected = tmp_path / "expected.txt"
|
|
16
|
+
expected.write_text("hello world\\n")
|
|
17
|
+
golden_master.check("hello world", expected)
|
|
18
|
+
"""
|
|
19
|
+
)
|
|
20
|
+
result = pytester.runpytest("--no-remaster")
|
|
21
|
+
result.assert_outcomes(passed=1)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_check_mismatch_remaster(pytester: pytest.Pytester) -> None:
|
|
25
|
+
"""check() with remaster writes new content and fails."""
|
|
26
|
+
pytester.makepyfile(
|
|
27
|
+
"""
|
|
28
|
+
from pathlib import Path
|
|
29
|
+
|
|
30
|
+
def test_mismatch(golden_master, tmp_path):
|
|
31
|
+
expected = tmp_path / "expected.txt"
|
|
32
|
+
expected.write_text("old content\\n")
|
|
33
|
+
golden_master.check("new content", expected)
|
|
34
|
+
"""
|
|
35
|
+
)
|
|
36
|
+
result = pytester.runpytest("--remaster")
|
|
37
|
+
result.assert_outcomes(failed=1)
|
|
38
|
+
result.stdout.fnmatch_lines(["*updated*review and relaunch*"])
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_check_mismatch_no_remaster(pytester: pytest.Pytester) -> None:
|
|
42
|
+
"""check() without remaster fails with diff."""
|
|
43
|
+
pytester.makepyfile(
|
|
44
|
+
"""
|
|
45
|
+
from pathlib import Path
|
|
46
|
+
|
|
47
|
+
def test_mismatch(golden_master, tmp_path):
|
|
48
|
+
expected = tmp_path / "expected.txt"
|
|
49
|
+
expected.write_text("old content\\n")
|
|
50
|
+
golden_master.check("new content", expected)
|
|
51
|
+
"""
|
|
52
|
+
)
|
|
53
|
+
result = pytester.runpytest("--no-remaster")
|
|
54
|
+
result.assert_outcomes(failed=1)
|
|
55
|
+
result.stdout.fnmatch_lines(["*mismatch*"])
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def test_check_missing_file_remaster(pytester: pytest.Pytester) -> None:
|
|
59
|
+
"""check() with remaster creates missing file and fails."""
|
|
60
|
+
pytester.makepyfile(
|
|
61
|
+
"""
|
|
62
|
+
from pathlib import Path
|
|
63
|
+
|
|
64
|
+
def test_missing(golden_master, tmp_path):
|
|
65
|
+
expected = tmp_path / "expected.txt"
|
|
66
|
+
golden_master.check("new content", expected)
|
|
67
|
+
"""
|
|
68
|
+
)
|
|
69
|
+
result = pytester.runpytest("--remaster")
|
|
70
|
+
result.assert_outcomes(failed=1)
|
|
71
|
+
result.stdout.fnmatch_lines(["*created*review and relaunch*"])
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def test_check_missing_file_no_remaster(pytester: pytest.Pytester) -> None:
|
|
75
|
+
"""check() without remaster fails when file missing."""
|
|
76
|
+
pytester.makepyfile(
|
|
77
|
+
"""
|
|
78
|
+
from pathlib import Path
|
|
79
|
+
|
|
80
|
+
def test_missing(golden_master, tmp_path):
|
|
81
|
+
expected = tmp_path / "expected.txt"
|
|
82
|
+
golden_master.check("new content", expected)
|
|
83
|
+
"""
|
|
84
|
+
)
|
|
85
|
+
result = pytester.runpytest("--no-remaster")
|
|
86
|
+
result.assert_outcomes(failed=1)
|
|
87
|
+
result.stdout.fnmatch_lines(["*does not exist*--remaster*"])
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def test_check_callable(pytester: pytest.Pytester) -> None:
|
|
91
|
+
"""check() accepts a callable and calls it."""
|
|
92
|
+
pytester.makepyfile(
|
|
93
|
+
"""
|
|
94
|
+
from pathlib import Path
|
|
95
|
+
|
|
96
|
+
def test_callable(golden_master, tmp_path):
|
|
97
|
+
expected = tmp_path / "expected.txt"
|
|
98
|
+
expected.write_text("hello\\n")
|
|
99
|
+
golden_master.check(lambda: "hello", expected)
|
|
100
|
+
"""
|
|
101
|
+
)
|
|
102
|
+
result = pytester.runpytest("--no-remaster")
|
|
103
|
+
result.assert_outcomes(passed=1)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def test_check_serializer(pytester: pytest.Pytester) -> None:
|
|
107
|
+
"""check() uses custom serializer."""
|
|
108
|
+
pytester.makepyfile(
|
|
109
|
+
"""
|
|
110
|
+
import json
|
|
111
|
+
from pathlib import Path
|
|
112
|
+
|
|
113
|
+
def test_serializer(golden_master, tmp_path):
|
|
114
|
+
expected = tmp_path / "expected.json"
|
|
115
|
+
expected.write_text('{"key": "value"}\\n')
|
|
116
|
+
golden_master.check(
|
|
117
|
+
{"key": "value"}, expected,
|
|
118
|
+
serializer=lambda o: json.dumps(o, sort_keys=True),
|
|
119
|
+
)
|
|
120
|
+
"""
|
|
121
|
+
)
|
|
122
|
+
result = pytester.runpytest("--no-remaster")
|
|
123
|
+
result.assert_outcomes(passed=1)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def test_check_all_match(pytester: pytest.Pytester) -> None:
|
|
127
|
+
"""check_all() passes when all results match."""
|
|
128
|
+
pytester.makepyfile(
|
|
129
|
+
"""
|
|
130
|
+
from pathlib import Path
|
|
131
|
+
|
|
132
|
+
def test_match(golden_master, tmp_path):
|
|
133
|
+
(tmp_path / "result_0").write_text("first\\n")
|
|
134
|
+
(tmp_path / "result_1").write_text("second\\n")
|
|
135
|
+
golden_master.check_all("first", "second", directory=tmp_path)
|
|
136
|
+
"""
|
|
137
|
+
)
|
|
138
|
+
result = pytester.runpytest("--no-remaster")
|
|
139
|
+
result.assert_outcomes(passed=1)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def test_check_all_callable(pytester: pytest.Pytester) -> None:
|
|
143
|
+
"""check_all() accepts a callable returning a list."""
|
|
144
|
+
pytester.makepyfile(
|
|
145
|
+
"""
|
|
146
|
+
from pathlib import Path
|
|
147
|
+
|
|
148
|
+
def test_callable(golden_master, tmp_path):
|
|
149
|
+
(tmp_path / "result_0").write_text("a\\n")
|
|
150
|
+
(tmp_path / "result_1").write_text("b\\n")
|
|
151
|
+
golden_master.check_all(lambda: ["a", "b"], directory=tmp_path)
|
|
152
|
+
"""
|
|
153
|
+
)
|
|
154
|
+
result = pytester.runpytest("--no-remaster")
|
|
155
|
+
result.assert_outcomes(passed=1)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def test_check_all_fewer_actuals_remaster(pytester: pytest.Pytester) -> None:
|
|
159
|
+
"""check_all() with remaster removes extra result files."""
|
|
160
|
+
pytester.makepyfile(
|
|
161
|
+
"""
|
|
162
|
+
from pathlib import Path
|
|
163
|
+
|
|
164
|
+
def test_fewer(golden_master, tmp_path):
|
|
165
|
+
(tmp_path / "result_0").write_text("only\\n")
|
|
166
|
+
(tmp_path / "result_1").write_text("extra\\n")
|
|
167
|
+
golden_master.check_all("only", directory=tmp_path)
|
|
168
|
+
"""
|
|
169
|
+
)
|
|
170
|
+
result = pytester.runpytest("--remaster")
|
|
171
|
+
# result_1 is removed, result_0 matches so no update needed
|
|
172
|
+
result.assert_outcomes(passed=1)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def test_check_all_more_actuals_remaster(pytester: pytest.Pytester) -> None:
|
|
176
|
+
"""check_all() with remaster creates new result files."""
|
|
177
|
+
pytester.makepyfile(
|
|
178
|
+
"""
|
|
179
|
+
from pathlib import Path
|
|
180
|
+
|
|
181
|
+
def test_more(golden_master, tmp_path):
|
|
182
|
+
(tmp_path / "result_0").write_text("first\\n")
|
|
183
|
+
golden_master.check_all("first", "second", directory=tmp_path)
|
|
184
|
+
"""
|
|
185
|
+
)
|
|
186
|
+
result = pytester.runpytest("--remaster")
|
|
187
|
+
result.assert_outcomes(failed=1)
|
|
188
|
+
result.stdout.fnmatch_lines(["*created*"])
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def test_check_all_count_mismatch_no_remaster(pytester: pytest.Pytester) -> None:
|
|
192
|
+
"""check_all() without remaster fails on count mismatch."""
|
|
193
|
+
pytester.makepyfile(
|
|
194
|
+
"""
|
|
195
|
+
from pathlib import Path
|
|
196
|
+
|
|
197
|
+
def test_count(golden_master, tmp_path):
|
|
198
|
+
(tmp_path / "result_0").write_text("first\\n")
|
|
199
|
+
(tmp_path / "result_1").write_text("second\\n")
|
|
200
|
+
(tmp_path / "result_2").write_text("third\\n")
|
|
201
|
+
golden_master.check_all("first", directory=tmp_path)
|
|
202
|
+
"""
|
|
203
|
+
)
|
|
204
|
+
result = pytester.runpytest("--no-remaster")
|
|
205
|
+
result.assert_outcomes(failed=1)
|
|
206
|
+
result.stdout.fnmatch_lines(["*Expected 3 results but got 1*"])
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def test_discover_test_cases(pytester: pytest.Pytester) -> None:
|
|
210
|
+
"""discover_test_cases() finds leaf directories."""
|
|
211
|
+
pytester.makepyfile(
|
|
212
|
+
"""
|
|
213
|
+
from pathlib import Path
|
|
214
|
+
from pytest_remaster import discover_test_cases
|
|
215
|
+
|
|
216
|
+
def test_discover(tmp_path):
|
|
217
|
+
# Create hierarchy: base/a/case1/ and base/a/case2/ and base/b/
|
|
218
|
+
(tmp_path / "a" / "case1").mkdir(parents=True)
|
|
219
|
+
(tmp_path / "a" / "case1" / "command").write_text("hello")
|
|
220
|
+
(tmp_path / "a" / "case2").mkdir(parents=True)
|
|
221
|
+
(tmp_path / "a" / "case2" / "command").write_text("bye")
|
|
222
|
+
(tmp_path / "b").mkdir()
|
|
223
|
+
(tmp_path / "b" / "command").write_text("help")
|
|
224
|
+
|
|
225
|
+
cases = discover_test_cases(tmp_path)
|
|
226
|
+
names = [c.name for c in cases]
|
|
227
|
+
assert sorted(names) == ["b", "case1", "case2"]
|
|
228
|
+
"""
|
|
229
|
+
)
|
|
230
|
+
result = pytester.runpytest()
|
|
231
|
+
result.assert_outcomes(passed=1)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def test_discover_test_files(pytester: pytest.Pytester) -> None:
|
|
235
|
+
"""discover_test_files() finds files matching a pattern."""
|
|
236
|
+
pytester.makepyfile(
|
|
237
|
+
"""
|
|
238
|
+
from pathlib import Path
|
|
239
|
+
from pytest_remaster import discover_test_files
|
|
240
|
+
|
|
241
|
+
def test_discover(tmp_path):
|
|
242
|
+
(tmp_path / "a.py").write_text("pass")
|
|
243
|
+
(tmp_path / "b.txt").write_text("hello")
|
|
244
|
+
(tmp_path / "sub").mkdir()
|
|
245
|
+
(tmp_path / "sub" / "c.py").write_text("pass")
|
|
246
|
+
|
|
247
|
+
py_files = discover_test_files(tmp_path, "*.py")
|
|
248
|
+
names = [f.name for f in py_files]
|
|
249
|
+
assert sorted(names) == ["a.py", "c.py"]
|
|
250
|
+
"""
|
|
251
|
+
)
|
|
252
|
+
result = pytester.runpytest()
|
|
253
|
+
result.assert_outcomes(passed=1)
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""Basic tests for the pytest-remaster plugin."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def test_remaster_option_default(pytester: pytest.Pytester) -> None:
|
|
9
|
+
"""The --remaster CLI option defaults to None (falls back to ini)."""
|
|
10
|
+
pytester.makepyfile(
|
|
11
|
+
"""
|
|
12
|
+
def test_default(pytestconfig):
|
|
13
|
+
assert pytestconfig.getoption("remaster") is None
|
|
14
|
+
"""
|
|
15
|
+
)
|
|
16
|
+
result = pytester.runpytest()
|
|
17
|
+
result.assert_outcomes(passed=1)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_remaster_ini_default(pytester: pytest.Pytester) -> None:
|
|
21
|
+
"""The remaster-by-default ini option defaults to True."""
|
|
22
|
+
pytester.makepyfile(
|
|
23
|
+
"""
|
|
24
|
+
def test_ini(pytestconfig):
|
|
25
|
+
assert pytestconfig.getini("remaster-by-default") is True
|
|
26
|
+
"""
|
|
27
|
+
)
|
|
28
|
+
result = pytester.runpytest()
|
|
29
|
+
result.assert_outcomes(passed=1)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_remaster_flag_enables(pytester: pytest.Pytester) -> None:
|
|
33
|
+
"""Passing --remaster sets the option to True."""
|
|
34
|
+
pytester.makepyfile(
|
|
35
|
+
"""
|
|
36
|
+
def test_flag(pytestconfig):
|
|
37
|
+
assert pytestconfig.getoption("remaster") is True
|
|
38
|
+
"""
|
|
39
|
+
)
|
|
40
|
+
result = pytester.runpytest("--remaster")
|
|
41
|
+
result.assert_outcomes(passed=1)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_no_remaster_flag_disables(pytester: pytest.Pytester) -> None:
|
|
45
|
+
"""Passing --no-remaster sets the option to False."""
|
|
46
|
+
pytester.makepyfile(
|
|
47
|
+
"""
|
|
48
|
+
def test_flag(pytestconfig):
|
|
49
|
+
assert pytestconfig.getoption("remaster") is False
|
|
50
|
+
"""
|
|
51
|
+
)
|
|
52
|
+
result = pytester.runpytest("--no-remaster")
|
|
53
|
+
result.assert_outcomes(passed=1)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def test_remaster_fixture(pytester: pytest.Pytester) -> None:
|
|
57
|
+
"""The remaster fixture resolves CLI > ini correctly."""
|
|
58
|
+
pytester.makepyfile(
|
|
59
|
+
"""
|
|
60
|
+
def test_fixture_default(remaster):
|
|
61
|
+
assert remaster is True
|
|
62
|
+
"""
|
|
63
|
+
)
|
|
64
|
+
result = pytester.runpytest()
|
|
65
|
+
result.assert_outcomes(passed=1)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_remaster_fixture_no_remaster(pytester: pytest.Pytester) -> None:
|
|
69
|
+
"""The remaster fixture returns False with --no-remaster."""
|
|
70
|
+
pytester.makepyfile(
|
|
71
|
+
"""
|
|
72
|
+
def test_fixture_off(remaster):
|
|
73
|
+
assert remaster is False
|
|
74
|
+
"""
|
|
75
|
+
)
|
|
76
|
+
result = pytester.runpytest("--no-remaster")
|
|
77
|
+
result.assert_outcomes(passed=1)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def test_remaster_ini_override(pytester: pytest.Pytester) -> None:
|
|
81
|
+
"""Setting remaster-by-default=false in ini changes the default."""
|
|
82
|
+
pytester.makeini(
|
|
83
|
+
"""
|
|
84
|
+
[pytest]
|
|
85
|
+
remaster-by-default = false
|
|
86
|
+
"""
|
|
87
|
+
)
|
|
88
|
+
pytester.makepyfile(
|
|
89
|
+
"""
|
|
90
|
+
def test_fixture_ini_false(remaster):
|
|
91
|
+
assert remaster is False
|
|
92
|
+
"""
|
|
93
|
+
)
|
|
94
|
+
result = pytester.runpytest()
|
|
95
|
+
result.assert_outcomes(passed=1)
|