pytest-httpchain 0.16.0__tar.gz → 0.16.1__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_httpchain-0.16.0 → pytest_httpchain-0.16.1}/PKG-INFO +1 -1
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/pyproject.toml +1 -1
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/pyproject.toml.orig +1 -1
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/cli.py +1 -1
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/importers/builder.py +8 -2
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/jsonref/jsonc.py +41 -5
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/response_steps.py +10 -3
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/validation/discovery.py +57 -7
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/validation/loader.py +8 -55
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/validation/validate.py +25 -4
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/LICENSE +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/README.md +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/__init__.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/body_schema.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/carrier.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/constants.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/dataflow.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/errors.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/factory.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/har_writer.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/importers/__init__.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/importers/curl.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/importers/har.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/jsonref/__init__.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/jsonref/equality.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/jsonref/exceptions.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/jsonref/loader.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/jsonref/plumbing/__init__.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/jsonref/plumbing/circular.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/jsonref/plumbing/path.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/jsonref/plumbing/reference.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/models/__init__.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/models/entities.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/models/types.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/parallel_stats.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/plugin.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/py.typed +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/redaction.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/report_formatter.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/request_builder.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/schema.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/scoping.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/templates/__init__.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/templates/exceptions.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/templates/expressions.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/templates/functions.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/templates/substitution.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/userfunc.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/utils.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/validation/__init__.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/validation/deep.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/validation/diagnostics.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/validation/semantic.py +0 -0
- {pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/warnings.py +0 -0
|
@@ -38,7 +38,7 @@ class GraphDirection(StrEnum):
|
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
RefParentTraversalDepth = Annotated[int, typer.Option(help="Maximum $ref parent directory traversal depth.")]
|
|
41
|
-
RootPath = Annotated[Path | None, typer.Option("--root-path", help="Directory that constrains $ref resolution (default:
|
|
41
|
+
RootPath = Annotated[Path | None, typer.Option("--root-path", help="Directory that constrains $ref resolution (default: the rootdir pytest would use).")]
|
|
42
42
|
OutputFormatOption = Annotated[OutputFormat, typer.Option("--format", help="Output format: human-readable text or machine-readable JSON.")]
|
|
43
43
|
|
|
44
44
|
|
{pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/importers/builder.py
RENAMED
|
@@ -638,7 +638,7 @@ class _Builder:
|
|
|
638
638
|
"""``{"fields": ..., "files": ...}``: a text field without a type or
|
|
639
639
|
filename is a field, anything else a file object (a path alone
|
|
640
640
|
where that says all). A secret's text, a field's or a file object's
|
|
641
|
-
``content`` (a field sent with a type is one), is a placeholder,
|
|
641
|
+
``content`` or ``base64`` (a field sent with a type is one), is a placeholder,
|
|
642
642
|
which fails the stage unset (a field or a file's only source is no
|
|
643
643
|
null). A part named as a reference key cannot be written, and is
|
|
644
644
|
left out with a note."""
|
|
@@ -656,7 +656,13 @@ class _Builder:
|
|
|
656
656
|
self.files.append(part.path)
|
|
657
657
|
spec["path"] = escape(part.path)
|
|
658
658
|
elif part.base64 is not None:
|
|
659
|
-
|
|
659
|
+
# Bytes that are no text (a password sent in another
|
|
660
|
+
# encoding) are as secret as text: the placeholder holds
|
|
661
|
+
# them base64-encoded, as recorded.
|
|
662
|
+
if self.is_secret_field(part.name, part.base64):
|
|
663
|
+
spec["base64"] = self.secret(part.name, part.base64, f"multipart part {part.name!r}, base64-encoded", stage)
|
|
664
|
+
else:
|
|
665
|
+
spec["base64"] = part.base64
|
|
660
666
|
elif self.is_secret_field(part.name, content := part.value if part.value is not None else part.content or ""):
|
|
661
667
|
spec["content"] = self.secret(part.name, content, f"multipart part {part.name!r}", stage)
|
|
662
668
|
else:
|
|
@@ -11,12 +11,13 @@ Strictly valid JSON is left as it is, so every reader goes through here with no
|
|
|
11
11
|
opt-in: `loads_jsonc` is what the reference resolver parses a file with and what
|
|
12
12
|
a body schema file is read with (``utils.read_json_schema_file``), so they agree
|
|
13
13
|
on what a file may hold. What arrives over HTTP (a response body) is never
|
|
14
|
-
passed through here: it stays
|
|
14
|
+
passed through here: it stays plain JSON, as ``json.loads`` reads it.
|
|
15
15
|
"""
|
|
16
16
|
|
|
17
17
|
import json
|
|
18
|
+
import math
|
|
18
19
|
import re
|
|
19
|
-
from typing import Any
|
|
20
|
+
from typing import Any, NoReturn
|
|
20
21
|
|
|
21
22
|
# JSON's whitespace, and nothing else: Python's \s would take a no-break space
|
|
22
23
|
# the JSON parser refuses as whitespace.
|
|
@@ -112,8 +113,43 @@ def strip_jsonc(text: str) -> str:
|
|
|
112
113
|
return "".join(parts)
|
|
113
114
|
|
|
114
115
|
|
|
116
|
+
# A string, whole, or a word ``json.loads`` reads as a number JSON cannot
|
|
117
|
+
# write: ``NaN`` or ``Infinity``, or a number too large for a float, which it
|
|
118
|
+
# reads as infinity. Words are found only outside strings, and the first one
|
|
119
|
+
# spelled as the parser handed it over is where the parser met it.
|
|
120
|
+
_WORD = re.compile(r'"[^"\\]*+(?:\\.[^"\\]*+)*+"|(?P<word>-?Infinity|NaN|-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?)')
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class _NotJSON(Exception):
|
|
124
|
+
"""A word the parser read that is no JSON number, raised out of it with
|
|
125
|
+
why."""
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _refuse_constant(word: str) -> NoReturn:
|
|
129
|
+
raise _NotJSON(word, f"{word} is not valid JSON")
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _finite(word: str) -> float:
|
|
133
|
+
# 1e400 is JSON, but a float past the largest is infinity, which is not.
|
|
134
|
+
if math.isinf(value := float(word)):
|
|
135
|
+
raise _NotJSON(word, f"{word} is too large a number (it reads as infinity)")
|
|
136
|
+
return value
|
|
137
|
+
|
|
138
|
+
|
|
115
139
|
def loads_jsonc(text: str, **kwargs: Any) -> Any:
|
|
116
140
|
"""``json.loads`` of JSONC text (`strip_jsonc`), with ``json.loads``' keyword
|
|
117
|
-
arguments
|
|
118
|
-
|
|
119
|
-
|
|
141
|
+
arguments but ``parse_constant`` and ``parse_float``, which it sets.
|
|
142
|
+
Raises `json.JSONDecodeError` as ``json.loads`` does, for an
|
|
143
|
+
unterminated comment too, and for ``NaN``, ``Infinity`` and
|
|
144
|
+
``-Infinity``, which ``json.loads`` reads as numbers though they are no
|
|
145
|
+
JSON, and a number too large for a float (``1e400``), which it reads as
|
|
146
|
+
infinity: a file holding one is not a JSON file, or holds a number no
|
|
147
|
+
JSON can write, and ``resolve``, which prints strict JSON, would print
|
|
148
|
+
``Infinity``."""
|
|
149
|
+
stripped = strip_jsonc(text)
|
|
150
|
+
try:
|
|
151
|
+
return json.loads(stripped, parse_constant=_refuse_constant, parse_float=_finite, **kwargs)
|
|
152
|
+
except _NotJSON as e:
|
|
153
|
+
word, message = e.args
|
|
154
|
+
position = next(match.start("word") for match in _WORD.finditer(stripped) if match["word"] == word)
|
|
155
|
+
raise json.JSONDecodeError(message, stripped, position) from None
|
|
@@ -58,8 +58,12 @@ def process_save(save_model: Save, response: httpx.Response, context: ChainMap[s
|
|
|
58
58
|
for var_name, jmespath_expr in save_model.jmespath.items():
|
|
59
59
|
try:
|
|
60
60
|
step_saved[var_name] = jmespath.search(jmespath_expr, response_json)
|
|
61
|
-
except
|
|
62
|
-
|
|
61
|
+
except (ValueError, ArithmeticError, TypeError) as e:
|
|
62
|
+
# What a verify.jmespath entry fails on (`_verify_jmespath`):
|
|
63
|
+
# jmespath's own errors, and Python's from what it hands
|
|
64
|
+
# its functions unchecked (`contains(s, n)`, `ceil()` of
|
|
65
|
+
# inf). Another response may hold what it needs: retryable.
|
|
66
|
+
raise SaveError(f"Error saving variable {var_name}: {_evaluation_error(e)}") from e
|
|
63
67
|
|
|
64
68
|
case RegexSave():
|
|
65
69
|
for var_name, entry in save_model.regex.items():
|
|
@@ -315,7 +319,10 @@ def process_verify(
|
|
|
315
319
|
if expression is _UNRENDERED:
|
|
316
320
|
continue
|
|
317
321
|
if not isinstance(expression, bool):
|
|
318
|
-
|
|
322
|
+
# The type alone, never the value, as for skip_if: `{{
|
|
323
|
+
# response.headers['Set-Cookie'] }}` renders a credential, which
|
|
324
|
+
# the report redacts in the headers but this line would print.
|
|
325
|
+
failures.add(f"Verify expression {i} must evaluate to bool, got {type(expression).__name__}, a value written where a condition belongs")
|
|
319
326
|
elif not expression:
|
|
320
327
|
failures.add(f"Expression {i} failed: evaluated to {expression}")
|
|
321
328
|
|
{pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/validation/discovery.py
RENAMED
|
@@ -154,9 +154,39 @@ def configured_suffix(paths: Sequence[Path]) -> str:
|
|
|
154
154
|
raise DiscoveryError(f"{file}: {ConfigOptions.SUFFIX} {e}") from None
|
|
155
155
|
|
|
156
156
|
|
|
157
|
+
def pytest_rootdir(paths: Sequence[Path]) -> Path:
|
|
158
|
+
"""The rootdir pytest would determine for a run on ``paths`` from the
|
|
159
|
+
current directory, given no ``-c`` or ``--rootdir``: the directory of the
|
|
160
|
+
configuration file it would read (see `configured_suffix`); failing that,
|
|
161
|
+
the nearest directory holding a ``setup.py``, at or above the common
|
|
162
|
+
ancestor of the paths; failing that, the common ancestor of the current
|
|
163
|
+
directory and the paths', or the paths' alone when that is the root of
|
|
164
|
+
the file system, or when there is none (on Windows, paths on another
|
|
165
|
+
drive than the current directory, where pytest keeps the current
|
|
166
|
+
directory, which holds none of them).
|
|
167
|
+
|
|
168
|
+
Collection sandboxes ``$ref`` targets in pytest's rootdir, so the CLI's
|
|
169
|
+
default reference root is this: `validate` rejects no reference a run
|
|
170
|
+
on the same paths resolves, and one run's files share one root.
|
|
171
|
+
|
|
172
|
+
A configuration file that cannot be read, which pytest stops on, is
|
|
173
|
+
passed over here, as one holding no pytest configuration is: a run over
|
|
174
|
+
files needs no setting from it (`configured_suffix` reports it when a
|
|
175
|
+
directory needs the suffix)."""
|
|
176
|
+
return _setup(paths, strict=False)[0]
|
|
177
|
+
|
|
178
|
+
|
|
157
179
|
def _locate_config(paths: Sequence[Path]) -> tuple[Path, dict[str, object]] | None:
|
|
158
180
|
"""The configuration file pytest would read for ``paths`` and the settings
|
|
159
181
|
it holds, or None when it would read none (see `configured_suffix`)."""
|
|
182
|
+
return _setup(paths, strict=True)[1]
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def _setup(paths: Sequence[Path], *, strict: bool) -> tuple[Path, tuple[Path, dict[str, object]] | None]:
|
|
186
|
+
"""pytest's rootdir for ``paths``, and the configuration file it reads
|
|
187
|
+
with its settings, or None (see `pytest_rootdir`); ``strict`` raises
|
|
188
|
+
`DiscoveryError` for a configuration file that cannot be read, else it is
|
|
189
|
+
passed over."""
|
|
160
190
|
dirs: list[Path] = []
|
|
161
191
|
for path in paths:
|
|
162
192
|
# Made absolute as pytest makes an argument absolute: `..` and `.`
|
|
@@ -165,10 +195,22 @@ def _locate_config(paths: Sequence[Path]) -> tuple[Path, dict[str, object]] | No
|
|
|
165
195
|
if os.path.exists(absolute):
|
|
166
196
|
dirs.append(absolute if os.path.isdir(absolute) else absolute.parent)
|
|
167
197
|
ancestor = _common_ancestor(dirs) if dirs else Path.cwd()
|
|
168
|
-
found
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
198
|
+
if (found := _find_config([ancestor], strict=strict)) is not None:
|
|
199
|
+
return found[0].parent, found
|
|
200
|
+
for base in (ancestor, *ancestor.parents):
|
|
201
|
+
if os.path.isfile(base / "setup.py"):
|
|
202
|
+
return base, None
|
|
203
|
+
if dirs != [ancestor] and (found := _find_config(dirs, strict=strict)) is not None:
|
|
204
|
+
return found[0].parent, found
|
|
205
|
+
try:
|
|
206
|
+
rootdir = Path(os.path.commonpath([Path.cwd(), ancestor]))
|
|
207
|
+
except ValueError:
|
|
208
|
+
# On another drive than the current directory (Windows): pytest keeps
|
|
209
|
+
# the current directory then, a rootdir that holds none of the paths,
|
|
210
|
+
# so their own common ancestor is taken instead.
|
|
211
|
+
return ancestor, None
|
|
212
|
+
# The root of the file system (of a drive, on Windows) is no rootdir.
|
|
213
|
+
return (ancestor if os.path.splitdrive(rootdir)[1] == os.sep else rootdir), None
|
|
172
214
|
|
|
173
215
|
|
|
174
216
|
def _common_ancestor(dirs: list[Path]) -> Path:
|
|
@@ -182,9 +224,12 @@ def _common_ancestor(dirs: list[Path]) -> Path:
|
|
|
182
224
|
return ancestor
|
|
183
225
|
|
|
184
226
|
|
|
185
|
-
def _find_config(starts: Iterable[Path]) -> tuple[Path, dict[str, object]] | None:
|
|
227
|
+
def _find_config(starts: Iterable[Path], *, strict: bool = True) -> tuple[Path, dict[str, object]] | None:
|
|
186
228
|
"""The first configuration file holding pytest configuration in each of
|
|
187
|
-
``starts`` or above it, in turn; else the first ``pyproject.toml`` met.
|
|
229
|
+
``starts`` or above it, in turn; else the first ``pyproject.toml`` met.
|
|
230
|
+
Not ``strict``, one that cannot be read, or that pytest would refuse, is
|
|
231
|
+
passed over as one holding no pytest configuration is: a
|
|
232
|
+
``pyproject.toml`` of the kind is still the one met, if first."""
|
|
188
233
|
bare_pyproject: Path | None = None
|
|
189
234
|
for start in starts:
|
|
190
235
|
for base in (start, *start.parents):
|
|
@@ -192,7 +237,12 @@ def _find_config(starts: Iterable[Path]) -> tuple[Path, dict[str, object]] | Non
|
|
|
192
237
|
file = base / name
|
|
193
238
|
if not os.path.isfile(file):
|
|
194
239
|
continue
|
|
195
|
-
|
|
240
|
+
try:
|
|
241
|
+
settings = _read_config(file)
|
|
242
|
+
except DiscoveryError:
|
|
243
|
+
if strict:
|
|
244
|
+
raise
|
|
245
|
+
settings = None
|
|
196
246
|
if settings is not None:
|
|
197
247
|
return file, settings
|
|
198
248
|
if name == "pyproject.toml" and bare_pyproject is None:
|
{pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/validation/loader.py
RENAMED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"""The load + $ref-resolve + model-validate path shared by the CLI and pytest collection."""
|
|
2
2
|
|
|
3
|
-
import configparser
|
|
4
3
|
import json
|
|
5
|
-
import tomllib
|
|
6
4
|
import warnings
|
|
7
5
|
from pathlib import Path
|
|
8
6
|
from typing import Any
|
|
@@ -12,66 +10,21 @@ from pydantic import ValidationError
|
|
|
12
10
|
from pytest_httpchain.jsonref import FileLoadError, InvalidJSONError, ReferenceResolverError, load_json
|
|
13
11
|
from pytest_httpchain.models import Scenario
|
|
14
12
|
from pytest_httpchain.validation.diagnostics import Diagnostic, DiagnosticCode, diag
|
|
13
|
+
from pytest_httpchain.validation.discovery import pytest_rootdir
|
|
15
14
|
from pytest_httpchain.warnings import AmbiguousReferenceWarning
|
|
16
15
|
|
|
17
|
-
_ROOT_MARKERS = ("pytest.ini", "pyproject.toml", "tox.ini", "setup.cfg", "setup.py", ".git")
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def _holds_pytest_config(directory: Path) -> bool:
|
|
21
|
-
"""True when the directory holds a file pytest would accept as its inifile.
|
|
22
|
-
|
|
23
|
-
Mirrors pytest's own rule: ``pytest.ini`` always counts, while the shared
|
|
24
|
-
files count only when they actually carry a pytest section. A bare
|
|
25
|
-
``pyproject.toml`` — a sub-package in a monorepo — is not a pytest rootdir.
|
|
26
|
-
"""
|
|
27
|
-
if (directory / "pytest.ini").is_file():
|
|
28
|
-
return True
|
|
29
|
-
|
|
30
|
-
pyproject = directory / "pyproject.toml"
|
|
31
|
-
if pyproject.is_file():
|
|
32
|
-
try:
|
|
33
|
-
if "pytest" in tomllib.loads(pyproject.read_text(encoding="utf-8")).get("tool", {}):
|
|
34
|
-
return True
|
|
35
|
-
except (OSError, ValueError):
|
|
36
|
-
pass
|
|
37
|
-
|
|
38
|
-
for filename, section in (("tox.ini", "pytest"), ("setup.cfg", "tool:pytest")):
|
|
39
|
-
candidate = directory / filename
|
|
40
|
-
if not candidate.is_file():
|
|
41
|
-
continue
|
|
42
|
-
parser = configparser.ConfigParser()
|
|
43
|
-
try:
|
|
44
|
-
parser.read(candidate, encoding="utf-8")
|
|
45
|
-
except (OSError, configparser.Error, UnicodeDecodeError):
|
|
46
|
-
continue
|
|
47
|
-
if parser.has_section(section):
|
|
48
|
-
return True
|
|
49
|
-
|
|
50
|
-
return False
|
|
51
|
-
|
|
52
16
|
|
|
53
17
|
def resolve_root_path(path: Path) -> Path:
|
|
54
18
|
"""Directory that constrains ``$ref`` resolution when no explicit root is given.
|
|
55
19
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
then the file's own parent.
|
|
20
|
+
pytest's rootdir for a run on ``path`` from the current directory
|
|
21
|
+
(`discovery.pytest_rootdir`), which collection passes explicitly: the
|
|
22
|
+
directory of the configuration file pytest would read, else of the
|
|
23
|
+
nearest ``setup.py``, else the common ancestor of the current directory
|
|
24
|
+
and the file's. A narrower root rejects ``$ref`` targets that collection
|
|
25
|
+
resolves fine, a red CI on a working scenario.
|
|
63
26
|
"""
|
|
64
|
-
|
|
65
|
-
for ancestor in ancestors:
|
|
66
|
-
if _holds_pytest_config(ancestor):
|
|
67
|
-
return ancestor
|
|
68
|
-
for ancestor in ancestors:
|
|
69
|
-
if any((ancestor / marker).exists() for marker in _ROOT_MARKERS):
|
|
70
|
-
return ancestor
|
|
71
|
-
for ancestor in ancestors:
|
|
72
|
-
if ancestor.name == "tests":
|
|
73
|
-
return ancestor
|
|
74
|
-
return path.parent
|
|
27
|
+
return pytest_rootdir([path])
|
|
75
28
|
|
|
76
29
|
|
|
77
30
|
def _verify_subpath(path: tuple[str | int, ...]) -> tuple[str | int, ...] | None:
|
{pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/validation/validate.py
RENAMED
|
@@ -10,7 +10,7 @@ from pytest_httpchain.body_schema import ReferenceBounds
|
|
|
10
10
|
from pytest_httpchain.constants import SCENARIO_FILE_EXTENSIONS
|
|
11
11
|
from pytest_httpchain.validation.deep import check_scenario_deep
|
|
12
12
|
from pytest_httpchain.validation.diagnostics import Diagnostic, DiagnosticCode, ValidateResult, diag, result
|
|
13
|
-
from pytest_httpchain.validation.discovery import configured_suffix, find_scenario_files
|
|
13
|
+
from pytest_httpchain.validation.discovery import configured_suffix, find_scenario_files, pytest_rootdir
|
|
14
14
|
from pytest_httpchain.validation.loader import load_with_diagnostics, resolve_root_path
|
|
15
15
|
from pytest_httpchain.validation.semantic import check_scenario, describe_scenario
|
|
16
16
|
|
|
@@ -23,7 +23,10 @@ def validate_scenario(
|
|
|
23
23
|
syspaths: list[Path] | None = None,
|
|
24
24
|
) -> ValidateResult:
|
|
25
25
|
"""Validate a scenario file: existence, JSON, ``$ref``, schema, then the
|
|
26
|
-
semantic checks — and with ``deep``, the opt-in import/file checks.
|
|
26
|
+
semantic checks — and with ``deep``, the opt-in import/file checks.
|
|
27
|
+
|
|
28
|
+
References are held to ``root_path``, by default pytest's rootdir for a
|
|
29
|
+
run on the file (`resolve_root_path`)."""
|
|
27
30
|
diagnostics: list[Diagnostic] = []
|
|
28
31
|
|
|
29
32
|
if not path.exists():
|
|
@@ -41,6 +44,9 @@ def validate_scenario(
|
|
|
41
44
|
)
|
|
42
45
|
)
|
|
43
46
|
|
|
47
|
+
if root_path is None:
|
|
48
|
+
root_path = resolve_root_path(path)
|
|
49
|
+
|
|
44
50
|
# Load diagnostics are collected rather than returned early, so ambiguity
|
|
45
51
|
# warnings earned by earlier references are still reported.
|
|
46
52
|
loaded, load_diagnostics = load_with_diagnostics(path, root_path=root_path, ref_parent_traversal_depth=ref_parent_traversal_depth)
|
|
@@ -53,7 +59,7 @@ def validate_scenario(
|
|
|
53
59
|
|
|
54
60
|
if deep:
|
|
55
61
|
# The bounds the load held the scenario's references to, for its body schemas'.
|
|
56
|
-
ref_bounds = ReferenceBounds(root_path
|
|
62
|
+
ref_bounds = ReferenceBounds(root_path, ref_parent_traversal_depth)
|
|
57
63
|
diagnostics.extend(check_scenario_deep(scenario, syspaths=syspaths, scenario_dir=path.parent, ref_bounds=ref_bounds))
|
|
58
64
|
|
|
59
65
|
return result(diagnostics, describe_scenario(scenario, test_data))
|
|
@@ -87,7 +93,22 @@ def validate_paths(
|
|
|
87
93
|
Every directory is searched before any file is validated, so the
|
|
88
94
|
`DiscoveryError` of one that cannot be (or of a configuration file that
|
|
89
95
|
cannot be read) stops the run before it has done any work.
|
|
96
|
+
|
|
97
|
+
References are held to ``root_path``, by default to the rootdir pytest
|
|
98
|
+
would determine for a run on ``paths`` (`pytest_rootdir`): one root for
|
|
99
|
+
every file, as a pytest run has, where a root derived for each file
|
|
100
|
+
alone could be narrower than the run's and reject a reference it
|
|
101
|
+
resolves. A file that root does not hold (files of two projects in one
|
|
102
|
+
run, the run's root the first one's) is held to the root pytest gives
|
|
103
|
+
it alone: the run's would fail every reference it makes.
|
|
90
104
|
"""
|
|
105
|
+
run_root = root_path if root_path is not None else pytest_rootdir(paths)
|
|
106
|
+
|
|
107
|
+
def file_root(path: Path) -> Path:
|
|
108
|
+
if root_path is not None or Path(os.path.abspath(path)).is_relative_to(run_root):
|
|
109
|
+
return run_root
|
|
110
|
+
return pytest_rootdir([path])
|
|
111
|
+
|
|
91
112
|
targets: list[tuple[Path, ValidateResult | None]] = []
|
|
92
113
|
seen: set[str] = set()
|
|
93
114
|
|
|
@@ -116,7 +137,7 @@ def validate_paths(
|
|
|
116
137
|
return [
|
|
117
138
|
(
|
|
118
139
|
path,
|
|
119
|
-
found if found is not None else validate_scenario(path, ref_parent_traversal_depth=ref_parent_traversal_depth, root_path=
|
|
140
|
+
found if found is not None else validate_scenario(path, ref_parent_traversal_depth=ref_parent_traversal_depth, root_path=file_root(path), deep=deep, syspaths=syspaths),
|
|
120
141
|
)
|
|
121
142
|
for path, found in targets
|
|
122
143
|
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/importers/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/jsonref/__init__.py
RENAMED
|
File without changes
|
{pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/jsonref/equality.py
RENAMED
|
File without changes
|
{pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/jsonref/exceptions.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/jsonref/plumbing/path.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/report_formatter.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/templates/__init__.py
RENAMED
|
File without changes
|
{pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/templates/exceptions.py
RENAMED
|
File without changes
|
{pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/templates/expressions.py
RENAMED
|
File without changes
|
{pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/templates/functions.py
RENAMED
|
File without changes
|
{pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/templates/substitution.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/validation/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/validation/diagnostics.py
RENAMED
|
File without changes
|
{pytest_httpchain-0.16.0 → pytest_httpchain-0.16.1}/src/pytest_httpchain/validation/semantic.py
RENAMED
|
File without changes
|
|
File without changes
|