Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first cut at a (somewhat) useful hypothesis test #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions glom/test/test_auto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'''
Use hypothesis and contracts to automatically search for flaws.
'''
from hypothesis import settings
from hypothesis.stateful import RuleBasedStateMachine, invariant, rule

from glom import glom, Inspect, Coalesce, T


class SpecAndTarget(RuleBasedStateMachine):
'''
auto generate a spec and target that should work together
need more sophisticated strategies to make this more useful
(probably not mindless recursion to an arbitrary depth)
'''
def __init__(self):
super(SpecAndTarget, self).__init__()
self.spec = T
self.target = None
self.result = None

@invariant()
def spec_works(self):
assert glom(self.target, self.spec) == self.result

@rule()
def add_inspect(self):
self.spec = Inspect(self.spec)

@rule()
def add_list(self):
self.spec = [self.spec]
self.target = [self.target, self.target]
self.result = [self.result, self.result]

@rule()
def add_dict(self):
self.spec = {'key': self.spec}
self.result = {'key': self.result}

@rule()
def add_coalesce(self):
self.spec = Coalesce(self.spec)

@rule()
def add_tuple(self):
self.spec = (self.spec, T)


TestSpecAndTarget = SpecAndTarget.TestCase
TestSpecAndTarget.settings = settings(max_examples=20, stateful_step_count=50)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ boltons==17.2.0
coverage==4.5.1
face>=0.1.0
funcsigs==1.0.2
hypothesis==3.82.1
more-itertools==4.1.0
pluggy==0.6.0
py==1.5.2
Expand Down