Skip to content

Commit

Permalink
fixup! Add stubs for hypothesis tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pganssle committed May 13, 2021
1 parent 3576fc9 commit 6b96345
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
40 changes: 38 additions & 2 deletions Lib/test/support/_hypothesis_stubs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from enum import Enum
import functools
import unittest

Expand All @@ -14,8 +15,6 @@
]

from . import strategies
from ._settings import HealthCheck, Verbosity, settings
from .control import assume, reject


def given(*_args, **_kwargs):
Expand All @@ -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"
Expand Down Expand Up @@ -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
10 changes: 0 additions & 10 deletions Lib/test/support/_hypothesis_stubs/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,3 @@
"reject",
"assume",
]


def assume(condition):
if not condition:
raise unittest.SkipTest("Unsatisfied assumption")
return True


def reject():
assume(False)

0 comments on commit 6b96345

Please sign in to comment.