# Copyright (C) 2009, Tutorius.org # Copyright (C) 2009, Michael Janelle-Montcalm # # 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 """ Core Tests This module contains all the tests that pertain to the usage of the Tutorius Core. This means that the Event Filters, the Finite State Machine and all the related elements and interfaces are tested here. Usage of actions and event filters is tested, but not the concrete actions and event filters. Those are in their separate test module """ import unittest import copy import logging from sugar.tutorius.tutorial import * # The following tests are organized around 4 classes: # # Black box tests: # Those tests should limit themselves to exercise the # interface of the object so everything should be tested # only through the interface the object offers. This will # ease test maintenance since we anticipate most changes # will be about the implementation of an object and not # its interface. # # Tests definitions are written assuming the previous tests # did complete correctly so the number of things to assert # is minimal. # # Basic interface cases: # Test the interface of the object for trivial cases # just to assert that the functionality this object # offers really works # # Limit cases: # Test edge cases that cover more obscure usage # scenarios but that should be valid nonetheless # # Error cases: # Test wrong inputs to make sure that the object is hard # to misuse and do generate proper errors # # White box tests: # Those should be used only for really important algorithms # to make sure they behave correctly in every cases, otherwise # the tests will break each time we change something in the # implementation class StateTest(unittest.TestCase): """Test basic functionalities of states used by tutorials""" def setUp(self): self.state = State("State1") def tearDown(self): pass ######################### Basic interface cases ######################### #### Action def test_add_dummy_action(self): action_name = self.state.add_action("action1") assert len(self.state.get_action_dict()) == 1 assert self.state.get_action_dict().has_key(action_name) assert self.state.get_action_dict()[action_name] == "action1" def test_add_generate_unique_action_names(self): action_name1 = self.state.add_action("action1") action_name2 = self.state.add_action("action2") assert action_name1 != action_name2 def test_update_dummy_action(self): action_name = self.state.add_action("action1") self.state.update_action(action_name, "action2") assert len(self.state.get_action_dict()) == 1 assert self.state.get_action_dict().has_key(action_name) assert self.state.get_action_dict()[action_name] == "action2" def test_delete_dummy_action(self): action_name = self.state.add_action("action1") assert len(self.state.get_action_dict()) == 1 assert self.state.get_action_dict().has_key(action_name) assert self.state.get_action_dict()[action_name] == "action1" self.state.delete_action(action_name) assert len(self.state.get_action_dict()) == 0 def test_delete_all_dummy_actions(self): action_name = self.state.add_action("action1") assert len(self.state.get_action_dict()) == 1 assert self.state.get_action_dict().has_key(action_name) assert self.state.get_action_dict()[action_name] == "action1" self.state.delete_actions() assert len(self.state.get_action_dict()) == 0 #### Transition def test_add_dummy_transition(self): transition_name = self.state.add_transition("transition1") assert len(self.state.get_transition_dict()) == 1 assert self.state.get_transition_dict().has_key(transition_name) assert self.state.get_transition_dict()[transition_name] == "transition1" def test_add_generate_unique_transition_names(self): transition_name1 = self.state.add_transition("transition1") transition_name2 = self.state.add_transition("transition2") assert transition_name1 != transition_name2 def test_update_dummy_transition(self): transition_name = self.state.add_transition("transition1") self.state.update_transition(transition_name, "transition2") assert len(self.state.get_transition_dict()) == 1 assert self.state.get_transition_dict().has_key(transition_name) assert self.state.get_transition_dict()[transition_name] == "transition2" def test_delete_dummy_transition(self): transition_name = self.state.add_transition("transition1") assert len(self.state.get_transition_dict()) == 1 assert self.state.get_transition_dict().has_key(transition_name) assert self.state.get_transition_dict()[transition_name] == "transition1" self.state.delete_transition(transition_name) assert len(self.state.get_transition_dict()) == 0 def test_delete_all_dummy_transitions(self): transition_name = self.state.add_transition("transition1") assert len(self.state.get_transition_dict()) == 1 assert self.state.get_transition_dict().has_key(transition_name) assert self.state.get_transition_dict()[transition_name] == "transition1" self.state.delete_transitions() assert len(self.state.get_transition_dict()) == 0 ######################### Limit cases ################################### #### Action #### Transition ######################### Error cases ################################### #### Action def test_update_unknown_action(self): name_error = None try: self.state.update_action("unknown_name", "action") except NameError, e: name_error = e assert name_error def test_delete_unknown_action(self): name_error = None try: self.state.delete_action("unknown_name") except NameError, e: name_error = e assert name_error #### Transition def test_add_existing_transition(self): self.state.add_transition("transition") transition_exists_error = None try: self.state.add_transition("transition") except TransitionAlreadyExists, e: transition_exists_error = e assert transition_exists_error class TutorialTest(unittest.TestCase): """Test basic functionalities of tutorials""" def setUp(self): pass def tearDown(self): pass ######################### Basic interface cases ######################### ######################### Limit cases ################################### ######################### Error cases ################################### if __name__ == "__main__": unittest.main()