From 6b963450593c3ff646d5c432e2521d874cbecdbc Mon Sep 17 00:00:00 2001 From: Paul Ganssle Date: Thu, 13 May 2021 10:36:38 -0400 Subject: [PATCH] fixup! Add stubs for hypothesis tests --- .../support/_hypothesis_stubs/__init__.py | 40 ++++++++++++++++++- Lib/test/support/_hypothesis_stubs/control.py | 10 ----- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/Lib/test/support/_hypothesis_stubs/__init__.py b/Lib/test/support/_hypothesis_stubs/__init__.py index c1661b16ab3013c..edf9e2b49354534 100644 --- a/Lib/test/support/_hypothesis_stubs/__init__.py +++ b/Lib/test/support/_hypothesis_stubs/__init__.py @@ -1,3 +1,4 @@ +from enum import Enum import functools import unittest @@ -14,8 +15,6 @@ ] from . import strategies -from ._settings import HealthCheck, Verbosity, settings -from .control import assume, reject def given(*_args, **_kwargs): @@ -29,6 +28,9 @@ def test_function(self): f(self, *example_args, **example_kwargs) else: + # If we have found no examples, we must skip the test. If @example + # is applied after @given, it will re-wrap the test to remove the + # skip decorator. test_function = unittest.skip( "Hypothesis required for property test with no " + "specified examples" @@ -62,5 +64,39 @@ def decorator(f): return decorator +def assume(condition): + if not condition: + raise unittest.SkipTest("Unsatisfied assumption") + return True + + +def reject(): + assume(False) + + def register_random(*args, **kwargs): pass # pragma: no cover + + +def settings(*args, **kwargs): + pass # pragma: nocover + + +class HealthCheck(Enum): + data_too_large = 1 + filter_too_much = 2 + too_slow = 3 + return_value = 5 + large_base_example = 7 + not_a_test_method = 8 + + @classmethod + def all(cls): + return list(cls) + + +class Verbosity(Enum): + quiet = 0 + normal = 1 + verbose = 2 + debug = 3 diff --git a/Lib/test/support/_hypothesis_stubs/control.py b/Lib/test/support/_hypothesis_stubs/control.py index e3318949b380fb1..f7b684ccbc5872b 100644 --- a/Lib/test/support/_hypothesis_stubs/control.py +++ b/Lib/test/support/_hypothesis_stubs/control.py @@ -4,13 +4,3 @@ "reject", "assume", ] - - -def assume(condition): - if not condition: - raise unittest.SkipTest("Unsatisfied assumption") - return True - - -def reject(): - assume(False)