diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-08-26 10:39:01 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-08-26 10:46:18 +0300 |
commit | 17f1572f6e7ea46a6cdf4b43b6f2445ad5e053c9 (patch) | |
tree | 41ed517fbe9fe5a82766289802769f33f13f68e3 /contrib/python/hypothesis/py3 | |
parent | 9cd5c4ca8b08287c6c01762a11f5ce5ad87d39eb (diff) | |
download | ydb-17f1572f6e7ea46a6cdf4b43b6f2445ad5e053c9.tar.gz |
Intermediate changes
Diffstat (limited to 'contrib/python/hypothesis/py3')
6 files changed, 68 insertions, 17 deletions
diff --git a/contrib/python/hypothesis/py3/.dist-info/METADATA b/contrib/python/hypothesis/py3/.dist-info/METADATA index 8b3d585d4b..accf483679 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.110.2 +Version: 6.111.0 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 6b443a1427..304ba614d0 100644 --- a/contrib/python/hypothesis/py3/hypothesis/core.py +++ b/contrib/python/hypothesis/py3/hypothesis/core.py @@ -77,7 +77,11 @@ from hypothesis.internal.compat import ( get_type_hints, int_from_bytes, ) -from hypothesis.internal.conjecture.data import ConjectureData, Status +from hypothesis.internal.conjecture.data import ( + ConjectureData, + PrimitiveProvider, + Status, +) from hypothesis.internal.conjecture.engine import BUFFER_SIZE, ConjectureRunner from hypothesis.internal.conjecture.junkdrawer import ( ensure_free_stackframes, @@ -1132,10 +1136,28 @@ class StateForActualGivenExecution: timing=self._timing_features, coverage=tractable_coverage_report(trace) or None, phase=phase, + backend_metadata=data.provider.observe_test_case(), ) deliver_json_blob(tc) + for msg in data.provider.observe_information_messages( + lifetime="test_case" + ): + self._deliver_information_message(**msg) self._timing_features = {} + def _deliver_information_message( + self, *, type: str, title: str, content: Union[str, dict] + ) -> None: + deliver_json_blob( + { + "type": type, + "run_start": self._start_timestamp, + "property": self.test_identifier, + "title": title, + "content": content, + } + ) + def run_engine(self): """Run the test function many times, on database input and generated input, using the Conjecture engine. @@ -1160,15 +1182,16 @@ class StateForActualGivenExecution: # on different inputs. runner.run() note_statistics(runner.statistics) - deliver_json_blob( - { - "type": "info", - "run_start": self._start_timestamp, - "property": self.test_identifier, - "title": "Hypothesis Statistics", - "content": describe_statistics(runner.statistics), - } - ) + if TESTCASE_CALLBACKS: + self._deliver_information_message( + type="info", + title="Hypothesis Statistics", + content=describe_statistics(runner.statistics), + ) + for msg in ( + p if isinstance(p := runner.provider, PrimitiveProvider) else p(None) + ).observe_information_messages(lifetime="test_function"): + self._deliver_information_message(**msg) if runner.call_count == 0: return diff --git a/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/data.py b/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/data.py index 40aad2e850..4661141544 100644 --- a/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/data.py +++ b/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/data.py @@ -1186,6 +1186,14 @@ class ConjectureResult: BYTE_MASKS = [(1 << n) - 1 for n in range(8)] BYTE_MASKS[0] = 255 +_Lifetime: TypeAlias = Literal["test_case", "test_function"] + + +class _BackendInfoMsg(TypedDict): + type: str + title: str + content: Union[str, Dict[str, Any]] + class PrimitiveProvider(abc.ABC): # This is the low-level interface which would also be implemented @@ -1212,7 +1220,7 @@ class PrimitiveProvider(abc.ABC): # lifetime can access the passed ConjectureData object. # # Non-hypothesis providers probably want to set a lifetime of test_function. - lifetime = "test_function" + lifetime: _Lifetime = "test_function" # Solver-based backends such as hypothesis-crosshair use symbolic values # which record operations performed on them in order to discover new paths. @@ -1240,9 +1248,28 @@ class PrimitiveProvider(abc.ABC): The returned value should be non-symbolic. """ - return value + def observe_test_case(self) -> Dict[str, Any]: + """Called at the end of the test case when observability mode is active. + + The return value should be a non-symbolic json-encodable dictionary, + and will be included as `observation["metadata"]["backend"]`. + """ + return {} + + def observe_information_messages( + self, *, lifetime: _Lifetime + ) -> Iterable[_BackendInfoMsg]: + """Called at the end of each test case and again at end of the test function. + + Return an iterable of `{type: info/alert/error, title: str, content: str|dict}` + dictionaries to be delivered as individual information messages. + (Hypothesis adds the `run_start` timestamp and `property` name for you.) + """ + assert lifetime in ("test_case", "test_function") + yield from [] + @abc.abstractmethod def draw_boolean( self, @@ -1307,7 +1334,6 @@ class HypothesisProvider(PrimitiveProvider): lifetime = "test_case" def __init__(self, conjecturedata: Optional["ConjectureData"], /): - assert conjecturedata is not None super().__init__(conjecturedata) def draw_boolean( diff --git a/contrib/python/hypothesis/py3/hypothesis/internal/observability.py b/contrib/python/hypothesis/py3/hypothesis/internal/observability.py index a532d054cd..f8b922dfca 100644 --- a/contrib/python/hypothesis/py3/hypothesis/internal/observability.py +++ b/contrib/python/hypothesis/py3/hypothesis/internal/observability.py @@ -17,7 +17,7 @@ import time import warnings from datetime import date, timedelta from functools import lru_cache -from typing import Callable, Dict, List, Optional +from typing import Any, Callable, Dict, List, Optional from hypothesis.configuration import storage_directory from hypothesis.errors import HypothesisWarning @@ -42,6 +42,7 @@ def make_testcase( timing: Dict[str, float], coverage: Optional[Dict[str, List[int]]] = None, phase: Optional[str] = None, + backend_metadata: Optional[Dict[str, Any]] = None, ) -> dict: if data.interesting_origin: status_reason = str(data.interesting_origin) @@ -74,6 +75,7 @@ def make_testcase( "metadata": { "traceback": getattr(data.extra_information, "_expected_traceback", None), "predicates": data._observability_predicates, + "backend": backend_metadata or {}, **_system_metadata(), }, "coverage": coverage, diff --git a/contrib/python/hypothesis/py3/hypothesis/version.py b/contrib/python/hypothesis/py3/hypothesis/version.py index 0c7cb254d5..3f18637632 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, 110, 2) +__version_info__ = (6, 111, 0) __version__ = ".".join(map(str, __version_info__)) diff --git a/contrib/python/hypothesis/py3/ya.make b/contrib/python/hypothesis/py3/ya.make index 8113ee865a..21fbb328a7 100644 --- a/contrib/python/hypothesis/py3/ya.make +++ b/contrib/python/hypothesis/py3/ya.make @@ -2,7 +2,7 @@ PY3_LIBRARY() -VERSION(6.110.2) +VERSION(6.111.0) LICENSE(MPL-2.0) |