pytest-approval 0.1.0__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.
- pytest_approval/__init__.py +30 -0
- pytest_approval/approver.toml +23 -0
- pytest_approval/compare.py +44 -0
- pytest_approval/config.py +32 -0
- pytest_approval/definitions.py +178 -0
- pytest_approval/empty_files/empty.7z +0 -0
- pytest_approval/empty_files/empty.7zip +0 -0
- pytest_approval/empty_files/empty.avif +0 -0
- pytest_approval/empty_files/empty.bmp +0 -0
- pytest_approval/empty_files/empty.bz2 +0 -0
- pytest_approval/empty_files/empty.bzip2 +0 -0
- pytest_approval/empty_files/empty.dds +0 -0
- pytest_approval/empty_files/empty.dib +0 -0
- pytest_approval/empty_files/empty.docx +0 -0
- pytest_approval/empty_files/empty.emf +0 -0
- pytest_approval/empty_files/empty.exif +0 -0
- pytest_approval/empty_files/empty.gif +0 -0
- pytest_approval/empty_files/empty.gz +0 -0
- pytest_approval/empty_files/empty.gzip +0 -0
- pytest_approval/empty_files/empty.heic +0 -0
- pytest_approval/empty_files/empty.heif +0 -0
- pytest_approval/empty_files/empty.ico +0 -0
- pytest_approval/empty_files/empty.j2c +0 -0
- pytest_approval/empty_files/empty.jfif +0 -0
- pytest_approval/empty_files/empty.jp2 +0 -0
- pytest_approval/empty_files/empty.jpc +0 -0
- pytest_approval/empty_files/empty.jpe +0 -0
- pytest_approval/empty_files/empty.jpeg +0 -0
- pytest_approval/empty_files/empty.jpg +0 -0
- pytest_approval/empty_files/empty.jxr +0 -0
- pytest_approval/empty_files/empty.nupkg +0 -0
- pytest_approval/empty_files/empty.odp +0 -0
- pytest_approval/empty_files/empty.ods +0 -0
- pytest_approval/empty_files/empty.odt +0 -0
- pytest_approval/empty_files/empty.pbm +3 -0
- pytest_approval/empty_files/empty.pcx +0 -0
- pytest_approval/empty_files/empty.pdf +12 -0
- pytest_approval/empty_files/empty.pgm +0 -0
- pytest_approval/empty_files/empty.png +0 -0
- pytest_approval/empty_files/empty.ppm +0 -0
- pytest_approval/empty_files/empty.pptx +0 -0
- pytest_approval/empty_files/empty.rle +0 -0
- pytest_approval/empty_files/empty.rtf +1 -0
- pytest_approval/empty_files/empty.tar +0 -0
- pytest_approval/empty_files/empty.tga +0 -0
- pytest_approval/empty_files/empty.tif +0 -0
- pytest_approval/empty_files/empty.tiff +0 -0
- pytest_approval/empty_files/empty.wdp +0 -0
- pytest_approval/empty_files/empty.webp +0 -0
- pytest_approval/empty_files/empty.wmp +0 -0
- pytest_approval/empty_files/empty.xlsx +0 -0
- pytest_approval/empty_files/empty.xz +0 -0
- pytest_approval/empty_files/empty.zip +0 -0
- pytest_approval/main.py +266 -0
- pytest_approval/plugin.py +24 -0
- pytest_approval/reporters.toml +14 -0
- pytest_approval/utils.py +22 -0
- pytest_approval-0.1.0.dist-info/METADATA +241 -0
- pytest_approval-0.1.0.dist-info/RECORD +63 -0
- pytest_approval-0.1.0.dist-info/WHEEL +4 -0
- pytest_approval-0.1.0.dist-info/entry_points.txt +3 -0
- pytest_approval-0.1.0.dist-info/licenses/COPYING +674 -0
- pytest_approval-0.1.0.dist-info/licenses/COPYING.LESSER +165 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
try:
|
|
2
|
+
from pytest_approval.main import (
|
|
3
|
+
verify,
|
|
4
|
+
verify_binary,
|
|
5
|
+
verify_image,
|
|
6
|
+
verify_image_pillow,
|
|
7
|
+
verify_json,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
__all__ = (
|
|
11
|
+
"verify",
|
|
12
|
+
"verify_binary",
|
|
13
|
+
"verify_image",
|
|
14
|
+
"verify_image_pillow",
|
|
15
|
+
"verify_json",
|
|
16
|
+
)
|
|
17
|
+
except ImportError:
|
|
18
|
+
from pytest_approval.main import (
|
|
19
|
+
verify,
|
|
20
|
+
verify_binary,
|
|
21
|
+
verify_image,
|
|
22
|
+
verify_json,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
__all__ = (
|
|
26
|
+
"verify",
|
|
27
|
+
"verify_binary",
|
|
28
|
+
"verify_image",
|
|
29
|
+
"verify_json",
|
|
30
|
+
)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
approvers = [
|
|
2
|
+
[
|
|
3
|
+
"meld",
|
|
4
|
+
"%received",
|
|
5
|
+
"%approved"
|
|
6
|
+
],
|
|
7
|
+
[
|
|
8
|
+
"/usr/bin/flatpak",
|
|
9
|
+
"run",
|
|
10
|
+
"com.jetbrains.PyCharm-Community",
|
|
11
|
+
"diff",
|
|
12
|
+
"%received",
|
|
13
|
+
"%approved"
|
|
14
|
+
],
|
|
15
|
+
[
|
|
16
|
+
"alacritty",
|
|
17
|
+
"--command",
|
|
18
|
+
"nvim",
|
|
19
|
+
"-d",
|
|
20
|
+
"%received",
|
|
21
|
+
"%approved"
|
|
22
|
+
],
|
|
23
|
+
]
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import filecmp
|
|
2
|
+
import logging
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from pytest_approval.definitions import BINARY_EXTENSIONS
|
|
6
|
+
|
|
7
|
+
logger = logging.getLogger(__name__)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def compare_files(received: Path, approved: Path) -> bool:
|
|
11
|
+
logger.debug(f"Compare {received} with {approved}.")
|
|
12
|
+
if filecmp.cmp(received, approved, shallow=False):
|
|
13
|
+
return True
|
|
14
|
+
elif received.suffix not in BINARY_EXTENSIONS:
|
|
15
|
+
return approved.read_text() == received.read_text()
|
|
16
|
+
else:
|
|
17
|
+
return False
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def compare_files_shallow(received: Path, approved: Path) -> bool:
|
|
21
|
+
logger.debug(f"Compare {received} with {approved}.")
|
|
22
|
+
if filecmp.cmp(received, approved, shallow=True):
|
|
23
|
+
return True
|
|
24
|
+
elif received.suffix not in BINARY_EXTENSIONS:
|
|
25
|
+
return approved.read_text() == received.read_text()
|
|
26
|
+
else:
|
|
27
|
+
return False
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def compare_image_contents_only(received: Path, approved: Path) -> bool:
|
|
31
|
+
"""Compare image contents without metadata."""
|
|
32
|
+
try:
|
|
33
|
+
import numpy
|
|
34
|
+
from PIL import Image
|
|
35
|
+
except ImportError as error:
|
|
36
|
+
raise RuntimeError(
|
|
37
|
+
'To use content_only, please install "pytest-approval[image]"'
|
|
38
|
+
+ '\n\n\tpip install "pytest-approval[image]"'
|
|
39
|
+
) from error
|
|
40
|
+
received_image = Image.open(received)
|
|
41
|
+
approved_image = Image.open(approved)
|
|
42
|
+
received_array = numpy.array(received_image)
|
|
43
|
+
approved_array = numpy.array(approved_image)
|
|
44
|
+
return numpy.array_equiv(received_array, approved_array)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import tomllib
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
logger = logging.getLogger(__name__)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _find_config(path: Path | None = None) -> Path | None:
|
|
9
|
+
"""Recursively walk up to root from current working dir to find pyproject.toml"""
|
|
10
|
+
if path is None:
|
|
11
|
+
path = Path.cwd()
|
|
12
|
+
if str(path) == path.root:
|
|
13
|
+
logger.debug("No pyproject.toml found.")
|
|
14
|
+
return None
|
|
15
|
+
config_path = path / "pyproject.toml"
|
|
16
|
+
if config_path.exists():
|
|
17
|
+
return config_path
|
|
18
|
+
else:
|
|
19
|
+
return _find_config(path.parent)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _read_config() -> dict:
|
|
23
|
+
path = _find_config()
|
|
24
|
+
if path is None:
|
|
25
|
+
return {}
|
|
26
|
+
with open(path, "rb") as file:
|
|
27
|
+
config = tomllib.load(file)
|
|
28
|
+
try:
|
|
29
|
+
return config["tool"]["pytest-approval"]
|
|
30
|
+
except KeyError:
|
|
31
|
+
logger.debug("No configuration table found.")
|
|
32
|
+
return {}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
from contextlib import suppress
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from pytest_approval.config import _read_config
|
|
5
|
+
|
|
6
|
+
BASE_DIR = Path(__file__).parent.resolve()
|
|
7
|
+
|
|
8
|
+
REPORTERS_TEXT: list[list[str]] = [
|
|
9
|
+
[
|
|
10
|
+
"meld",
|
|
11
|
+
"%received",
|
|
12
|
+
"%approved",
|
|
13
|
+
],
|
|
14
|
+
[
|
|
15
|
+
"pycharm",
|
|
16
|
+
"diff",
|
|
17
|
+
"%received",
|
|
18
|
+
"%approved",
|
|
19
|
+
],
|
|
20
|
+
[
|
|
21
|
+
"/usr/bin/flatpak",
|
|
22
|
+
"run",
|
|
23
|
+
"com.jetbrains.PyCharm-Community",
|
|
24
|
+
"diff",
|
|
25
|
+
"%received",
|
|
26
|
+
"%approved",
|
|
27
|
+
],
|
|
28
|
+
[
|
|
29
|
+
"/usr/bin/code",
|
|
30
|
+
"--new-window",
|
|
31
|
+
"--wait",
|
|
32
|
+
"--diff",
|
|
33
|
+
"%received",
|
|
34
|
+
"%approved",
|
|
35
|
+
],
|
|
36
|
+
[
|
|
37
|
+
"/usr/bin/open",
|
|
38
|
+
# -W: Wait until the application is closed
|
|
39
|
+
"-W",
|
|
40
|
+
# -n: new instance
|
|
41
|
+
"-n",
|
|
42
|
+
# -a: application
|
|
43
|
+
"-a",
|
|
44
|
+
"/Applications/PyCharm Professional Edition.app/Contents/MacOS/pycharm",
|
|
45
|
+
"--args",
|
|
46
|
+
"diff",
|
|
47
|
+
"%received",
|
|
48
|
+
"%approved",
|
|
49
|
+
],
|
|
50
|
+
[
|
|
51
|
+
"/usr/bin/open",
|
|
52
|
+
# -W: Wait until the application is closed
|
|
53
|
+
"-W",
|
|
54
|
+
# -n: New instance
|
|
55
|
+
"-n",
|
|
56
|
+
# -a: Application
|
|
57
|
+
"-a",
|
|
58
|
+
"/Applications/PyCharm CE.app/Contents/MacOS/pycharm",
|
|
59
|
+
"--args",
|
|
60
|
+
"diff",
|
|
61
|
+
"%received",
|
|
62
|
+
"%approved",
|
|
63
|
+
],
|
|
64
|
+
[
|
|
65
|
+
"/usr/bin/open",
|
|
66
|
+
# -W: Wait until the application is closed
|
|
67
|
+
"-W",
|
|
68
|
+
# -n: New instance
|
|
69
|
+
"-n",
|
|
70
|
+
# -a: Application
|
|
71
|
+
"-a",
|
|
72
|
+
"/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code",
|
|
73
|
+
"--args",
|
|
74
|
+
"--new-window",
|
|
75
|
+
"--wait",
|
|
76
|
+
"--diff",
|
|
77
|
+
"%received",
|
|
78
|
+
"%approved",
|
|
79
|
+
],
|
|
80
|
+
[
|
|
81
|
+
"diff",
|
|
82
|
+
"--unified",
|
|
83
|
+
"--color",
|
|
84
|
+
"--suppress-common-lines",
|
|
85
|
+
"--label",
|
|
86
|
+
"received",
|
|
87
|
+
"--label",
|
|
88
|
+
"approved",
|
|
89
|
+
"%received",
|
|
90
|
+
"%approved",
|
|
91
|
+
],
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
REPORTERS_BINARY: list[list[str]] = [
|
|
96
|
+
[
|
|
97
|
+
"pycharm",
|
|
98
|
+
"diff",
|
|
99
|
+
"%received",
|
|
100
|
+
"%approved",
|
|
101
|
+
],
|
|
102
|
+
[
|
|
103
|
+
"/usr/bin/flatpak",
|
|
104
|
+
"run",
|
|
105
|
+
"com.jetbrains.PyCharm-Community",
|
|
106
|
+
"diff",
|
|
107
|
+
"%received",
|
|
108
|
+
"%approved",
|
|
109
|
+
],
|
|
110
|
+
[
|
|
111
|
+
"diff",
|
|
112
|
+
"--unified",
|
|
113
|
+
"--color",
|
|
114
|
+
"--suppress-common-lines",
|
|
115
|
+
"--label",
|
|
116
|
+
"received",
|
|
117
|
+
"--label",
|
|
118
|
+
"approved",
|
|
119
|
+
"%received",
|
|
120
|
+
"%approved",
|
|
121
|
+
],
|
|
122
|
+
]
|
|
123
|
+
|
|
124
|
+
BINARY_EXTENSIONS: list[str] = [
|
|
125
|
+
# "7z",
|
|
126
|
+
# "7zip",
|
|
127
|
+
# "avif",
|
|
128
|
+
# "bmp",
|
|
129
|
+
# "bz2",
|
|
130
|
+
# "bzip2",
|
|
131
|
+
# "dds",
|
|
132
|
+
# "dib",
|
|
133
|
+
# "docx",
|
|
134
|
+
# "emf",
|
|
135
|
+
# "exif",
|
|
136
|
+
# "gif",
|
|
137
|
+
# "gz",
|
|
138
|
+
# "gzip",
|
|
139
|
+
# "heic",
|
|
140
|
+
# "heif",
|
|
141
|
+
# "ico",
|
|
142
|
+
# "j2c",
|
|
143
|
+
# "jfif",
|
|
144
|
+
# "jp2",
|
|
145
|
+
# "jpc",
|
|
146
|
+
# "jpe",
|
|
147
|
+
".jpeg",
|
|
148
|
+
".jpg",
|
|
149
|
+
# "jxr",
|
|
150
|
+
# "nupkg",
|
|
151
|
+
# "odp",
|
|
152
|
+
# "ods",
|
|
153
|
+
# "odt",
|
|
154
|
+
# "pbm",
|
|
155
|
+
# "pcx",
|
|
156
|
+
# "pdf",
|
|
157
|
+
# "pgm",
|
|
158
|
+
".png",
|
|
159
|
+
# "ppm",
|
|
160
|
+
# "pptx",
|
|
161
|
+
# "rle",
|
|
162
|
+
# "rtf",
|
|
163
|
+
# "tar",
|
|
164
|
+
# "tga",
|
|
165
|
+
# "tif",
|
|
166
|
+
# "tiff",
|
|
167
|
+
# "wdp",
|
|
168
|
+
# "webp",
|
|
169
|
+
# "wmp",
|
|
170
|
+
# "xlsx",
|
|
171
|
+
# "xz",
|
|
172
|
+
# "zip",
|
|
173
|
+
]
|
|
174
|
+
|
|
175
|
+
CONFIG = _read_config()
|
|
176
|
+
|
|
177
|
+
with suppress(KeyError):
|
|
178
|
+
REPORTERS_TEXT = list(set(CONFIG["reporters"] + REPORTERS_TEXT))
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
%PDF-1.0
|
|
2
|
+
1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj 2 0 obj<</Type/Pages/Kids[3 0 R]/Count 1>>endobj 3 0 obj<</Type/Page/MediaBox[0 0 3 3]>>endobj
|
|
3
|
+
xref
|
|
4
|
+
0 4
|
|
5
|
+
0000000000 65535 f
|
|
6
|
+
0000000010 00000 n
|
|
7
|
+
0000000053 00000 n
|
|
8
|
+
0000000102 00000 n
|
|
9
|
+
trailer<</Size 4/Root 1 0 R>>
|
|
10
|
+
startxref
|
|
11
|
+
149
|
|
12
|
+
%EOF
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{\rtf}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|