schemathesis 3.36.0__py3-none-any.whl → 3.36.2__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.
@@ -245,6 +245,11 @@ def _iter_coverage_cases(
245
245
  if operation.body:
246
246
  for body in operation.body:
247
247
  schema = body.as_json_schema(operation)
248
+ # Definition could be a list for Open API 2.0
249
+ definition = body.definition if isinstance(body.definition, dict) else {}
250
+ examples = [example["value"] for example in definition.get("examples", {}).values() if "value" in example]
251
+ if examples:
252
+ schema.setdefault("examples", []).extend(examples)
248
253
  gen = coverage.cover_schema_iter(ctx, schema)
249
254
  value = next(gen, NOT_SET)
250
255
  if isinstance(value, NotSet):
schemathesis/auths.py CHANGED
@@ -450,6 +450,7 @@ class AuthStorage(Generic[Auth]):
450
450
  data: Auth | None = _provider_get(provider, case, context)
451
451
  if data is not None:
452
452
  provider.set(case, data, context)
453
+ case._has_explicit_auth = True
453
454
  break
454
455
 
455
456
 
@@ -4,7 +4,8 @@ import json
4
4
  from contextlib import contextmanager, suppress
5
5
  from dataclasses import dataclass, field
6
6
  from functools import lru_cache
7
- from typing import Any, Generator, TypeVar, cast
7
+ from itertools import combinations
8
+ from typing import Any, Generator, Iterator, TypeVar, cast
8
9
 
9
10
  import jsonschema
10
11
  from hypothesis import strategies as st
@@ -14,7 +15,7 @@ from hypothesis_jsonschema._canonicalise import canonicalish
14
15
 
15
16
  from schemathesis.constants import NOT_SET
16
17
 
17
- from ._hypothesis import combine_strategies, get_single_example
18
+ from ._hypothesis import get_single_example
18
19
  from ._methods import DataGenerationMethod
19
20
 
20
21
  BUFFER_SIZE = 8 * 1024
@@ -156,12 +157,17 @@ def _ignore_unfixable(
156
157
  raise
157
158
 
158
159
 
159
- def cover_schema_iter(ctx: CoverageContext, schema: dict | bool) -> Generator[GeneratedValue, None, None]:
160
+ def cover_schema_iter(
161
+ ctx: CoverageContext, schema: dict | bool, seen: set[Any | tuple[type, str]] | None = None
162
+ ) -> Generator[GeneratedValue, None, None]:
163
+ if seen is None:
164
+ seen = set()
160
165
  if isinstance(schema, bool):
161
166
  types = ["null", "boolean", "string", "number", "array", "object"]
162
167
  schema = {}
163
168
  else:
164
169
  types = schema.get("type", [])
170
+ push_examples_to_properties(schema)
165
171
  if not isinstance(types, list):
166
172
  types = [types] # type: ignore[unreachable]
167
173
  if not types:
@@ -172,13 +178,16 @@ def cover_schema_iter(ctx: CoverageContext, schema: dict | bool) -> Generator[Ge
172
178
  yield from _cover_positive_for_type(ctx, schema, ty)
173
179
  if DataGenerationMethod.negative in ctx.data_generation_methods:
174
180
  template = None
175
- seen: set[Any | tuple[type, str]] = set()
176
181
  for key, value in schema.items():
177
182
  with _ignore_unfixable():
178
183
  if key == "enum":
179
184
  yield from _negative_enum(ctx, value)
180
185
  elif key == "const":
181
- yield from _negative_enum(ctx, [value])
186
+ for value_ in _negative_enum(ctx, [value]):
187
+ k = _to_hashable_key(value_.value)
188
+ if k not in seen:
189
+ yield value_
190
+ seen.add(k)
182
191
  elif key == "type":
183
192
  yield from _negative_type(ctx, seen, value)
184
193
  elif key == "properties":
@@ -190,27 +199,37 @@ def cover_schema_iter(ctx: CoverageContext, schema: dict | bool) -> Generator[Ge
190
199
  yield from _negative_format(ctx, schema, value)
191
200
  elif key == "maximum":
192
201
  next = value + 1
193
- yield NegativeValue(next)
194
- seen.add(next)
202
+ if next not in seen:
203
+ yield NegativeValue(next)
204
+ seen.add(next)
195
205
  elif key == "minimum":
196
206
  next = value - 1
197
- yield NegativeValue(next)
198
- seen.add(next)
207
+ if next not in seen:
208
+ yield NegativeValue(next)
209
+ seen.add(next)
199
210
  elif key == "exclusiveMaximum" or key == "exclusiveMinimum" and value not in seen:
200
211
  yield NegativeValue(value)
201
212
  seen.add(value)
202
213
  elif key == "multipleOf":
203
- yield from _negative_multiple_of(ctx, schema, value)
214
+ for value_ in _negative_multiple_of(ctx, schema, value):
215
+ k = _to_hashable_key(value_.value)
216
+ if k not in seen:
217
+ yield value_
218
+ seen.add(k)
204
219
  elif key == "minLength" and 0 < value < BUFFER_SIZE:
205
220
  with suppress(InvalidArgument):
206
- yield NegativeValue(
207
- ctx.generate_from_schema({**schema, "minLength": value - 1, "maxLength": value - 1})
208
- )
221
+ value = ctx.generate_from_schema({**schema, "minLength": value - 1, "maxLength": value - 1})
222
+ k = _to_hashable_key(value)
223
+ if k not in seen:
224
+ yield NegativeValue(value)
225
+ seen.add(k)
209
226
  elif key == "maxLength" and value < BUFFER_SIZE:
210
227
  with suppress(InvalidArgument):
211
- yield NegativeValue(
212
- ctx.generate_from_schema({**schema, "minLength": value + 1, "maxLength": value + 1})
213
- )
228
+ value = ctx.generate_from_schema({**schema, "minLength": value + 1, "maxLength": value + 1})
229
+ k = _to_hashable_key(value)
230
+ if k not in seen:
231
+ yield NegativeValue(value)
232
+ seen.add(k)
214
233
  elif key == "uniqueItems" and value:
215
234
  yield from _negative_unique_items(ctx, schema)
216
235
  elif key == "required":
@@ -222,16 +241,16 @@ def cover_schema_iter(ctx: CoverageContext, schema: dict | bool) -> Generator[Ge
222
241
  elif key == "allOf":
223
242
  nctx = ctx.with_negative()
224
243
  if len(value) == 1:
225
- yield from cover_schema_iter(nctx, value[0])
244
+ yield from cover_schema_iter(nctx, value[0], seen)
226
245
  else:
227
246
  with _ignore_unfixable():
228
247
  canonical = canonicalish(schema)
229
- yield from cover_schema_iter(nctx, canonical)
248
+ yield from cover_schema_iter(nctx, canonical, seen)
230
249
  elif key == "anyOf" or key == "oneOf":
231
250
  nctx = ctx.with_negative()
232
251
  # NOTE: Other sub-schemas are not filtered out
233
252
  for sub_schema in value:
234
- yield from cover_schema_iter(nctx, sub_schema)
253
+ yield from cover_schema_iter(nctx, sub_schema, seen)
235
254
 
236
255
 
237
256
  def _get_properties(schema: dict | bool) -> dict | bool:
@@ -264,6 +283,8 @@ def _positive_string(ctx: CoverageContext, schema: dict) -> Generator[GeneratedV
264
283
  """Generate positive string values."""
265
284
  # Boundary and near boundary values
266
285
  min_length = schema.get("minLength")
286
+ if min_length == 0:
287
+ min_length = None
267
288
  max_length = schema.get("maxLength")
268
289
  example = schema.get("example")
269
290
  examples = schema.get("examples")
@@ -283,6 +304,12 @@ def _positive_string(ctx: CoverageContext, schema: dict) -> Generator[GeneratedV
283
304
  elif not min_length and not max_length:
284
305
  # Default positive value
285
306
  yield PositiveValue(ctx.generate_from_schema(schema))
307
+ elif "pattern" in schema:
308
+ # Without merging `maxLength` & `minLength` into a regex it is problematic
309
+ # to generate a valid value as the unredlying machinery will resort to filtering
310
+ # and it is unlikely that it will generate a string of that length
311
+ yield PositiveValue(ctx.generate_from_schema(schema))
312
+ return
286
313
 
287
314
  seen = set()
288
315
 
@@ -476,6 +503,10 @@ def _positive_object(ctx: CoverageContext, schema: dict, template: dict) -> Gene
476
503
  combo = {k: v for k, v in template.items() if k in required or k == name}
477
504
  if combo != template:
478
505
  yield PositiveValue(combo)
506
+ # Generate one combination for each size from 2 to N-1
507
+ for selection in select_combinations(optional):
508
+ combo = {k: v for k, v in template.items() if k in required or k in selection}
509
+ yield PositiveValue(combo)
479
510
  # Generate only required properties
480
511
  if set(properties) != required:
481
512
  only_required = {k: v for k, v in template.items() if k in required}
@@ -491,6 +522,11 @@ def _positive_object(ctx: CoverageContext, schema: dict, template: dict) -> Gene
491
522
  seen.clear()
492
523
 
493
524
 
525
+ def select_combinations(optional: list[str]) -> Iterator[tuple[str, ...]]:
526
+ for size in range(2, len(optional)):
527
+ yield next(combinations(optional, size))
528
+
529
+
494
530
  def _negative_enum(ctx: CoverageContext, value: list) -> Generator[GeneratedValue, None, None]:
495
531
  strategy = JSON_STRATEGY.filter(lambda x: x not in value)
496
532
  # The exact negative value is not important here
@@ -565,7 +601,24 @@ def _negative_type(ctx: CoverageContext, seen: set, ty: str | list[str]) -> Gene
565
601
  del strategies["integer"]
566
602
  if "integer" in types:
567
603
  strategies["number"] = FLOAT_STRATEGY.filter(lambda x: x != int(x))
568
- negative_strategy = combine_strategies(tuple(strategies.values())).filter(lambda x: _to_hashable_key(x) not in seen)
569
- value = ctx.generate_from(negative_strategy, cached=True)
570
- yield NegativeValue(value)
571
- seen.add(_to_hashable_key(value))
604
+ for strat in strategies.values():
605
+ value = ctx.generate_from(strat, cached=True)
606
+ hashed = _to_hashable_key(value)
607
+ if hashed in seen:
608
+ continue
609
+ yield NegativeValue(value)
610
+ seen.add(hashed)
611
+
612
+
613
+ def push_examples_to_properties(schema: dict[str, Any]) -> None:
614
+ """Push examples from the top-level 'examples' field to the corresponding properties."""
615
+ if "examples" in schema and "properties" in schema:
616
+ properties = schema["properties"]
617
+ for example in schema["examples"]:
618
+ if isinstance(example, dict):
619
+ for prop, value in example.items():
620
+ if prop in properties:
621
+ if "examples" not in properties[prop]:
622
+ properties[prop]["examples"] = []
623
+ if value not in schema["properties"][prop]["examples"]:
624
+ properties[prop]["examples"].append(value)
@@ -6,9 +6,11 @@ from dataclasses import dataclass
6
6
  from typing import TYPE_CHECKING, Callable, Optional
7
7
 
8
8
  if TYPE_CHECKING:
9
+ from requests.structures import CaseInsensitiveDict
10
+
9
11
  from ..models import Case
10
12
  from ..transports.responses import GenericResponse
11
- from requests.structures import CaseInsensitiveDict
13
+ from ..types import RawAuth
12
14
 
13
15
 
14
16
  CheckFunction = Callable[["CheckContext", "GenericResponse", "Case"], Optional[bool]]
@@ -21,6 +23,7 @@ class CheckContext:
21
23
  Provides access to broader test execution data beyond individual test cases.
22
24
  """
23
25
 
26
+ auth: RawAuth | None = None
24
27
  headers: CaseInsensitiveDict | None = None
25
28
 
26
29
 
schemathesis/models.py CHANGED
@@ -136,8 +136,7 @@ def prepare_request_data(kwargs: dict[str, Any]) -> PreparedRequestData:
136
136
  )
137
137
 
138
138
 
139
- @dataclass
140
- class TestPhase(Enum):
139
+ class TestPhase(str, Enum):
141
140
  __test__ = False
142
141
 
143
142
  EXPLICIT = "explicit"
@@ -184,6 +183,7 @@ class Case:
184
183
  # The way the case was generated (None for manually crafted ones)
185
184
  data_generation_method: DataGenerationMethod | None = None
186
185
  _auth: requests.auth.AuthBase | None = None
186
+ _has_explicit_auth: bool = False
187
187
 
188
188
  def __repr__(self) -> str:
189
189
  parts = [f"{self.__class__.__name__}("]
@@ -562,6 +562,8 @@ class Case:
562
562
  body=fast_deepcopy(self.body),
563
563
  generation_time=self.generation_time,
564
564
  id=self.id,
565
+ _auth=self._auth,
566
+ _has_explicit_auth=self._has_explicit_auth,
565
567
  )
566
568
 
567
569
 
@@ -11,7 +11,7 @@ if TYPE_CHECKING:
11
11
 
12
12
  from ...exceptions import OperationSchemaError
13
13
  from ...models import Case
14
- from ...types import NotSet
14
+ from ...types import NotSet, RawAuth
15
15
 
16
16
 
17
17
  @dataclass
@@ -19,15 +19,19 @@ class RunnerContext:
19
19
  """Holds context shared for a test run."""
20
20
 
21
21
  data: TestResultSet
22
+ auth: RawAuth | None
22
23
  seed: int | None
23
24
  stop_event: threading.Event
24
25
  unique_data: bool
25
26
  outcome_cache: dict[int, BaseException | None]
26
27
 
27
- __slots__ = ("data", "seed", "stop_event", "unique_data", "outcome_cache")
28
+ __slots__ = ("data", "auth", "seed", "stop_event", "unique_data", "outcome_cache")
28
29
 
29
- def __init__(self, *, seed: int | None, stop_event: threading.Event, unique_data: bool) -> None:
30
+ def __init__(
31
+ self, *, seed: int | None, auth: RawAuth | None, stop_event: threading.Event, unique_data: bool
32
+ ) -> None:
30
33
  self.data = TestResultSet(seed=seed)
34
+ self.auth = auth
31
35
  self.seed = seed
32
36
  self.stop_event = stop_event
33
37
  self.outcome_cache = {}
@@ -131,7 +131,7 @@ class BaseRunner:
131
131
  # If auth is explicitly provided, then the global provider is ignored
132
132
  if self.auth is not None:
133
133
  unregister_auth()
134
- ctx = RunnerContext(seed=self.seed, stop_event=stop_event, unique_data=self.unique_data)
134
+ ctx = RunnerContext(auth=self.auth, seed=self.seed, stop_event=stop_event, unique_data=self.unique_data)
135
135
  start_time = time.monotonic()
136
136
  initialized = None
137
137
  __probes = None
@@ -955,6 +955,7 @@ def network_test(
955
955
  headers["User-Agent"] = USER_AGENT
956
956
  if not dry_run:
957
957
  args = (
958
+ ctx,
958
959
  checks,
959
960
  targets,
960
961
  result,
@@ -973,6 +974,7 @@ def network_test(
973
974
 
974
975
  def _network_test(
975
976
  case: Case,
977
+ ctx: RunnerContext,
976
978
  checks: Iterable[CheckFunction],
977
979
  targets: Iterable[Target],
978
980
  result: TestResult,
@@ -1015,11 +1017,11 @@ def _network_test(
1015
1017
  run_targets(targets, context)
1016
1018
  status = Status.success
1017
1019
 
1018
- ctx = CheckContext(headers=CaseInsensitiveDict(headers) if headers else None)
1020
+ check_ctx = CheckContext(auth=ctx.auth, headers=CaseInsensitiveDict(headers) if headers else None)
1019
1021
  try:
1020
1022
  run_checks(
1021
1023
  case=case,
1022
- ctx=ctx,
1024
+ ctx=check_ctx,
1023
1025
  checks=checks,
1024
1026
  check_results=check_results,
1025
1027
  result=result,
@@ -1069,6 +1071,7 @@ def wsgi_test(
1069
1071
  headers = prepare_wsgi_headers(headers, auth, auth_type)
1070
1072
  if not dry_run:
1071
1073
  args = (
1074
+ ctx,
1072
1075
  checks,
1073
1076
  targets,
1074
1077
  result,
@@ -1085,6 +1088,7 @@ def wsgi_test(
1085
1088
 
1086
1089
  def _wsgi_test(
1087
1090
  case: Case,
1091
+ ctx: RunnerContext,
1088
1092
  checks: Iterable[CheckFunction],
1089
1093
  targets: Iterable[Target],
1090
1094
  result: TestResult,
@@ -1105,11 +1109,11 @@ def _wsgi_test(
1105
1109
  result.logs.extend(recorded.records)
1106
1110
  status = Status.success
1107
1111
  check_results: list[Check] = []
1108
- ctx = CheckContext(headers=CaseInsensitiveDict(headers) if headers else None)
1112
+ check_ctx = CheckContext(auth=ctx.auth, headers=CaseInsensitiveDict(headers) if headers else None)
1109
1113
  try:
1110
1114
  run_checks(
1111
1115
  case=case,
1112
- ctx=ctx,
1116
+ ctx=check_ctx,
1113
1117
  checks=checks,
1114
1118
  check_results=check_results,
1115
1119
  result=result,
@@ -1151,6 +1155,7 @@ def asgi_test(
1151
1155
 
1152
1156
  if not dry_run:
1153
1157
  args = (
1158
+ ctx,
1154
1159
  checks,
1155
1160
  targets,
1156
1161
  result,
@@ -1167,6 +1172,7 @@ def asgi_test(
1167
1172
 
1168
1173
  def _asgi_test(
1169
1174
  case: Case,
1175
+ ctx: RunnerContext,
1170
1176
  checks: Iterable[CheckFunction],
1171
1177
  targets: Iterable[Target],
1172
1178
  result: TestResult,
@@ -1183,11 +1189,11 @@ def _asgi_test(
1183
1189
  run_targets(targets, context)
1184
1190
  status = Status.success
1185
1191
  check_results: list[Check] = []
1186
- ctx = CheckContext(headers=CaseInsensitiveDict(headers) if headers else None)
1192
+ check_ctx = CheckContext(auth=ctx.auth, headers=CaseInsensitiveDict(headers) if headers else None)
1187
1193
  try:
1188
1194
  run_checks(
1189
1195
  case=case,
1190
- ctx=ctx,
1196
+ ctx=check_ctx,
1191
1197
  checks=checks,
1192
1198
  check_results=check_results,
1193
1199
  result=result,
@@ -527,7 +527,12 @@ def is_valid_path(parameters: dict[str, Any]) -> bool:
527
527
  disallowed_values = (SLASH, "")
528
528
 
529
529
  return not any(
530
- (value in disallowed_values or is_illegal_surrogate(value) or isinstance(value, str) and SLASH in value)
530
+ (
531
+ value in disallowed_values
532
+ or is_illegal_surrogate(value)
533
+ or isinstance(value, str)
534
+ and (SLASH in value or "}" in value or "{" in value)
535
+ )
531
536
  for value in parameters.values()
532
537
  )
533
538
 
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
- from dataclasses import dataclass
4
3
  import enum
4
+ from dataclasses import dataclass
5
5
  from http.cookies import SimpleCookie
6
6
  from typing import TYPE_CHECKING, Any, Dict, Generator, NoReturn, cast
7
7
  from urllib.parse import parse_qs, urlparse
@@ -348,7 +348,7 @@ def ignored_auth(ctx: CheckContext, response: GenericResponse, case: Case) -> bo
348
348
  security_parameters = _get_security_parameters(case.operation)
349
349
  # Authentication is required for this API operation and response is successful
350
350
  if security_parameters and 200 <= response.status_code < 300:
351
- auth = _contains_auth(ctx, response.request, security_parameters)
351
+ auth = _contains_auth(ctx, case, response.request, security_parameters)
352
352
  if auth == AuthKind.EXPLICIT:
353
353
  # Auth is explicitly set, it is expected to be valid
354
354
  # Check if invalid auth will give an error
@@ -412,11 +412,14 @@ def _get_security_parameters(operation: APIOperation) -> list[SecurityParameter]
412
412
 
413
413
 
414
414
  def _contains_auth(
415
- ctx: CheckContext, request: PreparedRequest, security_parameters: list[SecurityParameter]
415
+ ctx: CheckContext, case: Case, request: PreparedRequest, security_parameters: list[SecurityParameter]
416
416
  ) -> AuthKind | None:
417
417
  """Whether a request has authentication declared in the schema."""
418
418
  from requests.cookies import RequestsCookieJar
419
419
 
420
+ # If auth comes from explicit `auth` option or a custom auth, it is always explicit
421
+ if ctx.auth is not None or case._has_explicit_auth:
422
+ return AuthKind.EXPLICIT
420
423
  parsed = urlparse(request.url)
421
424
  query = parse_qs(parsed.query) # type: ignore
422
425
  # Load the `Cookie` header separately, because it is possible that `request._cookies` and the header are out of sync
@@ -5,6 +5,7 @@ from typing import Any, Callable
5
5
 
6
6
  from ...internal.copy import fast_deepcopy
7
7
  from ...internal.jsonschema import traverse_schema
8
+ from .patterns import update_quantifier
8
9
 
9
10
 
10
11
  def to_json_schema(
@@ -24,6 +25,15 @@ def to_json_schema(
24
25
  if schema_type == "file":
25
26
  schema["type"] = "string"
26
27
  schema["format"] = "binary"
28
+ pattern = schema.get("pattern")
29
+ min_length = schema.get("minLength")
30
+ max_length = schema.get("maxLength")
31
+ if pattern and (min_length or max_length):
32
+ new_pattern = update_quantifier(pattern, min_length, max_length)
33
+ if new_pattern != pattern:
34
+ schema.pop("minLength", None)
35
+ schema.pop("maxLength", None)
36
+ schema["pattern"] = new_pattern
27
37
  if schema_type == "object":
28
38
  if is_response_schema:
29
39
  # Write-only properties should not occur in responses
@@ -0,0 +1,120 @@
1
+ from __future__ import annotations
2
+
3
+ import re
4
+ from functools import lru_cache
5
+
6
+ try: # pragma: no cover
7
+ import re._constants as sre
8
+ import re._parser as sre_parse
9
+ except ImportError:
10
+ import sre_constants as sre
11
+ import sre_parse
12
+
13
+ ANCHOR = sre.AT
14
+ REPEATS: tuple
15
+ if hasattr(sre, "POSSESSIVE_REPEAT"):
16
+ REPEATS = (sre.MIN_REPEAT, sre.MAX_REPEAT, sre.POSSESSIVE_REPEAT)
17
+ else:
18
+ REPEATS = (sre.MIN_REPEAT, sre.MAX_REPEAT)
19
+ LITERAL = sre.LITERAL
20
+ IN = sre.IN
21
+ MAXREPEAT = sre_parse.MAXREPEAT
22
+
23
+
24
+ @lru_cache()
25
+ def update_quantifier(pattern: str, min_length: int | None, max_length: int | None) -> str:
26
+ """Update the quantifier of a regular expression based on given min and max lengths."""
27
+ if not pattern or (min_length in (None, 0) and max_length is None):
28
+ return pattern
29
+
30
+ try:
31
+ parsed = sre_parse.parse(pattern)
32
+ return _handle_parsed_pattern(parsed, pattern, min_length, max_length)
33
+ except re.error:
34
+ # Invalid pattern
35
+ return pattern
36
+
37
+
38
+ def _handle_parsed_pattern(parsed: list, pattern: str, min_length: int | None, max_length: int | None) -> str:
39
+ """Handle the parsed pattern and update quantifiers based on different cases."""
40
+ if len(parsed) == 1:
41
+ op, value = parsed[0]
42
+ return _update_quantifier(op, value, pattern, min_length, max_length)
43
+ elif len(parsed) == 2:
44
+ if parsed[0][0] == ANCHOR:
45
+ # Starts with an anchor
46
+ op, value = parsed[1]
47
+ leading_anchor = pattern[0]
48
+ return leading_anchor + _update_quantifier(op, value, pattern[1:], min_length, max_length)
49
+ if parsed[1][0] == ANCHOR:
50
+ # Ends with an anchor
51
+ op, value = parsed[0]
52
+ trailing_anchor = pattern[-1]
53
+ return _update_quantifier(op, value, pattern[:-1], min_length, max_length) + trailing_anchor
54
+ elif len(parsed) == 3 and parsed[0][0] == ANCHOR and parsed[2][0] == ANCHOR:
55
+ op, value = parsed[1]
56
+ leading_anchor = pattern[0]
57
+ trailing_anchor = pattern[-1]
58
+ return leading_anchor + _update_quantifier(op, value, pattern[1:-1], min_length, max_length) + trailing_anchor
59
+ return pattern
60
+
61
+
62
+ def _update_quantifier(op: int, value: tuple, pattern: str, min_length: int | None, max_length: int | None) -> str:
63
+ """Update the quantifier based on the operation type and given constraints."""
64
+ if op in REPEATS:
65
+ return _handle_repeat_quantifier(value, pattern, min_length, max_length)
66
+ if op in (LITERAL, IN) and max_length != 0:
67
+ return _handle_literal_or_in_quantifier(pattern, min_length, max_length)
68
+ return pattern
69
+
70
+
71
+ def _handle_repeat_quantifier(
72
+ value: tuple[int, int, tuple], pattern: str, min_length: int | None, max_length: int | None
73
+ ) -> str:
74
+ """Handle repeat quantifiers (e.g., '+', '*', '?')."""
75
+ min_repeat, max_repeat, _ = value
76
+ min_length, max_length = _build_size(min_repeat, max_repeat, min_length, max_length)
77
+ if min_length > max_length:
78
+ return pattern
79
+ return f"({_strip_quantifier(pattern)})" + _build_quantifier(min_length, max_length)
80
+
81
+
82
+ def _handle_literal_or_in_quantifier(pattern: str, min_length: int | None, max_length: int | None) -> str:
83
+ """Handle literal or character class quantifiers."""
84
+ min_length = 1 if min_length is None else max(min_length, 1)
85
+ return f"({pattern})" + _build_quantifier(min_length, max_length)
86
+
87
+
88
+ def _build_quantifier(minimum: int | None, maximum: int | None) -> str:
89
+ """Construct a quantifier string based on min and max values."""
90
+ if maximum == MAXREPEAT or maximum is None:
91
+ return f"{{{minimum or 0},}}"
92
+ if minimum == maximum:
93
+ return f"{{{minimum}}}"
94
+ return f"{{{minimum or 0},{maximum}}}"
95
+
96
+
97
+ def _build_size(min_repeat: int, max_repeat: int, min_length: int | None, max_length: int | None) -> tuple[int, int]:
98
+ """Merge the current repetition constraints with the provided min and max lengths."""
99
+ if min_length is not None:
100
+ min_repeat = max(min_repeat, min_length)
101
+ if max_length is not None:
102
+ if max_repeat == MAXREPEAT:
103
+ max_repeat = max_length
104
+ else:
105
+ max_repeat = min(max_repeat, max_length)
106
+ return min_repeat, max_repeat
107
+
108
+
109
+ def _strip_quantifier(pattern: str) -> str:
110
+ """Remove quantifier from the pattern."""
111
+ # Lazy & posessive quantifiers
112
+ if pattern.endswith(("*?", "+?", "??", "*+", "?+", "++")):
113
+ return pattern[:-2]
114
+ if pattern.endswith(("?", "*", "+")):
115
+ pattern = pattern[:-1]
116
+ if pattern.endswith("}"):
117
+ # Find the start of the exact quantifier and drop everything since that index
118
+ idx = pattern.rfind("{")
119
+ pattern = pattern[:idx]
120
+ return pattern
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: schemathesis
3
- Version: 3.36.0
3
+ Version: 3.36.2
4
4
  Summary: Property-based testing framework for Open API and GraphQL based apps
5
5
  Project-URL: Documentation, https://schemathesis.readthedocs.io/en/stable/
6
6
  Project-URL: Changelog, https://schemathesis.readthedocs.io/en/stable/changelog.html
@@ -237,6 +237,7 @@ Schemathesis is used by a number of projects and companies, including direct usa
237
237
  - [Pixie](https://github.com/pixie-io/pixie)
238
238
  - [Qdrant](https://github.com/qdrant/qdrant)
239
239
  - Spotify ([Backstage](https://github.com/backstage/backstage))
240
+ - [Weechat](https://github.com/weechat/weechat)
240
241
  - WordPress ([OpenVerse](https://github.com/WordPress/openverse))
241
242
 
242
243
  ## Testimonials
@@ -1,12 +1,12 @@
1
1
  schemathesis/__init__.py,sha256=UW2Bq8hDDkcBeAAA7PzpBFXkOOxkmHox-mfQwzHDjL0,1914
2
2
  schemathesis/_compat.py,sha256=y4RZd59i2NCnZ91VQhnKeMn_8t3SgvLOk2Xm8nymUHY,1837
3
3
  schemathesis/_dependency_versions.py,sha256=pjEkkGAfOQJYNb-9UOo84V8nj_lKHr_TGDVdFwY2UU0,816
4
- schemathesis/_hypothesis.py,sha256=NTl1OXL9Us5rkvEroqtxlFcYz3_JVjcNbhPbEHi5B7E,14291
4
+ schemathesis/_hypothesis.py,sha256=Sj7pGspDGeevcPgLkCF1pV7T5HleF84nZd7FbDUs_vE,14646
5
5
  schemathesis/_lazy_import.py,sha256=aMhWYgbU2JOltyWBb32vnWBb6kykOghucEzI_F70yVE,470
6
6
  schemathesis/_override.py,sha256=TAjYB3eJQmlw9K_xiR9ptt9Wj7if4U7UFlUhGjpBAoM,1625
7
7
  schemathesis/_rate_limiter.py,sha256=q_XWst5hzuAyXQRiZc4s_bx7-JlPYZM_yKDmeavt3oo,242
8
8
  schemathesis/_xml.py,sha256=lwRaKEMQvl6SUySnhGgooNsdmXPnDh11YSPpbsW8dR8,6923
9
- schemathesis/auths.py,sha256=mYFOL2YDZl-6Lyh-dv3pMd5dRs4r_kO7UuGUHt6dC88,16790
9
+ schemathesis/auths.py,sha256=De97IS_iOlC36-jRhkZ2DUndjUpXYgsd8R-nA-iHn88,16837
10
10
  schemathesis/checks.py,sha256=YPUI1N5giGBy1072vd77e6HWelGAKrJUmJLEG4oqfF8,2630
11
11
  schemathesis/code_samples.py,sha256=rsdTo6ksyUs3ZMhqx0mmmkPSKUCFa--snIOYsXgZd80,4120
12
12
  schemathesis/constants.py,sha256=l1YQ7PXhEj9dyf9CTESVUpPOaFCH7iz-Fe8o4v6Th_s,2673
@@ -17,7 +17,7 @@ schemathesis/graphql.py,sha256=XiuKcfoOB92iLFC8zpz2msLkM0_V0TLdxPNBqrrGZ8w,216
17
17
  schemathesis/hooks.py,sha256=qXyVRfJdhsLk1GuJX47VAqkX0VPm6X6fK-cXhEnFLT4,14765
18
18
  schemathesis/lazy.py,sha256=uE8ef_7U_9ovs0-7UA7ssIiiDipJurJFHuxaUFOUETo,18956
19
19
  schemathesis/loaders.py,sha256=MoEhcdOEBJxNRn5X-ZNhWB9jZDHQQNpkNfEdQjf_NDw,4590
20
- schemathesis/models.py,sha256=ix-g8Z6a_V_U2DUc4iC7EmFQv-t4es4Lpt1RLlIz-ng,46294
20
+ schemathesis/models.py,sha256=YNZ9EXVw0WreTy_3hw2aZ9OPS-0W7xePlh5h0dLmgvs,46411
21
21
  schemathesis/parameters.py,sha256=PndmqQRlEYsCt1kWjSShPsFf6vj7X_7FRdz_-A95eNg,2258
22
22
  schemathesis/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
23
  schemathesis/sanitization.py,sha256=Lycn1VVfula9B6XpzkxTHja7CZ7RHqbUh9kBic0Yi4M,9056
@@ -60,9 +60,9 @@ schemathesis/fixups/utf8_bom.py,sha256=lWT9RNmJG8i-l5AXIpaCT3qCPUwRgzXPW3eoOjmZE
60
60
  schemathesis/generation/__init__.py,sha256=29Zys_tD6kfngaC4zHeC6TOBZQcmo7CWm7KDSYsHStQ,1581
61
61
  schemathesis/generation/_hypothesis.py,sha256=QDBzpcM9eXPgLGGdCPdGlxCtfMXD4YBN9_6Oz73lofI,1406
62
62
  schemathesis/generation/_methods.py,sha256=jCK09f4sedDfePrS-6BIiE-CcEE8fJ4ZHxq1BHoTltQ,1101
63
- schemathesis/generation/coverage.py,sha256=NnXpjkrJ8zjYgNCpGnvvqWx_YxLff-4kc_ET3Essfeg,22407
63
+ schemathesis/generation/coverage.py,sha256=F_ABsBsQ7k4dR_sGI2ZNTUNRCjxpAPh5V80MYXx8F20,24758
64
64
  schemathesis/internal/__init__.py,sha256=93HcdG3LF0BbQKbCteOsFMa1w6nXl8yTmx87QLNJOik,161
65
- schemathesis/internal/checks.py,sha256=z3kHi4zbn4RmG168KIvOYxwUE8jQ1xAnFXTaD1xarb4,1603
65
+ schemathesis/internal/checks.py,sha256=m6lY6x2Pkz6AjU8Hs-UMSDJZEOq8EcgZOCp6BQA7p_g,1668
66
66
  schemathesis/internal/copy.py,sha256=DcL56z-d69kKR_5u8mlHvjSL1UTyUKNMAwexrwHFY1s,1031
67
67
  schemathesis/internal/datetime.py,sha256=zPLBL0XXLNfP-KYel3H2m8pnsxjsA_4d-zTOhJg2EPQ,136
68
68
  schemathesis/internal/deprecation.py,sha256=Ty5VBFBlufkITpP0WWTPIPbnB7biDi0kQgXVYWZp820,1273
@@ -77,8 +77,8 @@ schemathesis/runner/events.py,sha256=cRKKSDvHvKLBIyFBz-J0JtAKshbGGKco9eaMyLCgzsY
77
77
  schemathesis/runner/probes.py,sha256=no5AfO3kse25qvHevjeUfB0Q3C860V2AYzschUW3QMQ,5688
78
78
  schemathesis/runner/serialization.py,sha256=Rn8wUpxe8saWUBfSI60jK7-qPR-D2pY1ad1hD8qTHhE,20418
79
79
  schemathesis/runner/impl/__init__.py,sha256=1E2iME8uthYPBh9MjwVBCTFV-P3fi7AdphCCoBBspjs,199
80
- schemathesis/runner/impl/context.py,sha256=gEYE58DTRT38Jl__dSmqZhV_YI4mbR_JarnwXv0LeF0,2402
81
- schemathesis/runner/impl/core.py,sha256=ehNxUReBeSF62OpUzoeh_gBw-fb1ZExWebpHA6Oorh8,46965
80
+ schemathesis/runner/impl/context.py,sha256=KT3Dl1HIUM29Jpp_DwfoSx_NbWFH_7s6gw-p2Sr-N24,2505
81
+ schemathesis/runner/impl/core.py,sha256=bAPwfhLJrXLlPN6BDNGyQoO9v35YlmeuxAmyFTNQg5Y,47197
82
82
  schemathesis/runner/impl/solo.py,sha256=y5QSxgK8nBCEjZVD5BpFvYUXmB6tEjk6TwxAo__NejA,2911
83
83
  schemathesis/runner/impl/threadpool.py,sha256=yNR5LYE8f3N_4t42OwSgy0_qdGgBPM7d11F9c9oEAAs,15075
84
84
  schemathesis/service/__init__.py,sha256=cDVTCFD1G-vvhxZkJUwiToTAEQ-0ByIoqwXvJBCf_V8,472
@@ -104,10 +104,10 @@ schemathesis/specs/graphql/schemas.py,sha256=b7QwglKbcYQCMjuYmqDsVoFu2o4xaA_kduU
104
104
  schemathesis/specs/graphql/validation.py,sha256=uINIOt-2E7ZuQV2CxKzwez-7L9tDtqzMSpnVoRWvxy0,1635
105
105
  schemathesis/specs/openapi/__init__.py,sha256=HDcx3bqpa6qWPpyMrxAbM3uTo0Lqpg-BUNZhDJSJKnw,279
106
106
  schemathesis/specs/openapi/_cache.py,sha256=PAiAu4X_a2PQgD2lG5H3iisXdyg4SaHpU46bRZvfNkM,4320
107
- schemathesis/specs/openapi/_hypothesis.py,sha256=XgKq36ONJIWM-8ASnDpzOgcCcVz-uUQw74bOxcUC3n8,24201
108
- schemathesis/specs/openapi/checks.py,sha256=nriqejh-Y5ECCRYvfVenAgRik4xpejlCh22VpRo0RA4,22093
107
+ schemathesis/specs/openapi/_hypothesis.py,sha256=ZbLo8hDf4WVmRKmKF6rhK47xetkVJmE59Ghu_p7kLCw,24293
108
+ schemathesis/specs/openapi/checks.py,sha256=-4qOzkova0e4QSqdgsoUiOv2bg57HZmzbpAiAeotc3Q,22288
109
109
  schemathesis/specs/openapi/constants.py,sha256=JqM_FHOenqS_MuUE9sxVQ8Hnw0DNM8cnKDwCwPLhID4,783
110
- schemathesis/specs/openapi/converter.py,sha256=TaYgc5BBHPdkN-n0lqpbeVgLu3eL3L8Wu3y_Vo3TJaQ,2800
110
+ schemathesis/specs/openapi/converter.py,sha256=NkrzBNjtmVwQTeE73NOtwB_puvQTjxxqqrc7gD_yscc,3241
111
111
  schemathesis/specs/openapi/definitions.py,sha256=nEsCKn_LgqYjZ9nNWp-8KUIrB4S94pT3GsV5A8UIzDw,94043
112
112
  schemathesis/specs/openapi/examples.py,sha256=FwhPWca7bpdHpUp_LRoK09DVgusojO3aXXhXYrK373I,20354
113
113
  schemathesis/specs/openapi/formats.py,sha256=JmmkQWNAj5XreXb7Edgj4LADAf4m86YulR_Ec8evpJ4,1220
@@ -115,6 +115,7 @@ schemathesis/specs/openapi/links.py,sha256=a8JmWM9aZhrR5CfyIh6t2SkfonMLfYKOScXY2
115
115
  schemathesis/specs/openapi/loaders.py,sha256=5B1cgYEBj3h2psPQxzrQ5Xq5owLVGw-u9HsCQIx7yFE,25705
116
116
  schemathesis/specs/openapi/media_types.py,sha256=dNTxpRQbY3SubdVjh4Cjb38R6Bc9MF9BsRQwPD87x0g,1017
117
117
  schemathesis/specs/openapi/parameters.py,sha256=CqJdS4d14l25_yEbqkLCnfIdDTlodRhJpxD8EXdaFwM,14059
118
+ schemathesis/specs/openapi/patterns.py,sha256=IK2BkXI1xByEz5if6jvydFE07nq5rDa4k_-2xX7ifG8,4715
118
119
  schemathesis/specs/openapi/references.py,sha256=euxM02kQGMHh4Ss1jWjOY_gyw_HazafKITIsvOEiAvI,9831
119
120
  schemathesis/specs/openapi/schemas.py,sha256=t3Gz2q-d9b8Oy-hDhz0rNfjYT3Nx-uOeLOmjO9hpRM0,53741
120
121
  schemathesis/specs/openapi/security.py,sha256=Z-6pk2Ga1PTUtBe298KunjVHsNh5A-teegeso7zcPIE,7138
@@ -150,8 +151,8 @@ schemathesis/transports/auth.py,sha256=urSTO9zgFO1qU69xvnKHPFQV0SlJL3d7_Ojl0tLnZ
150
151
  schemathesis/transports/content_types.py,sha256=MiKOm-Hy5i75hrROPdpiBZPOTDzOwlCdnthJD12AJzI,2187
151
152
  schemathesis/transports/headers.py,sha256=hr_AIDOfUxsJxpHfemIZ_uNG3_vzS_ZeMEKmZjbYiBE,990
152
153
  schemathesis/transports/responses.py,sha256=OFD4ZLqwEFpo7F9vaP_SVgjhxAqatxIj38FS4XVq8Qs,1680
153
- schemathesis-3.36.0.dist-info/METADATA,sha256=HfnlCBEOL6RdgwQymCXcWVvoEfF26bVX_kdRspp4A6Y,12856
154
- schemathesis-3.36.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
155
- schemathesis-3.36.0.dist-info/entry_points.txt,sha256=VHyLcOG7co0nOeuk8WjgpRETk5P1E2iCLrn26Zkn5uk,158
156
- schemathesis-3.36.0.dist-info/licenses/LICENSE,sha256=PsPYgrDhZ7g9uwihJXNG-XVb55wj2uYhkl2DD8oAzY0,1103
157
- schemathesis-3.36.0.dist-info/RECORD,,
154
+ schemathesis-3.36.2.dist-info/METADATA,sha256=eoWwbh8dfwwyl3EyHoJsV_MUm4zvKYGTMMehbfOJyyQ,12904
155
+ schemathesis-3.36.2.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
156
+ schemathesis-3.36.2.dist-info/entry_points.txt,sha256=VHyLcOG7co0nOeuk8WjgpRETk5P1E2iCLrn26Zkn5uk,158
157
+ schemathesis-3.36.2.dist-info/licenses/LICENSE,sha256=PsPYgrDhZ7g9uwihJXNG-XVb55wj2uYhkl2DD8oAzY0,1103
158
+ schemathesis-3.36.2.dist-info/RECORD,,