@@ -63,10 +63,10 @@ def split(self, left, right):
6363 def test_is_balanced (self , tree ):
6464 if isinstance (tree , Leaf ):
6565 return
66- else :
67- assert abs (self .size (tree .left ) - self .size (tree .right )) <= 1
68- self .test_is_balanced (tree .left )
69- self .test_is_balanced (tree .right )
66+
67+ assert abs (self .size (tree .left ) - self .size (tree .right )) <= 1
68+ self .test_is_balanced (tree .left )
69+ self .test_is_balanced (tree .right )
7070
7171 def size (self , tree ):
7272 if isinstance (tree , Leaf ):
@@ -108,13 +108,10 @@ def bunch(self, source):
108108
109109 @rule (source = nodes )
110110 def shallow (self , source ):
111- def d (ls ):
112- if not ls :
113- return 0
114- else :
115- return 1 + max (map (d , ls ))
111+ def depth (ls ):
112+ return 0 if not ls else 1 + max (map (depth , ls ))
116113
117- assert d (source ) <= 5
114+ assert depth (source ) <= 5
118115
119116
120117class NotTheLastMachine (RuleBasedStateMachine ):
@@ -166,11 +163,7 @@ def __init__(self):
166163 super ().__init__ ()
167164 self .seen = set ()
168165
169- # The reason this rule takes a parameter is that it ensures that we do not
170- # achieve "swarming" by by just restricting the alphabet for single byte
171- # decisions, which is a thing the underlying conjecture engine will
172- # happily do on its own without knowledge of the rule structure.
173- @rule (move = st .integers (0 , 255 ))
166+ @rule (move = st .integers ())
174167 def ladder (self , move ):
175168 self .seen .add (move )
176169 assert len (self .seen ) <= 15
@@ -190,16 +183,12 @@ def snake(self):
190183)
191184
192185for m in bad_machines :
193- m .TestCase .settings = Settings (m .TestCase .settings , max_examples = 1000 )
194-
195-
196- cheap_bad_machines = list (bad_machines )
197- cheap_bad_machines .remove (BalancedTrees )
198-
199-
200- with_cheap_bad_machines = pytest .mark .parametrize (
201- "machine" , cheap_bad_machines , ids = [t .__name__ for t in cheap_bad_machines ]
202- )
186+ m .TestCase .settings = Settings (
187+ m .TestCase .settings ,
188+ max_examples = 1000 ,
189+ database = None ,
190+ phases = set (Phase ) - {Phase .shrink },
191+ )
203192
204193
205194@pytest .mark .parametrize (
@@ -213,14 +202,8 @@ def test_bad_machines_fail(machine):
213202 # and also takes 10/6 minutes respectively, on top of not finding the failure
214203 pytest .xfail (reason = str (Why .undiscovered ))
215204
216- test_class = machine .TestCase
217- try :
218- test_class ().runTest ()
219- raise RuntimeError ("Expected an assertion error" )
220- except AssertionError as err :
221- notes = err .__notes__
222- steps = [l for l in notes if "Step " in l or "state." in l ]
223- assert 1 <= len (steps ) <= 50
205+ with pytest .raises (AssertionError ):
206+ machine .TestCase ().runTest ()
224207
225208
226209class MyStatefulMachine (RuleBasedStateMachine ):
0 commit comments