aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/hypothesis
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2024-03-05 14:54:25 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2024-03-05 15:05:44 +0300
commitf6c02fde7bd26b2e3f57a32972f9aa1e47144be8 (patch)
tree0c89e1977d3d3c394b11dfea2932e40c8445837a /contrib/python/hypothesis
parent274118e9de20923d783e4ec247dfbc8a63a86c8e (diff)
downloadydb-f6c02fde7bd26b2e3f57a32972f9aa1e47144be8.tar.gz
Intermediate changes
Diffstat (limited to 'contrib/python/hypothesis')
-rw-r--r--contrib/python/hypothesis/py3/.dist-info/METADATA2
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/core.py13
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/internal/conjecture/data.py4
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/internal/observability.py3
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/stateful.py55
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/version.py2
-rw-r--r--contrib/python/hypothesis/py3/ya.make2
7 files changed, 56 insertions, 25 deletions
diff --git a/contrib/python/hypothesis/py3/.dist-info/METADATA b/contrib/python/hypothesis/py3/.dist-info/METADATA
index 26ae8b8481..d883f6dec6 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.98.8
+Version: 6.98.9
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/core.py b/contrib/python/hypothesis/py3/hypothesis/core.py
index e000da174f..536d7f0156 100644
--- a/contrib/python/hypothesis/py3/hypothesis/core.py
+++ b/contrib/python/hypothesis/py3/hypothesis/core.py
@@ -834,8 +834,9 @@ class StateForActualGivenExecution:
in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime
runtime = datetime.timedelta(seconds=finish - start - in_drawtime)
self._timing_features = {
- "execute_test": finish - start - in_drawtime,
+ "execute:test": finish - start - in_drawtime,
**data.draw_times,
+ **data._stateful_run_times,
}
if (current_deadline := self.settings.deadline) is not None:
@@ -927,6 +928,9 @@ class StateForActualGivenExecution:
msg, format_arg = data._sampled_from_all_strategies_elements_message
add_note(e, msg.format(format_arg))
raise
+ finally:
+ if parts := getattr(data, "_stateful_repr_parts", None):
+ self._string_repr = "\n".join(parts)
# self.test_runner can include the execute_example method, or setup/teardown
# _example, so it's important to get the PRNG and build context in place first.
@@ -942,7 +946,11 @@ class StateForActualGivenExecution:
if expected_failure is not None:
exception, traceback = expected_failure
if isinstance(exception, DeadlineExceeded) and (
- runtime_secs := self._timing_features.get("execute_test")
+ runtime_secs := math.fsum(
+ v
+ for k, v in self._timing_features.items()
+ if k.startswith("execute:")
+ )
):
report(
"Unreliable test timings! On an initial run, this "
@@ -1068,6 +1076,7 @@ class StateForActualGivenExecution:
arguments={**self._jsonable_arguments, **data._observability_args},
timing=self._timing_features,
coverage=tractable_coverage_report(trace) or None,
+ phase=phase,
)
deliver_json_blob(tc)
self._timing_features = {}
diff --git a/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/data.py b/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/data.py
index cea40823be..0016f2fa1a 100644
--- a/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/data.py
+++ b/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/data.py
@@ -18,6 +18,7 @@ from typing import (
TYPE_CHECKING,
Any,
Callable,
+ DefaultDict,
Dict,
FrozenSet,
Iterable,
@@ -1468,6 +1469,7 @@ class ConjectureData:
self.forced_indices: "Set[int]" = set()
self.interesting_origin: Optional[InterestingOrigin] = None
self.draw_times: "Dict[str, float]" = {}
+ self._stateful_run_times: "DefaultDict[str, float]" = defaultdict(float)
self.max_depth = 0
self.has_discards = False
self.provider = PrimitiveProvider(self)
@@ -1752,7 +1754,7 @@ class ConjectureData:
try:
return strategy.do_draw(self)
finally:
- key = observe_as or f"unlabeled_{len(self.draw_times)}"
+ key = observe_as or f"generate:unlabeled_{len(self.draw_times)}"
self.draw_times[key] = time.perf_counter() - start_time
finally:
self.stop_example()
diff --git a/contrib/python/hypothesis/py3/hypothesis/internal/observability.py b/contrib/python/hypothesis/py3/hypothesis/internal/observability.py
index 98753985f1..aff19d805c 100644
--- a/contrib/python/hypothesis/py3/hypothesis/internal/observability.py
+++ b/contrib/python/hypothesis/py3/hypothesis/internal/observability.py
@@ -41,9 +41,12 @@ def make_testcase(
arguments: Optional[dict] = None,
timing: Dict[str, float],
coverage: Optional[Dict[str, List[int]]] = None,
+ phase: Optional[str] = None,
) -> dict:
if data.interesting_origin:
status_reason = str(data.interesting_origin)
+ elif phase == "shrink" and data.status == Status.OVERRUN:
+ status_reason = "exceeded size of current best example"
else:
status_reason = str(data.events.pop("invalid because", ""))
diff --git a/contrib/python/hypothesis/py3/hypothesis/stateful.py b/contrib/python/hypothesis/py3/hypothesis/stateful.py
index 2ae5815161..bf7271fc4c 100644
--- a/contrib/python/hypothesis/py3/hypothesis/stateful.py
+++ b/contrib/python/hypothesis/py3/hypothesis/stateful.py
@@ -20,6 +20,7 @@ import inspect
from copy import copy
from functools import lru_cache
from io import StringIO
+from time import perf_counter
from typing import (
Any,
Callable,
@@ -48,6 +49,7 @@ from hypothesis.core import TestFunc, given
from hypothesis.errors import InvalidArgument, InvalidDefinition
from hypothesis.internal.conjecture import utils as cu
from hypothesis.internal.healthcheck import fail_health_check
+from hypothesis.internal.observability import TESTCASE_CALLBACKS
from hypothesis.internal.reflection import (
function_digest,
get_pretty_function_description,
@@ -121,10 +123,17 @@ def run_state_machine_as_test(state_machine_factory, *, settings=None, _min_step
print_steps = (
current_build_context().is_final or current_verbosity() >= Verbosity.debug
)
- try:
+ cd._stateful_repr_parts = []
+
+ def output(s):
if print_steps:
- report(f"state = {machine.__class__.__name__}()")
- machine.check_invariants(settings)
+ report(s)
+ if TESTCASE_CALLBACKS:
+ cd._stateful_repr_parts.append(s)
+
+ try:
+ output(f"state = {machine.__class__.__name__}()")
+ machine.check_invariants(settings, output, cd._stateful_run_times)
max_steps = settings.stateful_step_count
steps_run = 0
@@ -141,6 +150,8 @@ def run_state_machine_as_test(state_machine_factory, *, settings=None, _min_step
must_stop = True
elif steps_run <= _min_steps:
must_stop = False
+
+ start_draw = perf_counter()
if cd.draw_boolean(p=2**-16, forced=must_stop):
break
steps_run += 1
@@ -156,12 +167,15 @@ def run_state_machine_as_test(state_machine_factory, *, settings=None, _min_step
machine._initialize_rules_to_run.remove(rule)
else:
rule, data = cd.draw(machine._rules_strategy)
+ draw_label = f"generate:rule:{rule.function.__name__}"
+ cd.draw_times.setdefault(draw_label, 0.0)
+ cd.draw_times[draw_label] += perf_counter() - start_draw
# Pretty-print the values this rule was called with *before* calling
# _add_result_to_targets, to avoid printing arguments which are also
# a return value using the variable name they are assigned to.
# See https://github.com/HypothesisWorks/hypothesis/issues/2341
- if print_steps:
+ if print_steps or TESTCASE_CALLBACKS:
data_to_print = {
k: machine._pretty_print(v) for k, v in data.items()
}
@@ -173,7 +187,12 @@ def run_state_machine_as_test(state_machine_factory, *, settings=None, _min_step
for k, v in list(data.items()):
if isinstance(v, VarReference):
data[k] = machine.names_to_values[v.name]
+
+ label = f"execute:rule:{rule.function.__name__}"
+ start = perf_counter()
result = rule.function(machine, **data)
+ cd._stateful_run_times[label] += perf_counter() - start
+
if rule.targets:
if isinstance(result, MultipleResults):
for single_result in result.values:
@@ -190,16 +209,15 @@ def run_state_machine_as_test(state_machine_factory, *, settings=None, _min_step
HealthCheck.return_value,
)
finally:
- if print_steps:
+ if print_steps or TESTCASE_CALLBACKS:
# 'result' is only used if the step has target bundles.
# If it does, and the result is a 'MultipleResult',
# then 'print_step' prints a multi-variable assignment.
- machine._print_step(rule, data_to_print, result)
- machine.check_invariants(settings)
+ output(machine._repr_step(rule, data_to_print, result))
+ machine.check_invariants(settings, output, cd._stateful_run_times)
cd.stop_example()
finally:
- if print_steps:
- report("state.teardown()")
+ output("state.teardown()")
machine.teardown()
# Use a machine digest to identify stateful tests in the example database
@@ -338,7 +356,7 @@ class RuleBasedStateMachine(metaclass=StateMachineMeta):
cls._invariants_per_class[cls] = target
return cls._invariants_per_class[cls]
- def _print_step(self, rule, data, result):
+ def _repr_step(self, rule, data, result):
self.step_count = getattr(self, "step_count", 0) + 1
output_assignment = ""
if rule.targets:
@@ -350,13 +368,8 @@ class RuleBasedStateMachine(metaclass=StateMachineMeta):
output_assignment = ", ".join(output_names) + " = "
else:
output_assignment = self._last_names(1)[0] + " = "
- report(
- "{}state.{}({})".format(
- output_assignment,
- rule.function.__name__,
- ", ".join("%s=%s" % kv for kv in data.items()),
- )
- )
+ args = ", ".join("%s=%s" % kv for kv in data.items())
+ return f"{output_assignment}state.{rule.function.__name__}({args})"
def _add_result_to_targets(self, targets, result):
name = self._new_name()
@@ -367,18 +380,22 @@ class RuleBasedStateMachine(metaclass=StateMachineMeta):
for target in targets:
self.bundles.setdefault(target, []).append(VarReference(name))
- def check_invariants(self, settings):
+ def check_invariants(self, settings, output, runtimes):
for invar in self.invariants():
if self._initialize_rules_to_run and not invar.check_during_init:
continue
if not all(precond(self) for precond in invar.preconditions):
continue
+ name = invar.function.__name__
if (
current_build_context().is_final
or settings.verbosity >= Verbosity.debug
+ or TESTCASE_CALLBACKS
):
- report(f"state.{invar.function.__name__}()")
+ output(f"state.{name}()")
+ start = perf_counter()
result = invar.function(self)
+ runtimes[f"execute:invariant:{name}"] += perf_counter() - start
if result is not None:
fail_health_check(
settings,
diff --git a/contrib/python/hypothesis/py3/hypothesis/version.py b/contrib/python/hypothesis/py3/hypothesis/version.py
index 6aafd5421c..f54f8dc42f 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, 98, 8)
+__version_info__ = (6, 98, 9)
__version__ = ".".join(map(str, __version_info__))
diff --git a/contrib/python/hypothesis/py3/ya.make b/contrib/python/hypothesis/py3/ya.make
index 1678e159c9..89269430da 100644
--- a/contrib/python/hypothesis/py3/ya.make
+++ b/contrib/python/hypothesis/py3/ya.make
@@ -2,7 +2,7 @@
PY3_LIBRARY()
-VERSION(6.98.8)
+VERSION(6.98.9)
LICENSE(MPL-2.0)