pytest-ditto-pickle 2.0.0b1__py3-none-any.whl

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.
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)
@@ -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,7 @@
1
+ ditto_pickle/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ ditto_pickle/recorders.py,sha256=ELSAI3DdL0U-clZ5xyzAsEccMPDAx89J2hqslP2MHvc,681
3
+ pytest_ditto_pickle-2.0.0b1.dist-info/METADATA,sha256=JjKSyrFO-_ddk_HSj8UuAJiBrU_7iDovTWYksVdxZPw,2678
4
+ pytest_ditto_pickle-2.0.0b1.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
5
+ pytest_ditto_pickle-2.0.0b1.dist-info/entry_points.txt,sha256=fQvD1D-TFeLZwHRQJ636MZBTcoO7rm2CXTsqXi3-zuQ,57
6
+ pytest_ditto_pickle-2.0.0b1.dist-info/licenses/LICENSE,sha256=Dllo6ok5zVKUEUmEVqsGbGwBoDYtBpQY_e2mxW1qrvQ,1069
7
+ pytest_ditto_pickle-2.0.0b1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.4
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [ditto_recorders]
2
+ pickle = ditto_pickle.recorders:pickle
@@ -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.