Skip to content

Instantly share code, notes, and snippets.

@shapr
Created June 28, 2017 15:03
Show Gist options
  • Save shapr/fad8a27800c8927f03c65657d20aac2e to your computer and use it in GitHub Desktop.
Save shapr/fad8a27800c8927f03c65657d20aac2e to your computer and use it in GitHub Desktop.
simple hypothesis demo
from hypothesis import given
import hypothesis.strategies as st
import json
@given(st.one_of( st.integers(), st.text(), st.lists(st.text())))
def test_decode_inverts_encode(s):
assert json.loads(json.dumps(s)) == s
@given(x=st.floats(), y=st.floats(), z=st.floats())
def test_floats_commutative(x, y, z):
assert (x * y) * z == x * (y * z)
@given(x=st.floats())
def test_floats_self_inverse(x):
assert x == -(-x)
if __name__ == '__main__':
test_decode_inverts_encode()
test_floats_commutative()
test_floats_self_inverse()
@agocs
Copy link

agocs commented Jun 28, 2017

could

@given(st.one_of( st.integers(), st.text(), st.lists(st.text())))

be expressed as

@given(s=st.one_of( st.integers(), st.text(), st.lists(st.text())))

?

@madeofstardust
Copy link

Hi, I have a problem with hypothesis. every time I want to use it, I get an error:
AttributeError: 'function' object has no attribute '(My attribute)'
It happens with every attribute. What should I do to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment