python-hypothesis

How to make custom Hypothesis strategy to supply custom objects?

How to make custom Hypothesis strategy to supply custom objects? Question: Suppose I have a class Thing class Thing: def __init__(self, x, y): … And suppose I have a function which acts on a list of things. def do_stuff(list_of_things): … I would like to write unit tests for do_stuff involving different instances of lists of …

Total answers: 2

Generating an interval set in hypothesis

Generating an interval set in hypothesis Question: I have some code that works with intervals, which are really just python dicts with the following structure: { "name": "some utf8 string", "start": 0.0, # 0.0 <= start < 1.0 "end": 1.0, # start < end <= 1.0 "size": 1.0, # size == end – start } …

Total answers: 1

Can you create a function with a specific signature without using eval?

Can you create a function with a specific signature without using eval? Question: I’ve written some code that inspects function signatures, and I would like to generate test cases for it. For this, I need to be able to construct objects that result in a given Signature object when signature is called on them. I …

Total answers: 1

Randomizing a user dataclass with pytest and hypothesis

Randomizing a user dataclass with pytest and hypothesis Question: I can manually define an Address builder strategy: import attrs from hypothesis import given import hypothesis.strategies as st @attrs.frozen(kw_only=True) class Address: street: str city: str AddressStrategy = st.builds( Address, street=st.text(), city=st.text() ) @given(AddressStrategy) def test_proper_address(address): assert len(address.city) < 4 When I run pytest, it indeed catches …

Total answers: 1

Hypothesis python package for onehots and longitudinal data

Hypothesis python package for onehots and longitudinal data Question: For context I work with mixed tabular data. I have complex data pipelines that I’d like to make sure works on any configuration of data. I see the pandas add-on/extra and have some questions related to that. How would I generate one-hot columns with this package? …

Total answers: 1

How to parametrize Hypothesis strategy in @given

How to parametrize Hypothesis strategy in @given Question: I’m testing a REST API, which can process different requests, e.g., dated and dateless. A request has a field called request_type. I’m wondering what’s the best way to write test in hypothesis: I can write two testes, one for dated, and the other is for dateless. But …

Total answers: 1