aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2024-06-29 11:45:31 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2024-06-29 11:52:41 +0300
commit632b3cedb8e12fbbb0bcd1bdbf7ec5686725b7e9 (patch)
tree38164f3cf78dc378be566fd9b04e0dda83700a2b
parentcb38d5c70aed1911b32b11ae32e90585d4d27cc3 (diff)
downloadydb-632b3cedb8e12fbbb0bcd1bdbf7ec5686725b7e9.tar.gz
Intermediate changes
-rw-r--r--contrib/python/hypothesis/py3/.dist-info/METADATA2
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/internal/conjecture/data.py63
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/internal/conjecture/engine.py67
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/internal/conjecture/optimiser.py4
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/internal/conjecture/utils.py20
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/version.py2
-rw-r--r--contrib/python/hypothesis/py3/ya.make2
-rw-r--r--contrib/python/responses/py3/.dist-info/METADATA2
-rw-r--r--contrib/python/responses/py3/responses/__init__.py7
-rw-r--r--contrib/python/responses/py3/responses/_recorder.py30
-rw-r--r--contrib/python/responses/py3/ya.make2
11 files changed, 115 insertions, 86 deletions
diff --git a/contrib/python/hypothesis/py3/.dist-info/METADATA b/contrib/python/hypothesis/py3/.dist-info/METADATA
index 57cf50eec1..ad18a5c15f 100644
--- a/contrib/python/hypothesis/py3/.dist-info/METADATA
+++ b/contrib/python/hypothesis/py3/.dist-info/METADATA
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: hypothesis
-Version: 6.103.1
+Version: 6.103.2
Summary: A library for property-based testing
Home-page: https://hypothesis.works
Author: David R. MacIver and Zac Hatfield-Dodds
diff --git a/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/data.py b/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/data.py
index 10ae727c2d..64885793fa 100644
--- a/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/data.py
+++ b/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/data.py
@@ -85,20 +85,7 @@ else:
return wrapper
-ONE_BOUND_INTEGERS_LABEL = calc_label_from_name("trying a one-bound int allowing 0")
-INTEGER_RANGE_DRAW_LABEL = calc_label_from_name("another draw in integer_range()")
-BIASED_COIN_LABEL = calc_label_from_name("biased_coin()")
-
TOP_LABEL = calc_label_from_name("top")
-DRAW_BYTES_LABEL = calc_label_from_name("draw_bytes() in ConjectureData")
-DRAW_FLOAT_LABEL = calc_label_from_name("drawing a float")
-FLOAT_STRATEGY_DO_DRAW_LABEL = calc_label_from_name(
- "getting another float in FloatStrategy"
-)
-INTEGER_WEIGHTED_DISTRIBUTION = calc_label_from_name(
- "drawing from a weighted distribution in integers"
-)
-
InterestingOrigin = Tuple[
Type[BaseException], str, int, Tuple[Any, ...], Tuple[Tuple[Any, ...], ...]
]
@@ -370,11 +357,9 @@ class ExampleProperty:
blocks = self.examples.blocks
for record in self.examples.trail:
if record == DRAW_BITS_RECORD:
- self.__push(0)
self.bytes_read = blocks.endpoints[self.block_count]
self.block(self.block_count)
self.block_count += 1
- self.__pop(discarded=False)
elif record == IR_NODE_RECORD:
data = self.examples.ir_nodes[self.ir_node_count]
self.ir_node(data)
@@ -469,8 +454,8 @@ class ExampleRecord:
"""
def __init__(self) -> None:
- self.labels = [DRAW_BYTES_LABEL]
- self.__index_of_labels: "Optional[Dict[int, int]]" = {DRAW_BYTES_LABEL: 0}
+ self.labels: List[int] = []
+ self.__index_of_labels: "Optional[Dict[int, int]]" = {}
self.trail = IntList()
self.ir_nodes: List[IRNode] = []
@@ -522,11 +507,9 @@ class Examples:
self.trail = record.trail
self.ir_nodes = record.ir_nodes
self.labels = record.labels
- self.__length = (
- self.trail.count(STOP_EXAMPLE_DISCARD_RECORD)
- + record.trail.count(STOP_EXAMPLE_NO_DISCARD_RECORD)
- + record.trail.count(DRAW_BITS_RECORD)
- )
+ self.__length = self.trail.count(
+ STOP_EXAMPLE_DISCARD_RECORD
+ ) + record.trail.count(STOP_EXAMPLE_NO_DISCARD_RECORD)
self.blocks = blocks
self.__children: "Optional[List[Sequence[int]]]" = None
@@ -649,18 +632,23 @@ class Examples:
class _mutator_groups(ExampleProperty):
def begin(self) -> None:
- self.groups: "Dict[Tuple[int, int], List[int]]" = defaultdict(list)
+ self.groups: "Dict[int, Set[Tuple[int, int]]]" = defaultdict(set)
def start_example(self, i: int, label_index: int) -> None:
- depth = len(self.example_stack)
- self.groups[label_index, depth].append(i)
+ # TODO should we discard start == end cases? occurs for eg st.data()
+ # which is conditionally or never drawn from. arguably swapping
+ # nodes with the empty list is a useful mutation enabled by start == end?
+ key = (self.examples[i].ir_start, self.examples[i].ir_end)
+ self.groups[label_index].add(key)
- def finish(self) -> Iterable[Iterable[int]]:
+ def finish(self) -> Iterable[Set[Tuple[int, int]]]:
# Discard groups with only one example, since the mutator can't
# do anything useful with them.
return [g for g in self.groups.values() if len(g) >= 2]
- mutator_groups: List[List[int]] = calculated_example_property(_mutator_groups)
+ mutator_groups: List[Set[Tuple[int, int]]] = calculated_example_property(
+ _mutator_groups
+ )
@property
def children(self) -> List[Sequence[int]]:
@@ -1338,7 +1326,6 @@ class HypothesisProvider(PrimitiveProvider):
size = 2**bits
- self._cd.start_example(BIASED_COIN_LABEL)
while True:
# The logic here is a bit complicated and special cased to make it
# play better with the shrinker.
@@ -1409,7 +1396,6 @@ class HypothesisProvider(PrimitiveProvider):
result = i > falsey
break
- self._cd.stop_example()
return result
def draw_integer(
@@ -1460,24 +1446,20 @@ class HypothesisProvider(PrimitiveProvider):
assert max_value is not None # make mypy happy
probe = max_value + 1
while max_value < probe:
- self._cd.start_example(ONE_BOUND_INTEGERS_LABEL)
probe = shrink_towards + self._draw_unbounded_integer(
forced=None if forced is None else forced - shrink_towards,
fake_forced=fake_forced,
)
- self._cd.stop_example()
return probe
if max_value is None:
assert min_value is not None
probe = min_value - 1
while probe < min_value:
- self._cd.start_example(ONE_BOUND_INTEGERS_LABEL)
probe = shrink_towards + self._draw_unbounded_integer(
forced=None if forced is None else forced - shrink_towards,
fake_forced=fake_forced,
)
- self._cd.stop_example()
return probe
return self._draw_bounded_integer(
@@ -1518,7 +1500,6 @@ class HypothesisProvider(PrimitiveProvider):
assert self._cd is not None
while True:
- self._cd.start_example(FLOAT_STRATEGY_DO_DRAW_LABEL)
# If `forced in nasty_floats`, then `forced` was *probably*
# generated by drawing a nonzero index from the sampler. However, we
# have no obligation to generate it that way when forcing. In particular,
@@ -1530,7 +1511,6 @@ class HypothesisProvider(PrimitiveProvider):
if sampler
else 0
)
- self._cd.start_example(DRAW_FLOAT_LABEL)
if i == 0:
result = self._draw_float(
forced_sign_bit=forced_sign_bit,
@@ -1546,8 +1526,6 @@ class HypothesisProvider(PrimitiveProvider):
assert pos_clamper is not None
clamped = pos_clamper(result)
if clamped != result and not (math.isnan(result) and allow_nan):
- self._cd.stop_example()
- self._cd.start_example(DRAW_FLOAT_LABEL)
self._draw_float(forced=clamped, fake_forced=fake_forced)
result = clamped
else:
@@ -1576,8 +1554,6 @@ class HypothesisProvider(PrimitiveProvider):
self._draw_float(forced=result, fake_forced=fake_forced)
- self._cd.stop_example() # (DRAW_FLOAT_LABEL)
- self._cd.stop_example() # (FLOAT_STRATEGY_DO_DRAW_LABEL)
return result
def draw_string(
@@ -1771,7 +1747,6 @@ class HypothesisProvider(PrimitiveProvider):
7 / 8, forced=None if forced is None else False, fake_forced=fake_forced
)
):
- self._cd.start_example(INTEGER_WEIGHTED_DISTRIBUTION)
# For large ranges, we combine the uniform random distribution from draw_bits
# with a weighting scheme with moderate chance. Cutoff at 2 ** 24 so that our
# choice of unicode characters is uniform but the 32bit distribution is not.
@@ -1782,18 +1757,15 @@ class HypothesisProvider(PrimitiveProvider):
upper=center if not above else min(upper, center + 2**force_bits - 1),
_vary_effective_size=False,
)
- self._cd.stop_example()
assert lower <= forced <= upper
while probe > gap:
- self._cd.start_example(INTEGER_RANGE_DRAW_LABEL)
probe = self._cd.draw_bits(
bits,
forced=None if forced is None else abs(forced - center),
fake_forced=fake_forced,
)
- self._cd.stop_example()
if above:
result = center + probe
@@ -1938,12 +1910,13 @@ class ConjectureData:
*,
observer: Optional[DataObserver] = None,
provider: Union[type, PrimitiveProvider] = HypothesisProvider,
+ max_length: Optional[int] = None,
) -> "ConjectureData":
from hypothesis.internal.conjecture.engine import BUFFER_SIZE
return cls(
- BUFFER_SIZE,
- b"",
+ max_length=BUFFER_SIZE if max_length is None else max_length,
+ prefix=b"",
random=None,
ir_tree_prefix=ir_tree_prefix,
observer=observer,
diff --git a/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/engine.py b/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/engine.py
index efeb284dbf..f1d29191ba 100644
--- a/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/engine.py
+++ b/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/engine.py
@@ -381,7 +381,7 @@ class ConjectureRunner:
self.__data_cache_ir[key] = result
def cached_test_function_ir(
- self, nodes: List[IRNode]
+ self, nodes: List[IRNode], *, error_on_discard: bool = False
) -> Union[ConjectureResult, _Overrun]:
key = self._cache_key_ir(nodes=nodes)
try:
@@ -389,8 +389,22 @@ class ConjectureRunner:
except KeyError:
pass
+ # explicitly use a no-op DataObserver here instead of a TreeRecordingObserver.
+ # The reason is we don't expect simulate_test_function to explore new choices
+ # and write back to the tree, so we don't want the overhead of the
+ # TreeRecordingObserver tracking those calls.
+ trial_observer: Optional[DataObserver] = DataObserver()
+ if error_on_discard:
+
+ class DiscardObserver(DataObserver):
+ @override
+ def kill_branch(self) -> NoReturn:
+ raise ContainsDiscard
+
+ trial_observer = DiscardObserver()
+
try:
- trial_data = self.new_conjecture_data_ir(nodes)
+ trial_data = self.new_conjecture_data_ir(nodes, observer=trial_observer)
self.tree.simulate_test_function(trial_data)
except PreviouslyUnseenBehaviour:
pass
@@ -1063,13 +1077,24 @@ class ConjectureRunner:
group = self.random.choice(groups)
- ex1, ex2 = (
- data.examples[i] for i in sorted(self.random.sample(group, 2))
- )
- assert ex1.end <= ex2.start
+ (start1, end1), (start2, end2) = self.random.sample(sorted(group), 2)
+ if (start1 <= start2 <= end2 <= end1) or (
+ start2 <= start1 <= end1 <= end2
+ ):
+ # one example entirely contains the other. give up.
+ # TODO use more intelligent mutation for containment, like
+ # replacing child with parent or vice versa. Would allow for
+ # recursive / subtree mutation
+ failed_mutations += 1
+ continue
- e = self.random.choice([ex1, ex2])
- replacement = data.buffer[e.start : e.end]
+ if start1 > start2:
+ (start1, end1), (start2, end2) = (start2, end2), (start1, end1)
+ assert end1 <= start2
+
+ nodes = data.examples.ir_tree_nodes
+ (start, end) = self.random.choice([(start1, end1), (start2, end2)])
+ replacement = nodes[start:end]
try:
# We attempt to replace both the examples with
@@ -1080,17 +1105,16 @@ class ConjectureRunner:
# really matter. It may not achieve the desired result,
# but it's still a perfectly acceptable choice sequence
# to try.
- new_data = self.cached_test_function(
- data.buffer[: ex1.start]
+ new_data = self.cached_test_function_ir(
+ nodes[:start1]
+ replacement
- + data.buffer[ex1.end : ex2.start]
+ + nodes[end1:start2]
+ replacement
- + data.buffer[ex2.end :],
+ + nodes[end2:],
# We set error_on_discard so that we don't end up
# entering parts of the tree we consider redundant
# and not worth exploring.
error_on_discard=True,
- extend=BUFFER_SIZE,
)
except ContainsDiscard:
failed_mutations += 1
@@ -1184,6 +1208,7 @@ class ConjectureRunner:
ir_tree_prefix: List[IRNode],
*,
observer: Optional[DataObserver] = None,
+ max_length: Optional[int] = None,
) -> ConjectureData:
provider = (
HypothesisProvider if self._switch_to_hypothesis_provider else self.provider
@@ -1193,7 +1218,7 @@ class ConjectureRunner:
observer = DataObserver()
return ConjectureData.for_ir_tree(
- ir_tree_prefix, observer=observer, provider=provider
+ ir_tree_prefix, observer=observer, provider=provider, max_length=max_length
)
def new_conjecture_data(
@@ -1331,7 +1356,6 @@ class ConjectureRunner:
self,
buffer: Union[bytes, bytearray],
*,
- error_on_discard: bool = False,
extend: int = 0,
) -> Union[ConjectureResult, _Overrun]:
"""Checks the tree to see if we've tested this buffer, and returns the
@@ -1370,18 +1394,7 @@ class ConjectureRunner:
except KeyError:
pass
- observer: DataObserver
- if error_on_discard:
-
- class DiscardObserver(DataObserver):
- @override
- def kill_branch(self) -> NoReturn:
- raise ContainsDiscard
-
- observer = DiscardObserver()
- else:
- observer = DataObserver()
-
+ observer = DataObserver()
dummy_data = self.new_conjecture_data(
prefix=buffer, max_length=max_length, observer=observer
)
diff --git a/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/optimiser.py b/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/optimiser.py
index 4594979199..2f8f761223 100644
--- a/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/optimiser.py
+++ b/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/optimiser.py
@@ -136,12 +136,12 @@ class Optimiser:
for i, ex in enumerate(self.current_data.examples):
if ex.start >= block.end:
- break
+ break # pragma: no cover
if ex.end <= block.start:
continue
ex_attempt = attempt.examples[i]
if ex.length == ex_attempt.length:
- continue
+ continue # pragma: no cover
replacement = attempt.buffer[ex_attempt.start : ex_attempt.end]
if self.consider_new_test_data(
self.engine.cached_test_function(
diff --git a/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/utils.py b/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/utils.py
index 509c03ef71..773324bc80 100644
--- a/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/utils.py
+++ b/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/utils.py
@@ -173,7 +173,8 @@ class Sampler:
forced: Optional[int] = None,
fake_forced: bool = False,
) -> int:
- data.start_example(SAMPLE_IN_SAMPLER_LABEL)
+ if self.observe:
+ data.start_example(SAMPLE_IN_SAMPLER_LABEL)
forced_choice = ( # pragma: no branch # https://github.com/nedbat/coveragepy/issues/1617
None
if forced is None
@@ -203,7 +204,8 @@ class Sampler:
fake_forced=fake_forced,
observe=self.observe,
)
- data.stop_example()
+ if self.observe:
+ data.stop_example()
if use_alternate:
assert forced is None or alternate == forced, (forced, alternate)
return alternate
@@ -254,15 +256,23 @@ class many:
self.rejected = False
self.observe = observe
+ def stop_example(self):
+ if self.observe:
+ self.data.stop_example()
+
+ def start_example(self, label):
+ if self.observe:
+ self.data.start_example(label)
+
def more(self) -> bool:
"""Should I draw another element to add to the collection?"""
if self.drawn:
- self.data.stop_example()
+ self.stop_example()
self.drawn = True
self.rejected = False
- self.data.start_example(ONE_FROM_MANY_LABEL)
+ self.start_example(ONE_FROM_MANY_LABEL)
if self.min_size == self.max_size:
# if we have to hit an exact size, draw unconditionally until that
# point, and no further.
@@ -291,7 +301,7 @@ class many:
self.count += 1
return True
else:
- self.data.stop_example()
+ self.stop_example()
return False
def reject(self, why: Optional[str] = None) -> None:
diff --git a/contrib/python/hypothesis/py3/hypothesis/version.py b/contrib/python/hypothesis/py3/hypothesis/version.py
index 0260a87746..86d564928e 100644
--- a/contrib/python/hypothesis/py3/hypothesis/version.py
+++ b/contrib/python/hypothesis/py3/hypothesis/version.py
@@ -8,5 +8,5 @@
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at https://mozilla.org/MPL/2.0/.
-__version_info__ = (6, 103, 1)
+__version_info__ = (6, 103, 2)
__version__ = ".".join(map(str, __version_info__))
diff --git a/contrib/python/hypothesis/py3/ya.make b/contrib/python/hypothesis/py3/ya.make
index c1289cb94f..715f22994a 100644
--- a/contrib/python/hypothesis/py3/ya.make
+++ b/contrib/python/hypothesis/py3/ya.make
@@ -2,7 +2,7 @@
PY3_LIBRARY()
-VERSION(6.103.1)
+VERSION(6.103.2)
LICENSE(MPL-2.0)
diff --git a/contrib/python/responses/py3/.dist-info/METADATA b/contrib/python/responses/py3/.dist-info/METADATA
index c12dde8ca8..7085a1a9f0 100644
--- a/contrib/python/responses/py3/.dist-info/METADATA
+++ b/contrib/python/responses/py3/.dist-info/METADATA
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: responses
-Version: 0.25.2
+Version: 0.25.3
Summary: A utility library for mocking out the `requests` Python library.
Home-page: https://github.com/getsentry/responses
Author: David Cramer
diff --git a/contrib/python/responses/py3/responses/__init__.py b/contrib/python/responses/py3/responses/__init__.py
index 8c12345a60..097e61ee99 100644
--- a/contrib/python/responses/py3/responses/__init__.py
+++ b/contrib/python/responses/py3/responses/__init__.py
@@ -814,7 +814,11 @@ class RequestsMock:
if adding_headers is not None:
kwargs.setdefault("headers", adding_headers)
- if "content_type" in kwargs and "headers" in kwargs:
+ if (
+ "content_type" in kwargs
+ and "headers" in kwargs
+ and kwargs["headers"] is not None
+ ):
header_keys = [header.lower() for header in kwargs["headers"]]
if "content-type" in header_keys:
raise RuntimeError(
@@ -852,6 +856,7 @@ class RequestsMock:
url=rsp["url"],
body=rsp["body"],
status=rsp["status"],
+ headers=rsp["headers"] if "headers" in rsp else None,
content_type=rsp["content_type"],
auto_calculate_content_length=rsp["auto_calculate_content_length"],
)
diff --git a/contrib/python/responses/py3/responses/_recorder.py b/contrib/python/responses/py3/responses/_recorder.py
index a533e8489a..64533e2972 100644
--- a/contrib/python/responses/py3/responses/_recorder.py
+++ b/contrib/python/responses/py3/responses/_recorder.py
@@ -36,6 +36,29 @@ def _remove_nones(d: "Any") -> "Any":
return d
+def _remove_default_headers(data: "Any") -> "Any":
+ """
+ It would be too verbose to store these headers in the file generated by the
+ record functionality.
+ """
+ if isinstance(data, dict):
+ keys_to_remove = [
+ "Content-Length",
+ "Content-Type",
+ "Date",
+ "Server",
+ "Connection",
+ "Content-Encoding",
+ ]
+ for i, response in enumerate(data["responses"]):
+ for key in keys_to_remove:
+ if key in response["response"]["headers"]:
+ del data["responses"][i]["response"]["headers"][key]
+ if not response["response"]["headers"]:
+ del data["responses"][i]["response"]["headers"]
+ return data
+
+
def _dump(
registered: "List[BaseResponse]",
destination: "Union[BinaryIO, TextIOWrapper]",
@@ -63,7 +86,8 @@ def _dump(
"Cannot dump response object."
"Probably you use custom Response object that is missing required attributes"
) from exc
- dumper(_remove_nones(data), destination)
+
+ dumper(_remove_default_headers(_remove_nones(data)), destination)
class Recorder(RequestsMock):
@@ -116,11 +140,15 @@ class Recorder(RequestsMock):
request.params = self._parse_request_params(request.path_url) # type: ignore[attr-defined]
request.req_kwargs = kwargs # type: ignore[attr-defined]
requests_response = _real_send(adapter, request, **kwargs)
+ headers_values = {
+ key: value for key, value in requests_response.headers.items()
+ }
responses_response = Response(
method=str(request.method),
url=str(requests_response.request.url),
status=requests_response.status_code,
body=requests_response.text,
+ headers=headers_values,
)
self._registry.add(responses_response)
return requests_response
diff --git a/contrib/python/responses/py3/ya.make b/contrib/python/responses/py3/ya.make
index 04114979d9..262b9ef33f 100644
--- a/contrib/python/responses/py3/ya.make
+++ b/contrib/python/responses/py3/ya.make
@@ -2,7 +2,7 @@
PY3_LIBRARY()
-VERSION(0.25.2)
+VERSION(0.25.3)
LICENSE(Apache-2.0)