pytest-ditto-pickle 2.0.0b1__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_ditto_pickle-2.0.0b1/.gitignore +49 -0
- pytest_ditto_pickle-2.0.0b1/LICENSE +21 -0
- pytest_ditto_pickle-2.0.0b1/PKG-INFO +74 -0
- pytest_ditto_pickle-2.0.0b1/README.md +47 -0
- pytest_ditto_pickle-2.0.0b1/hatch_build.py +30 -0
- pytest_ditto_pickle-2.0.0b1/pyproject.toml +69 -0
- pytest_ditto_pickle-2.0.0b1/src/ditto_pickle/__init__.py +0 -0
- pytest_ditto_pickle-2.0.0b1/src/ditto_pickle/recorders.py +28 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# tests/ci/.ditto and the root ditto.lock are pytest-ditto's own committed,
|
|
2
|
+
# PR-reviewed baseline (see docs/src/guides/lock-file.md), and each first-party
|
|
3
|
+
# plugin has its own under plugins/<name>/ — everywhere else .ditto/ditto.lock
|
|
4
|
+
# are ephemeral local test-run artifacts.
|
|
5
|
+
.ditto
|
|
6
|
+
!/tests/ci/.ditto/
|
|
7
|
+
!/plugins/*/tests/ci/.ditto/
|
|
8
|
+
ditto.lock
|
|
9
|
+
!/ditto.lock
|
|
10
|
+
!/plugins/*/ditto.lock
|
|
11
|
+
.tmp/
|
|
12
|
+
tmp.py
|
|
13
|
+
ditto-tui.html
|
|
14
|
+
|
|
15
|
+
# Python
|
|
16
|
+
__pycache__
|
|
17
|
+
# Written by the hatch-vcs build hook on every build and editable install.
|
|
18
|
+
src/ditto/_version.py
|
|
19
|
+
*.egg-info
|
|
20
|
+
*.pyc
|
|
21
|
+
|
|
22
|
+
# Testing
|
|
23
|
+
.pytest_cache
|
|
24
|
+
.pytest
|
|
25
|
+
.coverage
|
|
26
|
+
.hypothesis
|
|
27
|
+
|
|
28
|
+
# Linting
|
|
29
|
+
.ruff_cache
|
|
30
|
+
|
|
31
|
+
# IDE
|
|
32
|
+
.idea/
|
|
33
|
+
.vscode/
|
|
34
|
+
.claude/
|
|
35
|
+
|
|
36
|
+
# Build artifacts
|
|
37
|
+
dist/
|
|
38
|
+
archive/
|
|
39
|
+
docs/site/
|
|
40
|
+
|
|
41
|
+
# pixi environments
|
|
42
|
+
.pixi/*
|
|
43
|
+
!.pixi/config.toml
|
|
44
|
+
|
|
45
|
+
# Dev
|
|
46
|
+
.designs/
|
|
47
|
+
.issues/
|
|
48
|
+
.impl/
|
|
49
|
+
/tests/release/synthetic_plugin/build/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 pytest-ditto
|
|
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,74 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pytest-ditto-pickle
|
|
3
|
+
Version: 2.0.0b1
|
|
4
|
+
Summary: pytest-ditto plugin for pickle snapshots.
|
|
5
|
+
Project-URL: Homepage, https://github.com/owlowlyowl/pytest-ditto
|
|
6
|
+
Project-URL: Source, https://github.com/owlowlyowl/pytest-ditto/tree/main/plugins/pickle
|
|
7
|
+
Author-email: Lachlan Taylor <95459213+owlowlyowl@users.noreply.github.com>
|
|
8
|
+
Maintainer-email: Lachlan Taylor <95459213+owlowlyowl@users.noreply.github.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: pickle,pytest,snapshot,testing
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Framework :: Pytest
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Topic :: Software Development :: Testing
|
|
24
|
+
Requires-Python: >=3.12
|
|
25
|
+
Requires-Dist: pytest-ditto<3,>=2.0.0b1
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# pytest-ditto-pickle
|
|
29
|
+
|
|
30
|
+
Extension plugin for [`pytest-ditto`](https://github.com/owlowlyowl/pytest-ditto) that records snapshots with Python's `pickle`.
|
|
31
|
+
|
|
32
|
+
> [!WARNING]
|
|
33
|
+
> Loading pickle data can execute arbitrary code. Only load snapshots you
|
|
34
|
+
> trust, and never load a `.pkl` snapshot from an untrusted source, such as a
|
|
35
|
+
> pull request from someone you don't know. Review changes to `.pkl` files as
|
|
36
|
+
> carefully as changes to code.
|
|
37
|
+
|
|
38
|
+
pytest-ditto records snapshots as strict JSON by default. Use pickle only when
|
|
39
|
+
a value can't be represented in JSON, or YAML, or one of the other recorders,
|
|
40
|
+
and you accept the risk above.
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
```bash
|
|
44
|
+
pip install pytest-ditto-pickle
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
pytest-ditto has no `pickle` extra: install this package by name, deliberately.
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
Select the recorder explicitly on each test, with `@ditto.pickle` or its
|
|
52
|
+
long form, `@ditto.record("pickle")`:
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
import datetime
|
|
56
|
+
|
|
57
|
+
import ditto
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@ditto.pickle
|
|
61
|
+
def test_schedule(snapshot):
|
|
62
|
+
schedule = {"days": {"mon", "wed"}, "start": datetime.time(9, 30)}
|
|
63
|
+
assert snapshot(schedule, key="schedule") == schedule
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Snapshots from pytest-ditto 1.x
|
|
67
|
+
|
|
68
|
+
pytest-ditto 1.x used pickle by default and saved snapshots with the `.pkl`
|
|
69
|
+
extension. This recorder keeps that extension and file format, so a 1.x
|
|
70
|
+
`.pkl` file loads unchanged.
|
|
71
|
+
|
|
72
|
+
pytest-ditto 2.0 names snapshot files differently, though, so 2.0 won't find a
|
|
73
|
+
1.x file where 1.x left it. See the pytest-ditto upgrade guide for the new
|
|
74
|
+
names.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# pytest-ditto-pickle
|
|
2
|
+
|
|
3
|
+
Extension plugin for [`pytest-ditto`](https://github.com/owlowlyowl/pytest-ditto) that records snapshots with Python's `pickle`.
|
|
4
|
+
|
|
5
|
+
> [!WARNING]
|
|
6
|
+
> Loading pickle data can execute arbitrary code. Only load snapshots you
|
|
7
|
+
> trust, and never load a `.pkl` snapshot from an untrusted source, such as a
|
|
8
|
+
> pull request from someone you don't know. Review changes to `.pkl` files as
|
|
9
|
+
> carefully as changes to code.
|
|
10
|
+
|
|
11
|
+
pytest-ditto records snapshots as strict JSON by default. Use pickle only when
|
|
12
|
+
a value can't be represented in JSON, or YAML, or one of the other recorders,
|
|
13
|
+
and you accept the risk above.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
```bash
|
|
17
|
+
pip install pytest-ditto-pickle
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
pytest-ditto has no `pickle` extra: install this package by name, deliberately.
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
Select the recorder explicitly on each test, with `@ditto.pickle` or its
|
|
25
|
+
long form, `@ditto.record("pickle")`:
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
import datetime
|
|
29
|
+
|
|
30
|
+
import ditto
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@ditto.pickle
|
|
34
|
+
def test_schedule(snapshot):
|
|
35
|
+
schedule = {"days": {"mon", "wed"}, "start": datetime.time(9, 30)}
|
|
36
|
+
assert snapshot(schedule, key="schedule") == schedule
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Snapshots from pytest-ditto 1.x
|
|
40
|
+
|
|
41
|
+
pytest-ditto 1.x used pickle by default and saved snapshots with the `.pkl`
|
|
42
|
+
extension. This recorder keeps that extension and file format, so a 1.x
|
|
43
|
+
`.pkl` file loads unchanged.
|
|
44
|
+
|
|
45
|
+
pytest-ditto 2.0 names snapshot files differently, though, so 2.0 won't find a
|
|
46
|
+
1.x file where 1.x left it. See the pytest-ditto upgrade guide for the new
|
|
47
|
+
names.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Add the plugin's requirement on pytest-ditto to its dependencies.
|
|
2
|
+
|
|
3
|
+
Plugins are released in lockstep with pytest-ditto, from the same git tag, so each
|
|
4
|
+
requires at least the core it was released with: plugin X.Y.Z requires
|
|
5
|
+
``pytest-ditto>=X.Y.Z,<3``. The local segment (``+sha`` on untagged commits) is
|
|
6
|
+
dropped because PEP 440 doesn't allow it in a ``>=`` specifier. ``<3`` is the plugin
|
|
7
|
+
contract's major version.
|
|
8
|
+
|
|
9
|
+
The plugin's other dependencies are listed under
|
|
10
|
+
``[tool.hatch.metadata.hooks.custom]`` in its ``pyproject.toml``. A wheel built from
|
|
11
|
+
the sdist takes all of them from ``PKG-INFO`` and doesn't run this hook.
|
|
12
|
+
|
|
13
|
+
Every plugin carries an identical copy of this file, so it ships in each sdist.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
from hatchling.metadata.plugin.interface import MetadataHookInterface
|
|
19
|
+
from packaging.version import Version
|
|
20
|
+
|
|
21
|
+
CORE_MAJOR = 2
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class CoreFloorHook(MetadataHookInterface):
|
|
25
|
+
def update(self, metadata: dict[str, Any]) -> None:
|
|
26
|
+
floor = Version(metadata["version"]).public
|
|
27
|
+
metadata["dependencies"] = [
|
|
28
|
+
f"pytest-ditto>={floor},<{CORE_MAJOR + 1}",
|
|
29
|
+
*self.config.get("dependencies", []),
|
|
30
|
+
]
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "pytest-ditto-pickle"
|
|
3
|
+
dynamic = ["version", "dependencies"]
|
|
4
|
+
description = "pytest-ditto plugin for pickle snapshots."
|
|
5
|
+
keywords = ["pytest", "testing", "pickle", "snapshot"]
|
|
6
|
+
authors = [{ name = "Lachlan Taylor", email = "95459213+owlowlyowl@users.noreply.github.com" }]
|
|
7
|
+
maintainers = [{ name = "Lachlan Taylor", email = "95459213+owlowlyowl@users.noreply.github.com" }]
|
|
8
|
+
requires-python = ">=3.12"
|
|
9
|
+
license = "MIT"
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Development Status :: 5 - Production/Stable",
|
|
13
|
+
"Framework :: Pytest",
|
|
14
|
+
"Intended Audience :: Developers",
|
|
15
|
+
"License :: OSI Approved :: MIT License",
|
|
16
|
+
"Topic :: Software Development :: Testing",
|
|
17
|
+
"Programming Language :: Python",
|
|
18
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Programming Language :: Python :: 3.14",
|
|
23
|
+
"Operating System :: OS Independent",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://github.com/owlowlyowl/pytest-ditto"
|
|
28
|
+
Source = "https://github.com/owlowlyowl/pytest-ditto/tree/main/plugins/pickle"
|
|
29
|
+
|
|
30
|
+
[project.entry-points.ditto_recorders]
|
|
31
|
+
# Named `pickle` (mark `ditto.pickle`) but persisted with identifier `pkl`,
|
|
32
|
+
# the extension pytest-ditto 1.x used, so 1.x .pkl files load unchanged.
|
|
33
|
+
pickle = "ditto_pickle.recorders:pickle"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
[build-system]
|
|
37
|
+
requires = ["hatchling"]
|
|
38
|
+
build-backend = "hatchling.build"
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
[tool.hatch.build]
|
|
42
|
+
targets.wheel.packages = ["src/ditto_pickle"]
|
|
43
|
+
targets.sdist.only-include = ["src", "README.md", "LICENSE", "hatch_build.py"]
|
|
44
|
+
|
|
45
|
+
# hatch_build.py adds pytest-ditto>=<this version>,<3 to these.
|
|
46
|
+
[tool.hatch.metadata.hooks.custom]
|
|
47
|
+
dependencies = []
|
|
48
|
+
|
|
49
|
+
# Versioned in lockstep with pytest-ditto, from the same git tag.
|
|
50
|
+
[tool.hatch.version]
|
|
51
|
+
source = "code"
|
|
52
|
+
path = "../../version_builder.py"
|
|
53
|
+
expression = "_version()"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
[tool.pytest.ini_options]
|
|
57
|
+
minversion = "8.3"
|
|
58
|
+
testpaths = "tests/ci"
|
|
59
|
+
addopts = [
|
|
60
|
+
"-lv",
|
|
61
|
+
"--tb=short",
|
|
62
|
+
"--color=yes",
|
|
63
|
+
"--code-highlight=yes",
|
|
64
|
+
"--junit-xml=.pytest/test-results.xml",
|
|
65
|
+
]
|
|
66
|
+
junit_family = "xunit2"
|
|
67
|
+
filterwarnings = [
|
|
68
|
+
"ignore::DeprecationWarning",
|
|
69
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""The pickle recorder.
|
|
2
|
+
|
|
3
|
+
Loading pickle data can execute arbitrary code. Only load snapshots you trust.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import pickle as _pickle
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from ditto.recorders import Recorder
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
__all__ = ("pickle",)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _save(data: Any, filepath: Path) -> None:
|
|
17
|
+
with open(filepath, "wb") as f:
|
|
18
|
+
_pickle.dump(data, f)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _load(filepath: Path) -> Any:
|
|
22
|
+
with open(filepath, "rb") as f:
|
|
23
|
+
return _pickle.load(f)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# The identifier is `pkl`, not the recorder's name, `pickle`: it is the file
|
|
27
|
+
# extension pytest-ditto 1.x used, so 1.x snapshots keep loading.
|
|
28
|
+
pickle: Recorder[Any] = Recorder(identifier="pkl", save=_save, load=_load)
|