| 1 |
# This file is part of Hypothesis, which may be found at |
| 2 |
# https://github.com/HypothesisWorks/hypothesis/ |
| 3 |
# |
| 4 |
# Copyright the Hypothesis Authors. |
| 5 |
# Individual contributors are listed in AUTHORS.rst and the git log. |
| 6 |
# |
| 7 |
# This Source Code Form is subject to the terms of the Mozilla Public License, |
| 8 |
# v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 9 |
# obtain one at https://mozilla.org/MPL/2.0/. |
| 10 |
|
| 11 |
"""This example demonstrates a setuptools entry point. |
| 12 |
|
| 13 |
See https://hypothesis.readthedocs.io/en/latest/strategies.html#registering-strategies-via-setuptools-entry-points |
| 14 |
for details and documentation. |
| 15 |
""" |
| 16 |
|
| 17 |
|
| 18 |
class MyCustomType: |
| 19 |
def __init__(self, x: int): |
| 20 |
assert x >= 0, f"got {x}, but only positive numbers are allowed" |
| 21 |
self.x = x |
| 22 |
|
| 23 |
|
| 24 |
def _hypothesis_setup_hook(): |
| 25 |
import hypothesis.strategies as st |
| 26 |
|
| 27 |
st.register_type_strategy(MyCustomType, st.integers(min_value=0).map(MyCustomType)) |