From c9f5b6ad86fa1e5e0d7cd5a3418188092141f73b Mon Sep 17 00:00:00 2001 From: mike Date: Fri, 20 Mar 2009 04:50:48 +0000 Subject: TutoriusV2 : Adding linear tutorial creator wih basic tests --- (limited to 'src/sugar/tutorius/tests/linear_creatortests.py') diff --git a/src/sugar/tutorius/tests/linear_creatortests.py b/src/sugar/tutorius/tests/linear_creatortests.py new file mode 100644 index 0000000..b328c45 --- /dev/null +++ b/src/sugar/tutorius/tests/linear_creatortests.py @@ -0,0 +1,71 @@ +# 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 coretests import TriggerEventFilter, 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("Not important")) + + creator.action(CountAction()) + + creator.event(TriggerEventFilter("Not good either...")) + + fsm = creator.generate_fsm() + print "------------- Generated FSM -------------------" + print str(fsm) + print "-----------------------------------------------" + # 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].get_next_state() == "State1" + + state1 = fsm.get_state_by_name("State1") + + assert len(state1.get_action_list()) == 1, "Creator did not insert all the actions" + + assert state1.get_event_filter_list()[0].get_next_state() == "State2" + + # 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" + +if __name__ == '__main__': + unittest.main() \ No newline at end of file -- cgit v0.9.1