pytest-accept 0.2.2__tar.gz → 0.2.4__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_accept-0.2.4/LICENSE +191 -0
- {pytest_accept-0.2.2 → pytest_accept-0.2.4}/PKG-INFO +6 -8
- {pytest_accept-0.2.2 → pytest_accept-0.2.4}/README.md +4 -7
- {pytest_accept-0.2.2 → pytest_accept-0.2.4}/pyproject.toml +7 -8
- {pytest_accept-0.2.2 → pytest_accept-0.2.4}/pytest_accept/__init__.py +4 -2
- {pytest_accept-0.2.2 → pytest_accept-0.2.4}/pytest_accept/assert_plugin.py +15 -10
- {pytest_accept-0.2.2 → pytest_accept-0.2.4}/pytest_accept/tests/test_doctest.py +0 -3
- pytest_accept-0.2.4/pytest_accept/tests/test_issue_296.py +50 -0
- {pytest_accept-0.2.2 → pytest_accept-0.2.4}/pytest_accept/common.py +0 -0
- {pytest_accept-0.2.2 → pytest_accept-0.2.4}/pytest_accept/doctest_plugin.py +0 -0
- {pytest_accept-0.2.2 → pytest_accept-0.2.4}/pytest_accept/tests/__init__.py +0 -0
- {pytest_accept-0.2.2 → pytest_accept-0.2.4}/pytest_accept/tests/test_api_compatibility.py +0 -0
- {pytest_accept-0.2.2 → pytest_accept-0.2.4}/pytest_accept/tests/test_assert_plugin.py +0 -0
- {pytest_accept-0.2.2 → pytest_accept-0.2.4}/pytest_accept/tests/test_assertion_filtering.py +0 -0
- {pytest_accept-0.2.2 → pytest_accept-0.2.4}/pytest_accept/tests/test_atomic_write_verification.py +0 -0
- {pytest_accept-0.2.2 → pytest_accept-0.2.4}/pytest_accept/tests/test_complex_assertion_warning.py +0 -0
- {pytest_accept-0.2.2 → pytest_accept-0.2.4}/pytest_accept/tests/test_concurrent_execution.py +0 -0
- {pytest_accept-0.2.2 → pytest_accept-0.2.4}/pytest_accept/tests/test_doctest_formatting.py +0 -0
- {pytest_accept-0.2.2 → pytest_accept-0.2.4}/pytest_accept/tests/test_file_change_detection.py +0 -0
- {pytest_accept-0.2.2 → pytest_accept-0.2.4}/pytest_accept/tests/test_integration.py +0 -0
- {pytest_accept-0.2.2 → pytest_accept-0.2.4}/pytest_accept/tests/test_multiple_doctest_failures.py +0 -0
- {pytest_accept-0.2.2 → pytest_accept-0.2.4}/pytest_accept/tests/test_no_xdist.py +0 -0
- {pytest_accept-0.2.2 → pytest_accept-0.2.4}/pytest_accept/tests/test_parametrized.py +0 -0
- {pytest_accept-0.2.2 → pytest_accept-0.2.4}/pytest_accept/tests/test_unified_integration.py +0 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and
|
|
10
|
+
distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
|
13
|
+
owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities
|
|
16
|
+
that control, are controlled by, or are under common control with that entity.
|
|
17
|
+
For the purposes of this definition, "control" means (i) the power, direct or
|
|
18
|
+
indirect, to cause the direction or management of such entity, whether by
|
|
19
|
+
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
20
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
21
|
+
|
|
22
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
|
23
|
+
permissions granted by this License.
|
|
24
|
+
|
|
25
|
+
"Source" form shall mean the preferred form for making modifications, including
|
|
26
|
+
but not limited to software source code, documentation source, and configuration
|
|
27
|
+
files.
|
|
28
|
+
|
|
29
|
+
"Object" form shall mean any form resulting from mechanical transformation or
|
|
30
|
+
translation of a Source form, including but not limited to compiled object code,
|
|
31
|
+
generated documentation, and conversions to other media types.
|
|
32
|
+
|
|
33
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made
|
|
34
|
+
available under the License, as indicated by a copyright notice that is included
|
|
35
|
+
in or attached to the work (an example is provided in the Appendix below).
|
|
36
|
+
|
|
37
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
|
38
|
+
is based on (or derived from) the Work and for which the editorial revisions,
|
|
39
|
+
annotations, elaborations, or other modifications represent, as a whole, an
|
|
40
|
+
original work of authorship. For the purposes of this License, Derivative Works
|
|
41
|
+
shall not include works that remain separable from, or merely link (or bind by
|
|
42
|
+
name) to the interfaces of, the Work and Derivative Works thereof.
|
|
43
|
+
|
|
44
|
+
"Contribution" shall mean any work of authorship, including the original version
|
|
45
|
+
of the Work and any modifications or additions to that Work or Derivative Works
|
|
46
|
+
thereof, that is intentionally submitted to Licensor for inclusion in the Work
|
|
47
|
+
by the copyright owner or by an individual or Legal Entity authorized to submit
|
|
48
|
+
on behalf of the copyright owner. For the purposes of this definition,
|
|
49
|
+
"submitted" means any form of electronic, verbal, or written communication sent
|
|
50
|
+
to the Licensor or its representatives, including but not limited to
|
|
51
|
+
communication on electronic mailing lists, source code control systems, and
|
|
52
|
+
issue tracking systems that are managed by, or on behalf of, the Licensor for
|
|
53
|
+
the purpose of discussing and improving the Work, but excluding communication
|
|
54
|
+
that is conspicuously marked or otherwise designated in writing by the copyright
|
|
55
|
+
owner as "Not a Contribution."
|
|
56
|
+
|
|
57
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
|
58
|
+
of whom a Contribution has been received by Licensor and subsequently
|
|
59
|
+
incorporated within the Work.
|
|
60
|
+
|
|
61
|
+
2. Grant of Copyright License.
|
|
62
|
+
|
|
63
|
+
Subject to the terms and conditions of this License, each Contributor hereby
|
|
64
|
+
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
|
65
|
+
irrevocable copyright license to reproduce, prepare Derivative Works of,
|
|
66
|
+
publicly display, publicly perform, sublicense, and distribute the Work and such
|
|
67
|
+
Derivative Works in Source or Object form.
|
|
68
|
+
|
|
69
|
+
3. Grant of Patent License.
|
|
70
|
+
|
|
71
|
+
Subject to the terms and conditions of this License, each Contributor hereby
|
|
72
|
+
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
|
73
|
+
irrevocable (except as stated in this section) patent license to make, have
|
|
74
|
+
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
|
|
75
|
+
such license applies only to those patent claims licensable by such Contributor
|
|
76
|
+
that are necessarily infringed by their Contribution(s) alone or by combination
|
|
77
|
+
of their Contribution(s) with the Work to which such Contribution(s) was
|
|
78
|
+
submitted. If You institute patent litigation against any entity (including a
|
|
79
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
|
80
|
+
Contribution incorporated within the Work constitutes direct or contributory
|
|
81
|
+
patent infringement, then any patent licenses granted to You under this License
|
|
82
|
+
for that Work shall terminate as of the date such litigation is filed.
|
|
83
|
+
|
|
84
|
+
4. Redistribution.
|
|
85
|
+
|
|
86
|
+
You may reproduce and distribute copies of the Work or Derivative Works thereof
|
|
87
|
+
in any medium, with or without modifications, and in Source or Object form,
|
|
88
|
+
provided that You meet the following conditions:
|
|
89
|
+
|
|
90
|
+
You must give any other recipients of the Work or Derivative Works a copy of
|
|
91
|
+
this License; and
|
|
92
|
+
You must cause any modified files to carry prominent notices stating that You
|
|
93
|
+
changed the files; and
|
|
94
|
+
You must retain, in the Source form of any Derivative Works that You distribute,
|
|
95
|
+
all copyright, patent, trademark, and attribution notices from the Source form
|
|
96
|
+
of the Work, excluding those notices that do not pertain to any part of the
|
|
97
|
+
Derivative Works; and
|
|
98
|
+
If the Work includes a "NOTICE" text file as part of its distribution, then any
|
|
99
|
+
Derivative Works that You distribute must include a readable copy of the
|
|
100
|
+
attribution notices contained within such NOTICE file, excluding those notices
|
|
101
|
+
that do not pertain to any part of the Derivative Works, in at least one of the
|
|
102
|
+
following places: within a NOTICE text file distributed as part of the
|
|
103
|
+
Derivative Works; within the Source form or documentation, if provided along
|
|
104
|
+
with the Derivative Works; or, within a display generated by the Derivative
|
|
105
|
+
Works, if and wherever such third-party notices normally appear. The contents of
|
|
106
|
+
the NOTICE file are for informational purposes only and do not modify the
|
|
107
|
+
License. You may add Your own attribution notices within Derivative Works that
|
|
108
|
+
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
|
109
|
+
provided that such additional attribution notices cannot be construed as
|
|
110
|
+
modifying the License.
|
|
111
|
+
You may add Your own copyright statement to Your modifications and may provide
|
|
112
|
+
additional or different license terms and conditions for use, reproduction, or
|
|
113
|
+
distribution of Your modifications, or for any such Derivative Works as a whole,
|
|
114
|
+
provided Your use, reproduction, and distribution of the Work otherwise complies
|
|
115
|
+
with the conditions stated in this License.
|
|
116
|
+
|
|
117
|
+
5. Submission of Contributions.
|
|
118
|
+
|
|
119
|
+
Unless You explicitly state otherwise, any Contribution intentionally submitted
|
|
120
|
+
for inclusion in the Work by You to the Licensor shall be under the terms and
|
|
121
|
+
conditions of this License, without any additional terms or conditions.
|
|
122
|
+
Notwithstanding the above, nothing herein shall supersede or modify the terms of
|
|
123
|
+
any separate license agreement you may have executed with Licensor regarding
|
|
124
|
+
such Contributions.
|
|
125
|
+
|
|
126
|
+
6. Trademarks.
|
|
127
|
+
|
|
128
|
+
This License does not grant permission to use the trade names, trademarks,
|
|
129
|
+
service marks, or product names of the Licensor, except as required for
|
|
130
|
+
reasonable and customary use in describing the origin of the Work and
|
|
131
|
+
reproducing the content of the NOTICE file.
|
|
132
|
+
|
|
133
|
+
7. Disclaimer of Warranty.
|
|
134
|
+
|
|
135
|
+
Unless required by applicable law or agreed to in writing, Licensor provides the
|
|
136
|
+
Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
137
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
|
|
138
|
+
including, without limitation, any warranties or conditions of TITLE,
|
|
139
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
|
|
140
|
+
solely responsible for determining the appropriateness of using or
|
|
141
|
+
redistributing the Work and assume any risks associated with Your exercise of
|
|
142
|
+
permissions under this License.
|
|
143
|
+
|
|
144
|
+
8. Limitation of Liability.
|
|
145
|
+
|
|
146
|
+
In no event and under no legal theory, whether in tort (including negligence),
|
|
147
|
+
contract, or otherwise, unless required by applicable law (such as deliberate
|
|
148
|
+
and grossly negligent acts) or agreed to in writing, shall any Contributor be
|
|
149
|
+
liable to You for damages, including any direct, indirect, special, incidental,
|
|
150
|
+
or consequential damages of any character arising as a result of this License or
|
|
151
|
+
out of the use or inability to use the Work (including but not limited to
|
|
152
|
+
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
|
|
153
|
+
any and all other commercial damages or losses), even if such Contributor has
|
|
154
|
+
been advised of the possibility of such damages.
|
|
155
|
+
|
|
156
|
+
9. Accepting Warranty or Additional Liability.
|
|
157
|
+
|
|
158
|
+
While redistributing the Work or Derivative Works thereof, You may choose to
|
|
159
|
+
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
|
|
160
|
+
other liability obligations and/or rights consistent with this License. However,
|
|
161
|
+
in accepting such obligations, You may act only on Your own behalf and on Your
|
|
162
|
+
sole responsibility, not on behalf of any other Contributor, and only if You
|
|
163
|
+
agree to indemnify, defend, and hold each Contributor harmless for any liability
|
|
164
|
+
incurred by, or claims asserted against, such Contributor by reason of your
|
|
165
|
+
accepting any such warranty or additional liability.
|
|
166
|
+
|
|
167
|
+
END OF TERMS AND CONDITIONS
|
|
168
|
+
|
|
169
|
+
APPENDIX: How to apply the Apache License to your work
|
|
170
|
+
|
|
171
|
+
To apply the Apache License to your work, attach the following boilerplate
|
|
172
|
+
notice, with the fields enclosed by brackets "[]" replaced with your own
|
|
173
|
+
identifying information. (Don't include the brackets!) The text should be
|
|
174
|
+
enclosed in the appropriate comment syntax for the file format. We also
|
|
175
|
+
recommend that a file or class name and description of purpose be included on
|
|
176
|
+
the same "printed page" as the copyright notice for easier identification within
|
|
177
|
+
third-party archives.
|
|
178
|
+
|
|
179
|
+
Copyright [yyyy] [name of copyright owner]
|
|
180
|
+
|
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
+
you may not use this file except in compliance with the License.
|
|
183
|
+
You may obtain a copy of the License at
|
|
184
|
+
|
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
+
|
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
+
See the License for the specific language governing permissions and
|
|
191
|
+
limitations under the License.
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pytest-accept
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Author: Maximilian Roos
|
|
5
5
|
Author-email: Maximilian Roos <m@maxroos.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
7
|
+
License-File: LICENSE
|
|
7
8
|
Requires-Dist: astor>=0.8.1
|
|
8
9
|
Requires-Dist: pytest>=7
|
|
9
10
|
Requires-Python: >=3.9, <4
|
|
@@ -24,9 +25,6 @@ documented outputs.
|
|
|
24
25
|
## Before
|
|
25
26
|
|
|
26
27
|
```python
|
|
27
|
-
import re
|
|
28
|
-
|
|
29
|
-
|
|
30
28
|
def extract_functions(code):
|
|
31
29
|
return re.findall(r"(\w+)\(", code)
|
|
32
30
|
|
|
@@ -41,8 +39,8 @@ def test_extract_functions():
|
|
|
41
39
|
```diff
|
|
42
40
|
def test_extract_functions():
|
|
43
41
|
assert extract_functions("print('hi')") == ["print"]
|
|
44
|
-
-
|
|
45
|
-
+
|
|
42
|
+
- assert extract_functions("sum(map(f, x))") == ["sum"]
|
|
43
|
+
+ assert extract_functions("sum(map(f, x))") == ["sum", "map"]
|
|
46
44
|
```
|
|
47
45
|
|
|
48
46
|
pytest-accept is decoupled from the tests it works with — it can be used with
|
|
@@ -71,8 +69,8 @@ pytest --accept
|
|
|
71
69
|
|
|
72
70
|
- Often it's fairly easy to observe whether something is working by viewing the
|
|
73
71
|
output it produces
|
|
74
|
-
- ...but often output is verbose, and copying and pasting the output into
|
|
75
|
-
test is tedious
|
|
72
|
+
- ...but often the output is verbose, and copying and pasting the output into
|
|
73
|
+
the test is tedious
|
|
76
74
|
- `pytest-accept` does the copying & pasting for you
|
|
77
75
|
- Similarly, lots of folks generally find writing any tests a bit annoying, and
|
|
78
76
|
prefer to develop by "running the code and seeing if it works". This library
|
|
@@ -11,9 +11,6 @@ documented outputs.
|
|
|
11
11
|
## Before
|
|
12
12
|
|
|
13
13
|
```python
|
|
14
|
-
import re
|
|
15
|
-
|
|
16
|
-
|
|
17
14
|
def extract_functions(code):
|
|
18
15
|
return re.findall(r"(\w+)\(", code)
|
|
19
16
|
|
|
@@ -28,8 +25,8 @@ def test_extract_functions():
|
|
|
28
25
|
```diff
|
|
29
26
|
def test_extract_functions():
|
|
30
27
|
assert extract_functions("print('hi')") == ["print"]
|
|
31
|
-
-
|
|
32
|
-
+
|
|
28
|
+
- assert extract_functions("sum(map(f, x))") == ["sum"]
|
|
29
|
+
+ assert extract_functions("sum(map(f, x))") == ["sum", "map"]
|
|
33
30
|
```
|
|
34
31
|
|
|
35
32
|
pytest-accept is decoupled from the tests it works with — it can be used with
|
|
@@ -58,8 +55,8 @@ pytest --accept
|
|
|
58
55
|
|
|
59
56
|
- Often it's fairly easy to observe whether something is working by viewing the
|
|
60
57
|
output it produces
|
|
61
|
-
- ...but often output is verbose, and copying and pasting the output into
|
|
62
|
-
test is tedious
|
|
58
|
+
- ...but often the output is verbose, and copying and pasting the output into
|
|
59
|
+
the test is tedious
|
|
63
60
|
- `pytest-accept` does the copying & pasting for you
|
|
64
61
|
- Similarly, lots of folks generally find writing any tests a bit annoying, and
|
|
65
62
|
prefer to develop by "running the code and seeing if it works". This library
|
|
@@ -3,13 +3,14 @@ authors = [{ name = "Maximilian Roos", email = "m@maxroos.com" }]
|
|
|
3
3
|
dependencies = ["astor>=0.8.1", "pytest>=7"]
|
|
4
4
|
requires-python = ">=3.9, <4"
|
|
5
5
|
license = "Apache-2.0"
|
|
6
|
+
license-files = ["LICENSE"]
|
|
6
7
|
readme = "README.md"
|
|
7
|
-
version = "0.2.
|
|
8
|
+
version = "0.2.4"
|
|
8
9
|
name = "pytest-accept"
|
|
9
10
|
urls = { homepage = "https://github.com/max-sixty/pytest-accept", repository = "https://github.com/max-sixty/pytest-accept" }
|
|
10
11
|
|
|
11
12
|
[dependency-groups]
|
|
12
|
-
dev = ["
|
|
13
|
+
dev = ["pre-commit", "pytest-xdist>=3.8.0", "ruff", "ty"]
|
|
13
14
|
|
|
14
15
|
[project.entry-points.pytest11]
|
|
15
16
|
accept = "pytest_accept"
|
|
@@ -17,7 +18,7 @@ accept = "pytest_accept"
|
|
|
17
18
|
[tool.pytest.ini_options]
|
|
18
19
|
addopts = ["--strict-config", "--strict-markers", "--doctest-modules"]
|
|
19
20
|
doctest_optionflags = "NORMALIZE_WHITESPACE IGNORE_EXCEPTION_DETAIL ELLIPSIS"
|
|
20
|
-
filterwarnings = ["error
|
|
21
|
+
filterwarnings = ["error"]
|
|
21
22
|
pytester_example_dir = "examples"
|
|
22
23
|
testpaths = ["pytest_accept"]
|
|
23
24
|
|
|
@@ -33,6 +34,9 @@ module-root = ""
|
|
|
33
34
|
[tool.ruff]
|
|
34
35
|
fix = true
|
|
35
36
|
|
|
37
|
+
[tool.ruff.format]
|
|
38
|
+
docstring-code-format = true
|
|
39
|
+
|
|
36
40
|
[tool.ruff.lint]
|
|
37
41
|
ignore = [
|
|
38
42
|
"E402", # module level import at top — too strict in some cases
|
|
@@ -47,8 +51,3 @@ select = [
|
|
|
47
51
|
"I", # isort
|
|
48
52
|
"UP", # Pyupgrade
|
|
49
53
|
]
|
|
50
|
-
|
|
51
|
-
[tool.mypy]
|
|
52
|
-
files = "."
|
|
53
|
-
# TODO: ideally we would list the modules that aren't yet typed
|
|
54
|
-
ignore_missing_imports = true
|
|
@@ -237,8 +237,10 @@ def _apply_doctest_changes(
|
|
|
237
237
|
result.extend(original[:next_start_line])
|
|
238
238
|
|
|
239
239
|
for current, next_failure in zip_longest(failures, failures[1:]):
|
|
240
|
-
# Get
|
|
241
|
-
|
|
240
|
+
# Get indentation from the >>> source line of the current example,
|
|
241
|
+
# not from next_start_line which may be an empty line (issue #296)
|
|
242
|
+
source_line_idx = current.test.lineno + current.example.lineno
|
|
243
|
+
match = re.match(r"\s*", original[source_line_idx])
|
|
242
244
|
existing_indent = match.group() if match else ""
|
|
243
245
|
snapshot_result = _to_doctest_format(current.got)
|
|
244
246
|
indented = textwrap.indent(snapshot_result, prefix=existing_indent)
|
|
@@ -17,7 +17,6 @@ containing a failing assertion:
|
|
|
17
17
|
|
|
18
18
|
```python
|
|
19
19
|
def test_x():
|
|
20
|
-
|
|
21
20
|
assert 1 + 1 == 3
|
|
22
21
|
|
|
23
22
|
assert 2 == 3
|
|
@@ -111,7 +110,7 @@ def _patch_assertion_rewriter():
|
|
|
111
110
|
|
|
112
111
|
# Add simple safety check - if there are too many AST nodes, skip wrapping
|
|
113
112
|
# This prevents "too many statically nested blocks" errors in edge cases
|
|
114
|
-
total_nodes = sum(1 for _ in ast.walk(ast.Module(body=rv)))
|
|
113
|
+
total_nodes = sum(1 for _ in ast.walk(ast.Module(body=rv, type_ignores=[])))
|
|
115
114
|
if total_nodes > 200: # Higher threshold - only skip for very complex cases
|
|
116
115
|
# module_path is an internal pytest attribute that may not exist in all versions
|
|
117
116
|
if hasattr(self, "module_path"):
|
|
@@ -123,11 +122,14 @@ def _patch_assertion_rewriter():
|
|
|
123
122
|
# Return original without wrapping to avoid "too many nested blocks"
|
|
124
123
|
return rv
|
|
125
124
|
|
|
125
|
+
exception_type = ast.Name(id="AssertionError", ctx=ast.Load())
|
|
126
|
+
ast.copy_location(exception_type, assert_)
|
|
127
|
+
|
|
126
128
|
try_except = ast.Try(
|
|
127
129
|
body=rv,
|
|
128
130
|
handlers=[
|
|
129
131
|
ast.ExceptHandler(
|
|
130
|
-
|
|
132
|
+
type=exception_type,
|
|
131
133
|
name="__pytest_accept_e",
|
|
132
134
|
body=_ASSERTION_HANDLER,
|
|
133
135
|
)
|
|
@@ -142,7 +144,7 @@ def _patch_assertion_rewriter():
|
|
|
142
144
|
|
|
143
145
|
return [try_except]
|
|
144
146
|
|
|
145
|
-
AssertionRewriter.visit_Assert = new_visit_assert
|
|
147
|
+
AssertionRewriter.visit_Assert = new_visit_assert # type: ignore[method-assign]
|
|
146
148
|
|
|
147
149
|
|
|
148
150
|
def __handle_failed_assertion():
|
|
@@ -181,7 +183,7 @@ def __handle_failed_assertion_impl(raw_excinfo, session, left):
|
|
|
181
183
|
line_number_end = line_number_start + len(tb_entry.statement.lines) - 1
|
|
182
184
|
original_location = slice(line_number_start, line_number_end)
|
|
183
185
|
|
|
184
|
-
path = tb_entry.path
|
|
186
|
+
path = Path(tb_entry.path)
|
|
185
187
|
with path.open() as f:
|
|
186
188
|
tree = ast.parse(f.read())
|
|
187
189
|
|
|
@@ -189,18 +191,21 @@ def __handle_failed_assertion_impl(raw_excinfo, session, left):
|
|
|
189
191
|
if isinstance(item, ast.Assert) and original_location.start == item.lineno:
|
|
190
192
|
# we need to _then_ check that the next compare item's
|
|
191
193
|
# ops[0] is Eq and then replace the comparator[0]
|
|
194
|
+
test = item.test
|
|
195
|
+
if not isinstance(test, ast.Compare):
|
|
196
|
+
continue
|
|
192
197
|
try:
|
|
193
198
|
assert item.msg is None
|
|
194
|
-
assert len(
|
|
195
|
-
assert len(
|
|
196
|
-
assert isinstance(
|
|
199
|
+
assert len(test.comparators) == 1
|
|
200
|
+
assert len(test.ops) == 1
|
|
201
|
+
assert isinstance(test.ops[0], ast.Eq)
|
|
197
202
|
|
|
198
|
-
ast.literal_eval(
|
|
203
|
+
ast.literal_eval(test.comparators[0])
|
|
199
204
|
except Exception:
|
|
200
205
|
continue
|
|
201
206
|
|
|
202
207
|
new_assert = copy.copy(item)
|
|
203
|
-
|
|
208
|
+
test.comparators[0] = ast.Constant(value=left)
|
|
204
209
|
|
|
205
210
|
# Submit change to unified change collection
|
|
206
211
|
file_changes = session.stash.setdefault(file_changes_key, {})
|
|
@@ -14,7 +14,6 @@ def add_example():
|
|
|
14
14
|
>>> pytester = getfixture("pytester")
|
|
15
15
|
>>> if sys.platform == "win32":
|
|
16
16
|
... pytest.skip("Paths differ on windows")
|
|
17
|
-
...
|
|
18
17
|
>>> pytester.copy_example("add.py")
|
|
19
18
|
PosixPath('.../pytest_accept.tests.test_doctest.add_example0/add.py')
|
|
20
19
|
|
|
@@ -55,7 +54,6 @@ def add_example():
|
|
|
55
54
|
(For some reason we need to delete the pyc file, TODO: work out why upstream
|
|
56
55
|
>>> for f in pytester.path.glob(r"**/*.pyc"):
|
|
57
56
|
... f.unlink()
|
|
58
|
-
...
|
|
59
57
|
|
|
60
58
|
>>> result = pytester.runpytest("--doctest-modules", "--accept")
|
|
61
59
|
=====...==== test session starts ====...====
|
|
@@ -86,7 +84,6 @@ def no_overwrite_example():
|
|
|
86
84
|
|
|
87
85
|
>>> if sys.platform == "win32":
|
|
88
86
|
... pytest.skip("Paths differ on windows")
|
|
89
|
-
...
|
|
90
87
|
>>> path = pytester.copy_example("add.py")
|
|
91
88
|
|
|
92
89
|
Collect the tests, to simulate starting the tests:
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Reproduce issue #296: indentation depends on blank line whitespace content"""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def test_indentation_with_empty_blank_line(pytester):
|
|
5
|
+
"""When the blank line after >>> has no whitespace, output should still be indented."""
|
|
6
|
+
# The blank line between >>> and the closing """ has NO trailing spaces
|
|
7
|
+
test_contents = (
|
|
8
|
+
"def func():\n"
|
|
9
|
+
' """\n'
|
|
10
|
+
" >>> func()\n"
|
|
11
|
+
"\n" # truly empty line - no indentation
|
|
12
|
+
' """\n'
|
|
13
|
+
" return 2\n"
|
|
14
|
+
)
|
|
15
|
+
path = pytester.makepyfile(test_contents)
|
|
16
|
+
result = pytester.runpytest("--doctest-modules", "--accept")
|
|
17
|
+
result.assert_outcomes(failed=1)
|
|
18
|
+
|
|
19
|
+
content = path.read_text()
|
|
20
|
+
# The output '2' must be indented to match the docstring level
|
|
21
|
+
assert " 2\n" in content, f"Expected indented output but got:\n{content}"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_indentation_two_examples_mixed_blank_lines(pytester):
|
|
25
|
+
"""Exact scenario from issue #296: two examples with different blank line content."""
|
|
26
|
+
# Case 1 blank line has 4 spaces; case 2 blank line is truly empty
|
|
27
|
+
test_contents = (
|
|
28
|
+
"def func():\n"
|
|
29
|
+
' """\n'
|
|
30
|
+
" Examples\n"
|
|
31
|
+
" --------\n"
|
|
32
|
+
" >>> func()\n"
|
|
33
|
+
" \n" # blank line WITH indentation spaces
|
|
34
|
+
" >>> func()\n"
|
|
35
|
+
"\n" # blank line WITHOUT any spaces
|
|
36
|
+
' """\n'
|
|
37
|
+
" return 2\n"
|
|
38
|
+
)
|
|
39
|
+
path = pytester.makepyfile(test_contents)
|
|
40
|
+
result = pytester.runpytest("--doctest-modules", "--accept")
|
|
41
|
+
result.assert_outcomes(failed=1)
|
|
42
|
+
|
|
43
|
+
content = path.read_text()
|
|
44
|
+
lines = content.splitlines()
|
|
45
|
+
# Find the output lines (lines containing just "2" with indentation)
|
|
46
|
+
output_lines = [line for line in lines if line.strip() == "2"]
|
|
47
|
+
assert len(output_lines) == 2, f"Expected 2 output lines but got:\n{content}"
|
|
48
|
+
# Both must be indented identically
|
|
49
|
+
assert output_lines[0] == " 2", f"First output wrong indent:\n{content}"
|
|
50
|
+
assert output_lines[1] == " 2", f"Second output wrong indent:\n{content}"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pytest_accept-0.2.2 → pytest_accept-0.2.4}/pytest_accept/tests/test_atomic_write_verification.py
RENAMED
|
File without changes
|
{pytest_accept-0.2.2 → pytest_accept-0.2.4}/pytest_accept/tests/test_complex_assertion_warning.py
RENAMED
|
File without changes
|
{pytest_accept-0.2.2 → pytest_accept-0.2.4}/pytest_accept/tests/test_concurrent_execution.py
RENAMED
|
File without changes
|
|
File without changes
|
{pytest_accept-0.2.2 → pytest_accept-0.2.4}/pytest_accept/tests/test_file_change_detection.py
RENAMED
|
File without changes
|
|
File without changes
|
{pytest_accept-0.2.2 → pytest_accept-0.2.4}/pytest_accept/tests/test_multiple_doctest_failures.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|