diff options
author | mike <michael.jmontcalm@gmail.com> | 2009-11-25 17:26:09 (GMT) |
---|---|---|
committer | mike <michael.jmontcalm@gmail.com> | 2009-11-25 17:26:09 (GMT) |
commit | e7abfee767ef1f9b6efb6e6145da044151dd30e3 (patch) | |
tree | 8aa9afb9f71106195fa731b9e9112e462bb89dd1 | |
parent | 10f70b3a165dabca7478c76d3d4d342293bb1fbb (diff) |
Boyscout: Removing linear creator
-rw-r--r-- | tests/linear_creatortests.py | 79 | ||||
-rw-r--r-- | tutorius/linear_creator.py | 94 |
2 files changed, 0 insertions, 173 deletions
diff --git a/tests/linear_creatortests.py b/tests/linear_creatortests.py deleted file mode 100644 index e3c30c1..0000000 --- a/tests/linear_creatortests.py +++ /dev/null @@ -1,79 +0,0 @@ -# Copyright (C) 2009, Tutorius.org -# Greatly influenced by sugar/activity/namingalert.py -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -from sugar.tutorius.core import * -from sugar.tutorius.actions import * -from sugar.tutorius.filters import * -from sugar.tutorius.linear_creator import * -from sugar.tutorius.addons.triggereventfilter import * -from actiontests import CountAction -import unittest - -class CreatorTests(unittest.TestCase): - - def test_simple_usage(self): - creator = LinearCreator() - fsm_name = "SimpleUsageTest" - - creator.set_name(fsm_name) - - # Generate an FSM using the steps - creator.action(CountAction()) - creator.action(CountAction()) - - creator.event(TriggerEventFilter()) - - creator.action(CountAction()) - - creator.event(TriggerEventFilter()) - - fsm = creator.generate_fsm() - - # Make sure everything worked! - assert fsm.name == fsm_name, "Name was not set properly" - - init_state = fsm.get_state_by_name("INIT") - - assert len(init_state.get_action_list()) == 2, "Creator did not insert all the actions" - - assert init_state.get_event_filter_list()[0][1] == "State 1" , "expected next state to be 'State 1' but got %s" % init_state.get_event_filter_list()[0][1] - - state1 = fsm.get_state_by_name("State 1") - - assert len(state1.get_action_list()) == 1, "Creator did not insert all the actions" - - assert state1.get_event_filter_list()[0][1] == "State 2" - - # Make sure we have the final state and that it's empty - state2 = fsm.get_state_by_name("State2") - - assert len(state2.get_action_list()) == 0, "Creator inserted extra actions on wrong state" - - assert len(state2.get_event_filter_list()) == 0, "Creator assigner events to the final state" - - creator.action(CountAction()) - - fsm = creator.generate_fsm() - - state2 = fsm.get_state_by_name("State2") - - assert len(state2.get_action_list()) == 1, "Creator did not add the action" - - assert len(state2.get_event_filter_list()) == 0, "Creator assigner events to the final state" - -if __name__ == '__main__': - unittest.main() diff --git a/tutorius/linear_creator.py b/tutorius/linear_creator.py deleted file mode 100644 index f664c49..0000000 --- a/tutorius/linear_creator.py +++ /dev/null @@ -1,94 +0,0 @@ -# Copyright (C) 2009, Tutorius.org -# Greatly influenced by sugar/activity/namingalert.py -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -from copy import deepcopy - -from .core import * -from .actions import * -from .filters import * - -class LinearCreator(object): - """ - This class is used to create a FSM from a linear sequence of orders. The - orders themselves are meant to be either an action or a transition. - """ - - def __init__(self): - self.fsm = FiniteStateMachine("Sample Tutorial") - self.current_actions = [] - self.nb_state = 0 - self.state_name = "INIT" - - def set_name(self, name): - """ - Sets the name of the generated FSM. - """ - self.fsm.name = name - - def action(self, action): - """ - Adds an action to execute in the current state. - """ - self.current_actions.append(action) - - def event(self, event_filter): - """ - Adds a transition to another state. When executing this, all the actions - previously called will be bundled in a single state, with the exit - condition of this state being the transition just added. - - Whatever the name of the next state you inserted in the event, it will - be replaced to point to the next event in the line. - """ - if len(self.current_actions) != 0: - # Set the next state name - there is no way the caller should have - # to deal with that. - next_state_name = "State %d" % (self.nb_state+1) - state = State(self.state_name, action_list=self.current_actions, - event_filter_list=[(event_filter, next_state_name),]) - self.state_name = next_state_name - - self.nb_state += 1 - self.fsm.add_state(state) - - # Clear the actions from the list - self.current_actions = [] - - def generate_fsm(self): - """ - Returns a finite state machine corresponding to the sequence of calls - that were made from this point on. - """ - # Copy the whole FSM that was generated yet - new_fsm = deepcopy(self.fsm) - - # Generate the final state - state = None - if len(self.current_actions) != 0: - state = State("State" + str(self.nb_state), action_list=self.current_actions) - # Don't increment the nb_state here - we would break the linearity - # because we might generate more stuff with this creator later. - # Since we rely on linearity for continuity when generating the - # next state's name on an event filter, we cannot increment here. - else: - state = State("State" + str(self.nb_state)) - - # Insert the state in the copy of the FSM - new_fsm.add_state(state) - - return new_fsm - |