Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/tutorialtests.py
blob: 864c452b1439a001a148f10314476b0a17bfc029 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# Copyright (C) 2009, Tutorius.org
# Copyright (C) 2009, Michael Janelle-Montcalm <michael.jmontcalm@gmail.com>
#
# 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()