diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-07-09 08:58:14 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-07-09 09:07:46 +0300 |
commit | 749e098320dd9c0f8bf27fa600bf8cde20dac080 (patch) | |
tree | f671dfdef5328069a1120dd39928c0de5fe3f035 /contrib/python/hypothesis | |
parent | e01ebe0f63993394f721cc48adfd7e169ba4c709 (diff) | |
download | ydb-749e098320dd9c0f8bf27fa600bf8cde20dac080.tar.gz |
Intermediate changes
Diffstat (limited to 'contrib/python/hypothesis')
12 files changed, 98 insertions, 18 deletions
diff --git a/contrib/python/hypothesis/py3/.dist-info/METADATA b/contrib/python/hypothesis/py3/.dist-info/METADATA index ad18a5c15f..cd866b19e8 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.2 +Version: 6.104.0 Summary: A library for property-based testing Home-page: https://hypothesis.works Author: David R. MacIver and Zac Hatfield-Dodds @@ -41,7 +41,7 @@ Requires-Dist: exceptiongroup >=1.0.0 ; python_version < "3.11" Provides-Extra: all Requires-Dist: black >=19.10b0 ; extra == 'all' Requires-Dist: click >=7.0 ; extra == 'all' -Requires-Dist: crosshair-tool >=0.0.54 ; extra == 'all' +Requires-Dist: crosshair-tool >=0.0.55 ; extra == 'all' Requires-Dist: django >=3.2 ; extra == 'all' Requires-Dist: dpcontracts >=0.4 ; extra == 'all' Requires-Dist: hypothesis-crosshair >=0.0.4 ; extra == 'all' @@ -64,7 +64,7 @@ Provides-Extra: codemods Requires-Dist: libcst >=0.3.16 ; extra == 'codemods' Provides-Extra: crosshair Requires-Dist: hypothesis-crosshair >=0.0.4 ; extra == 'crosshair' -Requires-Dist: crosshair-tool >=0.0.54 ; extra == 'crosshair' +Requires-Dist: crosshair-tool >=0.0.55 ; extra == 'crosshair' Provides-Extra: dateutil Requires-Dist: python-dateutil >=1.4 ; extra == 'dateutil' Provides-Extra: django diff --git a/contrib/python/hypothesis/py3/hypothesis/core.py b/contrib/python/hypothesis/py3/hypothesis/core.py index 9af0381fea..759d9b5afc 100644 --- a/contrib/python/hypothesis/py3/hypothesis/core.py +++ b/contrib/python/hypothesis/py3/hypothesis/core.py @@ -1104,7 +1104,9 @@ class StateForActualGivenExecution: if TESTCASE_CALLBACKS: if runner := getattr(self, "_runner", None): phase = runner._current_phase - elif self.failed_normally or self.failed_due_to_deadline: + elif ( + self.failed_normally or self.failed_due_to_deadline + ): # pragma: no cover # FIXME phase = "shrink" else: # pragma: no cover # in case of messing with internals phase = "unknown" diff --git a/contrib/python/hypothesis/py3/hypothesis/extra/_patching.py b/contrib/python/hypothesis/py3/hypothesis/extra/_patching.py index d3678e3f9f..b8fbfa3c7a 100644 --- a/contrib/python/hypothesis/py3/hypothesis/extra/_patching.py +++ b/contrib/python/hypothesis/py3/hypothesis/extra/_patching.py @@ -121,7 +121,7 @@ class AddExamplesCodemod(VisitorBasedCodemodCommand): cst.Module([]).code_for_node(via), mode=black.FileMode(line_length=self.line_length), ) - except (ImportError, AttributeError): + except (ImportError, AttributeError): # pragma: no cover return None # See https://github.com/psf/black/pull/4224 via = cst.parse_expression(pretty.strip()) return cst.Decorator(via) diff --git a/contrib/python/hypothesis/py3/hypothesis/extra/django/_fields.py b/contrib/python/hypothesis/py3/hypothesis/extra/django/_fields.py index b4a574d69d..181c8869f9 100644 --- a/contrib/python/hypothesis/py3/hypothesis/extra/django/_fields.py +++ b/contrib/python/hypothesis/py3/hypothesis/extra/django/_fields.py @@ -262,6 +262,55 @@ def _for_form_boolean(field): return st.booleans() +def _model_choice_strategy(field): + def _strategy(): + if field.choices is None: + # The field was instantiated with queryset=None, and not + # subsequently updated. + raise InvalidArgument( + "Cannot create strategy for ModelChoicesField with no choices" + ) + elif hasattr(field, "_choices"): + # The choices property was set manually. + choices = field._choices + else: + # choices is not None, and was not set manually, so we + # must have a QuerySet. + choices = field.queryset + + if not choices.ordered: + raise InvalidArgument( + f"Cannot create strategy for {field.__class__.__name__} with a choices " + "attribute derived from a QuerySet without an explicit ordering - this may " + "cause Hypothesis to produce unstable results between runs." + ) + + return st.sampled_from( + [ + ( + choice.value + if isinstance(choice, df.models.ModelChoiceIteratorValue) + else choice # Empty value, if included. + ) + for choice, _ in field.choices + ] + ) + + # Accessing field.choices causes database access, so defer the strategy. + return st.deferred(_strategy) + + +@register_for(df.ModelChoiceField) +def _for_model_choice(field): + return _model_choice_strategy(field) + + +@register_for(df.ModelMultipleChoiceField) +def _for_model_multiple_choice(field): + min_size = 1 if field.required else 0 + return st.lists(_model_choice_strategy(field), min_size=min_size, unique=True) + + def register_field_strategy( field_type: Type[AnyField], strategy: st.SearchStrategy ) -> None: @@ -299,7 +348,13 @@ def from_field(field: F) -> st.SearchStrategy[Union[F, None]]: instance attributes such as string length and validators. """ check_type((dm.Field, df.Field), field, "field") - if getattr(field, "choices", False): + + # The following isinstance check must occur *before* the getattr + # check. In the case of ModelChoicesField, evaluating + # field.choices causes database access, which we want to avoid if + # we don't have a connection (the generated strategies for + # ModelChoicesField defer evaluation of `choices'). + if not isinstance(field, df.ModelChoiceField) and getattr(field, "choices", False): choices: list = [] for value, name_or_optgroup in field.choices: if isinstance(name_or_optgroup, (list, tuple)): diff --git a/contrib/python/hypothesis/py3/hypothesis/extra/numpy.py b/contrib/python/hypothesis/py3/hypothesis/extra/numpy.py index 9edca6ee00..3754192d70 100644 --- a/contrib/python/hypothesis/py3/hypothesis/extra/numpy.py +++ b/contrib/python/hypothesis/py3/hypothesis/extra/numpy.py @@ -1103,7 +1103,7 @@ def basic_indices( allow_newaxis: bool = False, allow_ellipsis: bool = True, ) -> st.SearchStrategy[BasicIndex]: - """Return a strategy for :doc:`basic indexes <numpy:reference/arrays.indexing>` of + """Return a strategy for :doc:`basic indexes <numpy:reference/routines.indexing>` of arrays with the specified shape, which may include dimensions of size zero. It generates tuples containing some mix of integers, :obj:`python:slice` diff --git a/contrib/python/hypothesis/py3/hypothesis/internal/cache.py b/contrib/python/hypothesis/py3/hypothesis/internal/cache.py index 86241d3737..eae61a2578 100644 --- a/contrib/python/hypothesis/py3/hypothesis/internal/cache.py +++ b/contrib/python/hypothesis/py3/hypothesis/internal/cache.py @@ -8,6 +8,8 @@ # 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/. +import threading + import attr @@ -51,7 +53,7 @@ class GenericCache: on_access and on_evict to implement a specific scoring strategy. """ - __slots__ = ("keys_to_indices", "data", "max_size", "__pinned_entry_count") + __slots__ = ("max_size", "_threadlocal") def __init__(self, max_size): self.max_size = max_size @@ -61,9 +63,31 @@ class GenericCache: # its children. keys_to_index then maps keys to their index in the # heap. We keep these two in sync automatically - the heap is never # reordered without updating the index. - self.keys_to_indices = {} - self.data = [] - self.__pinned_entry_count = 0 + self._threadlocal = threading.local() + + @property + def keys_to_indices(self): + try: + return self._threadlocal.keys_to_indices + except AttributeError: + self._threadlocal.keys_to_indices = {} + return self._threadlocal.keys_to_indices + + @property + def data(self): + try: + return self._threadlocal.data + except AttributeError: + self._threadlocal.data = [] + return self._threadlocal.data + + @property + def __pinned_entry_count(self): + return getattr(self._threadlocal, "_pinned_entry_count", 0) + + @__pinned_entry_count.setter + def __pinned_entry_count(self, value): + self._threadlocal._pinned_entry_count = value def __len__(self): assert len(self.keys_to_indices) == len(self.data) diff --git a/contrib/python/hypothesis/py3/hypothesis/internal/entropy.py b/contrib/python/hypothesis/py3/hypothesis/internal/entropy.py index 6e4a30b99a..eedd5919dc 100644 --- a/contrib/python/hypothesis/py3/hypothesis/internal/entropy.py +++ b/contrib/python/hypothesis/py3/hypothesis/internal/entropy.py @@ -127,7 +127,7 @@ def register_random(r: RandomLike) -> None: "PRNG. See the docs for `register_random` for more " "details." ) - elif not FREE_THREADED_CPYTHON: + elif not FREE_THREADED_CPYTHON: # pragma: no cover # FIXME # On CPython, check for the free-threaded build because # gc.get_referrers() ignores objects with immortal refcounts # and objects are immortalized in the Python 3.13 diff --git a/contrib/python/hypothesis/py3/hypothesis/stateful.py b/contrib/python/hypothesis/py3/hypothesis/stateful.py index 067d9c77c6..0cdf33dd38 100644 --- a/contrib/python/hypothesis/py3/hypothesis/stateful.py +++ b/contrib/python/hypothesis/py3/hypothesis/stateful.py @@ -388,7 +388,7 @@ class RuleBasedStateMachine(metaclass=StateMachineMeta): for target in targets: name = self._new_name(target) - def printer(obj, p, cycle, name=name): + def printer(obj, p, cycle, name=name): # pragma: no cover # FIXME return p.text(name) self.__printer.singleton_pprinters.setdefault(id(result), printer) diff --git a/contrib/python/hypothesis/py3/hypothesis/statistics.py b/contrib/python/hypothesis/py3/hypothesis/statistics.py index 7425db7bcb..465c92e9c1 100644 --- a/contrib/python/hypothesis/py3/hypothesis/statistics.py +++ b/contrib/python/hypothesis/py3/hypothesis/statistics.py @@ -48,7 +48,7 @@ def format_ms(times): """ ordered = sorted(times) n = len(ordered) - 1 - if n < 0 or any(math.isnan(t) for t in ordered): + if n < 0 or any(math.isnan(t) for t in ordered): # pragma: no cover return "NaN ms" lower = int(ordered[int(math.floor(n * 0.05))] * 1000) upper = int(ordered[int(math.ceil(n * 0.95))] * 1000) diff --git a/contrib/python/hypothesis/py3/hypothesis/vendor/tlds-alpha-by-domain.txt b/contrib/python/hypothesis/py3/hypothesis/vendor/tlds-alpha-by-domain.txt index 08ad35057e..503af0851b 100644 --- a/contrib/python/hypothesis/py3/hypothesis/vendor/tlds-alpha-by-domain.txt +++ b/contrib/python/hypothesis/py3/hypothesis/vendor/tlds-alpha-by-domain.txt @@ -1,4 +1,4 @@ -# Version 2024033000, Last Updated Sat Mar 30 07:07:01 2024 UTC +# Version 2024062300, Last Updated Sun Jun 23 07:07:01 2024 UTC AAA AARP ABB @@ -802,7 +802,6 @@ NA NAB NAGOYA NAME -NATURA NAVY NBA NC diff --git a/contrib/python/hypothesis/py3/hypothesis/version.py b/contrib/python/hypothesis/py3/hypothesis/version.py index 86d564928e..fff67d6291 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, 2) +__version_info__ = (6, 104, 0) __version__ = ".".join(map(str, __version_info__)) diff --git a/contrib/python/hypothesis/py3/ya.make b/contrib/python/hypothesis/py3/ya.make index 715f22994a..8bd9ebb97a 100644 --- a/contrib/python/hypothesis/py3/ya.make +++ b/contrib/python/hypothesis/py3/ya.make @@ -2,7 +2,7 @@ PY3_LIBRARY() -VERSION(6.103.2) +VERSION(6.104.0) LICENSE(MPL-2.0) |