From a8149cd5dcda7615bdd4199ec7afbd8479906e0e Mon Sep 17 00:00:00 2001 From: Joel Bender Date: Wed, 5 Aug 2015 23:28:23 -0400 Subject: [PATCH] add a reset function to states, call it when the state machine resets --- tests/utilities.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/utilities.py b/tests/utilities.py index b13fc72..a623870 100644 --- a/tests/utilities.py +++ b/tests/utilities.py @@ -140,13 +140,20 @@ class State: self.is_success_state = False self.is_fail_state = False - # list of send and receive transitions + # empty lists of send and receive transitions self.send_transitions = [] self.receive_transitions = [] # timeout transition self.timeout_transition = None + def reset(self): + """Override this method in a derived class if the state maintains + counters or other information. Called when the associated state + machine is reset. + """ + if _debug: State._debug("reset") + def doc(self, doc_string): """Change the documentation string (label) for the state. The state is returned for method chaining. @@ -438,6 +445,10 @@ class StateMachine: # we are not starting up self._startup_flag = False + # give all the states a chance to reset + for state in self.states: + state.reset() + def run(self): if _debug: StateMachine._debug("run")