From 3b9bff2ef1826987d95815ff03c235052cea9aae Mon Sep 17 00:00:00 2001 From: mike Date: Sat, 17 Oct 2009 17:47:58 +0000 Subject: LP 439980 : Code review changes : renamed is_identical to __eq__, relaxed action insertion constraints, added fixed meta-props for addons --- (limited to 'tutorius/core.py') diff --git a/tutorius/core.py b/tutorius/core.py index d034c30..4376315 100644 --- a/tutorius/core.py +++ b/tutorius/core.py @@ -89,18 +89,6 @@ class Tutorial (object): self.state_machine.set_state(name) - -## # Currently unused -- equivalent function is in each state -## def _eventfilter_state_done(self, eventfilter): -## """ -## Callback handler for eventfilter to notify -## when we must go to the next state. -## """ -## #XXX Tests should be run here normally -## -## #Swith to the next state pointed by the eventfilter -## self.set_state(eventfilter.get_next_state()) - def _prepare_activity(self): """ Prepare the activity for the tutorial by loading the saved state and @@ -202,15 +190,13 @@ class State(object): # These functions are used to simplify the creation of states def add_action(self, new_action): """ - Adds an action to the state (only if it wasn't added before) + Adds an action to the state @param new_action The new action to execute when in this state @return True if added, False otherwise """ - if new_action not in self._actions: - self._actions.append(new_action) - return True - return False + self._actions.append(new_action) + return True # remove_action - We did not define names for the action, hence they're # pretty hard to remove on a precise basis @@ -256,7 +242,7 @@ class State(object): """ self._event_filters = [] - def is_identical(self, otherState): + def __eq__(self, otherState): """ Compares two states and tells whether they contain the same states with the same actions and event filters. @@ -284,7 +270,7 @@ class State(object): found = False # For each action in the other state, try to match it with this one. for otherAct in otherState._actions: - if act.is_identical(otherAct): + if act == otherAct: found = True break if found == False: @@ -299,7 +285,7 @@ class State(object): # the current filter. We just need to find one with the right # properties and values. for otherEvent in otherState._event_filters: - if event.is_identical(otherEvent): + if event == otherEvent: found = True break if found == False: @@ -578,7 +564,7 @@ class FiniteStateMachine(State): out_string += st.name + ", " return out_string - def is_identical(self, otherFSM): + def __eq__(self, otherFSM): """ Compares the elements of two FSM to ensure and returns true if they have the same set of states, containing the same actions and the same event filters. @@ -603,7 +589,7 @@ class FiniteStateMachine(State): # For every action in the other FSM, try to match it with the # current one. for otherAct in otherFSM._actions: - if act.is_identical(otherAct): + if act == otherAct: found = True break if found == False: @@ -626,7 +612,7 @@ class FiniteStateMachine(State): return False # If two states with the same name exist, then we want to make sure # they are also identical - if not state.is_identical(other_state): + if not state == other_state: return False # If we made it here, then all the states in this FSM could be matched to an -- cgit v0.9.1