44from statemachine import Event
55from statemachine import State
66from statemachine import StateChart
7- from statemachine import StateMachine
87
98
109class ErrorInGuardSC (StateChart ):
@@ -54,8 +53,10 @@ def bad_after(self):
5453 raise RuntimeError ("after failed" )
5554
5655
57- class ErrorInGuardSM (StateMachine ):
58- """StateMachine subclass: exceptions should propagate."""
56+ class ErrorInGuardSM (StateChart ):
57+ """StateChart subclass with error_on_execution=False: exceptions should propagate."""
58+
59+ error_on_execution = False
5960
6061 initial = State ("initial" , initial = True )
6162
@@ -65,10 +66,8 @@ def bad_guard(self):
6566 raise RuntimeError ("guard failed" )
6667
6768
68- class ErrorInActionSMWithFlag (StateMachine ):
69- """StateMachine subclass with error_on_execution = True."""
70-
71- error_on_execution = True
69+ class ErrorInActionSMWithFlag (StateChart ):
70+ """StateChart subclass (error_on_execution = True by default)."""
7271
7372 s1 = State ("s1" , initial = True )
7473 s2 = State ("s2" )
@@ -144,7 +143,7 @@ def test_exception_in_after_sends_error_execution_no_rollback():
144143
145144
146145def test_statemachine_exception_propagates ():
147- """StateMachine ( error_on_execution=False) should propagate exceptions normally."""
146+ """StateChart with error_on_execution=False should propagate exceptions normally."""
148147 sm = ErrorInGuardSM ()
149148 assert sm .configuration == {sm .initial }
150149
@@ -184,7 +183,7 @@ def test_error_in_error_handler_no_infinite_loop():
184183
185184
186185def test_statemachine_with_error_on_execution_true ():
187- """Custom StateMachine subclass with error_on_execution=True should catch errors."""
186+ """StateChart ( error_on_execution=True by default) should catch errors."""
188187 sm = ErrorInActionSMWithFlag ()
189188 assert sm .configuration == {sm .s1 }
190189
@@ -496,11 +495,9 @@ def obsess(self):
496495 assert sm .configuration == {sm .betrayed }
497496
498497 def test_statemachine_with_convention_and_flag (self ):
499- """StateMachine with error_on_execution=True uses the error_ convention."""
500-
501- class SarumanBetrayal (StateMachine ):
502- error_on_execution = True
498+ """StateChart (error_on_execution=True by default) uses the error_ convention."""
503499
500+ class SarumanBetrayal (StateChart ):
504501 white_council = State ("white_council" , initial = True )
505502 orthanc = State ("orthanc" , final = True )
506503
@@ -515,9 +512,11 @@ def betray(self):
515512 assert sm .configuration == {sm .orthanc }
516513
517514 def test_statemachine_without_flag_propagates (self ):
518- """StateMachine without error_on_execution=True propagates errors even with convention."""
515+ """StateChart with error_on_execution=False propagates errors even with convention."""
516+
517+ class AragornSword (StateChart ):
518+ error_on_execution = False
519519
520- class AragornSword (StateMachine ):
521520 broken = State ("broken" , initial = True )
522521
523522 reforge = broken .to (broken , on = "attempt_reforge" )
@@ -955,7 +954,9 @@ def after_go(self, **kwargs):
955954 def test_runtime_error_in_after_without_error_on_execution_propagates (self ):
956955 """RuntimeError in after callback without error_on_execution raises."""
957956
958- class SM (StateMachine ):
957+ class SM (StateChart ):
958+ error_on_execution = False
959+
959960 s1 = State (initial = True )
960961 s2 = State (final = True )
961962
@@ -989,7 +990,9 @@ def after_go(self, **kwargs):
989990 def test_runtime_error_in_microstep_without_error_on_execution (self ):
990991 """RuntimeError in microstep without error_on_execution raises."""
991992
992- class SM (StateMachine ):
993+ class SM (StateChart ):
994+ error_on_execution = False
995+
993996 s1 = State (initial = True )
994997 s2 = State ()
995998
@@ -1007,7 +1010,9 @@ def on_enter_s2(self, **kwargs):
10071010def test_internal_queue_processes_raised_events ():
10081011 """Internal events raised during processing are handled."""
10091012
1010- class SM (StateMachine ):
1013+ class SM (StateChart ):
1014+ error_on_execution = False
1015+
10111016 s1 = State (initial = True )
10121017 s2 = State ()
10131018 s3 = State (final = True )
@@ -1027,7 +1032,9 @@ def on_enter_s2(self, **kwargs):
10271032def test_engine_start_when_already_started ():
10281033 """start() is a no-op when state machine is already initialized."""
10291034
1030- class SM (StateMachine ):
1035+ class SM (StateChart ):
1036+ error_on_execution = False
1037+
10311038 s1 = State (initial = True )
10321039 s2 = State (final = True )
10331040
@@ -1092,7 +1099,9 @@ def bad_action(self):
10921099def test_runtime_error_in_internal_event_propagates_without_error_on_execution ():
10931100 """RuntimeError in internal event propagates when error_on_execution is False."""
10941101
1095- class SM (StateMachine ):
1102+ class SM (StateChart ):
1103+ error_on_execution = False
1104+
10961105 s1 = State (initial = True )
10971106 s2 = State ()
10981107 s3 = State ()
0 commit comments