~ubuntu-branches/ubuntu/oneiric/ubuntuone-client/oneiric

« back to all changes in this revision

Viewing changes to tests/syncdaemon/fsm/test_fsm.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2010-06-08 17:31:18 UTC
  • mto: This revision was merged to the branch mainline in revision 31.
  • Revision ID: james.westby@ubuntu.com-20100608173118-o8s897ll11rtne99
Tags: upstream-1.3.0
ImportĀ upstreamĀ versionĀ 1.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# ubuntuone.syncdaemon.fsm.tests.test_fsm 
 
1
# ubuntuone.syncdaemon.fsm.tests.test_fsm
2
2
#
3
3
# Author: Lucio Torre <lucio.torre@canonical.com>
4
4
#
15
15
#
16
16
# You should have received a copy of the GNU General Public License along
17
17
# with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
"""
19
 
tests for fsm that depend on python uno
20
 
"""
 
18
 
 
19
"""Tests for fsm that depend on python uno."""
 
20
 
 
21
import os
21
22
import unittest
22
 
import os
23
 
 
24
23
 
25
24
from ubuntuone.syncdaemon.fsm import fsm
26
25
 
27
26
def p(name):
28
 
    """make a full path from here."""
 
27
    """Make a full path from here."""
29
28
    return os.path.join(os.path.dirname(__file__), name)
30
29
 
31
30
class TestParse(unittest.TestCase):
32
 
    'Test fsm validation'
33
 
    
 
31
    """Test fsm validation."""
 
32
 
34
33
    def test_one_event(self):
35
 
        'test parsing a simple machine'
 
34
        """Test parsing a simple machine."""
36
35
        f = fsm.StateMachine(p("test_one_event.ods"))
37
36
        f.validate()
38
 
        
 
37
 
39
38
    def test_two_events(self):
40
 
        'test parsing a machine with two events'
 
39
        """Test parsing a machine with two events."""
41
40
        f = fsm.StateMachine(p("test_two_events.ods"))
42
41
        f.validate()
43
42
 
44
43
    def test_bang(self):
45
 
        'test not event expansion'
 
44
        """Test not event expansion."""
46
45
        f = fsm.StateMachine(p("test_bang.ods"))
47
46
        f.validate()
48
 
    
 
47
 
49
48
    def test_transition_twice(self):
50
 
        'test error on duplicate transition'
 
49
        """Test error on duplicate transition."""
51
50
        f = fsm.StateMachine(p("test_transition_twice.ods"))
52
51
        self.assertRaises(fsm.ValidationFailed, f.validate)
53
52
        self.assertEquals(len(f.errors), 1)
54
 
        
 
53
 
55
54
    def test_missing_source_state(self):
56
 
        'test incomplete state transition coverage'
 
55
        """Test incomplete state transition coverage."""
57
56
        f = fsm.StateMachine(p("test_missing_source_state.ods"))
58
57
        self.assertRaises(fsm.ValidationFailed, f.validate)
59
58
        self.assertEquals(len(f.errors), 1)
60
 
    
 
59
 
61
60
    def test_missing_param_values(self):
62
 
        'test incomplete param transition coverage'
 
61
        """Test incomplete param transition coverage."""
63
62
        f = fsm.StateMachine(p("test_missing_param_values.ods"))
64
63
        self.assertRaises(fsm.ValidationFailed, f.validate)
65
64
        self.assertEquals(len(f.errors), 4)
66
 
    
67
 
        
 
65
 
 
66
 
68
67
    def test_two_missing_source_state(self):
69
 
        'test incomplete state transition coverage'
 
68
        """Test incomplete state transition coverage."""
70
69
        f = fsm.StateMachine(p("test_two_missing_source_state.ods"))
71
70
        self.assertRaises(fsm.ValidationFailed, f.validate)
72
71
        self.assertEquals(len(f.errors), 2)
73
72
 
74
73
    def test_star_event(self):
75
 
        'test expansion of one star in event columns'
 
74
        """Test expansion of one star in event columns."""
76
75
        f = fsm.StateMachine(p("test_star_event.ods"))
77
76
        f.validate()
78
 
    
 
77
 
79
78
    def test_two_star_event(self):
80
 
        'test expansion of two stars in event columns'
 
79
        """Test expansion of two stars in event columns."""
81
80
        f = fsm.StateMachine(p("test_two_star_event.ods"))
82
81
        f.validate()
83
 
    
 
82
 
84
83
    def test_star_param(self):
85
 
        'test expansion of one star in param columns'
 
84
        """Test expansion of one star in param columns."""
86
85
        f = fsm.StateMachine(p("test_star_param.ods"))
87
86
        f.validate()
88
 
    
 
87
 
89
88
    def test_two_star_param(self):
90
 
        'test expansion of two stars in param columns'
 
89
        """Test expansion of two stars in param columns."""
91
90
        f = fsm.StateMachine(p("test_two_star_param.ods"))
92
91
        f.validate()
93
 
    
 
92
 
94
93
    def test_invalid(self):
95
 
        'test expansion of two stars in param columns'
 
94
        """Test expansion of two stars in param columns."""
96
95
        f = fsm.StateMachine(p("test_invalid.ods"))
97
96
        f.validate()
98
97
 
99
98
    def test_invalid_expand(self):
100
 
        'test expansion of two stars in param columns'
 
99
        """Test expansion of two stars in param columns."""
101
100
        f = fsm.StateMachine(p("test_invalid_expand.ods"))
102
101
        f.validate()
103
 
        
104
 
        
 
102
 
105
103
    def test_star_event_repeat(self):
106
 
        'test expansion of stars that cover too much'
 
104
        """Test expansion of stars that cover too much."""
107
105
        f = fsm.StateMachine(p("test_star_event_repeat.ods"))
108
106
        self.assertRaises(fsm.ValidationFailed, f.validate)
109
107
        self.assertEquals(len(f.errors), 1)
110
108
 
111
109
    def test_out_equal(self):
112
 
        'test expansion of "=" in state out'
 
110
        """Test expansion of "=" in state out."""
113
111
        f = fsm.StateMachine(p("test_out_equal.ods"))
114
112
        f.validate()
115
113
        for s in f.states.values():
118
116
                    self.assertEquals(t.source[k], t.target[k])
119
117
 
120
118
    def test_out_equal_star(self):
121
 
        'test expansion of "=" in state out'
 
119
        """Test expansion of "=" in state out."""
122
120
        f = fsm.StateMachine(p("test_out_equal_star.ods"))
123
121
        f.validate()
124
122
        for s in f.states.values():
126
124
                for k in t.source:
127
125
                    self.assertEquals(t.source[k], t.target[k],
128
126
                        "on transition %s target is %s"%(t, t.target))
129
 
                    
 
127
 
130
128
    def test_equal_wrong_places(self):
131
 
        'make sure "=" are not allowed on state or params'
 
129
        """make sure "=" are not allowed on state or params."""
132
130
        f = fsm.StateMachine(p("test_equal_wrong_place.ods"))
133
131
        self.assertRaises(fsm.ValidationFailed, f.validate)
134
132
        # this should be two errors
135
133
        # but more errors happen as there is no clear interpretation of
136
134
        # the table in this case
137
135
        self.assertEquals(len(f.errors), 5)
138
 
        
 
136
 
139
137
    def test_param_na(self):
140
 
        'test that na param columns are ignored'
 
138
        """Test that na param columns are ignored."""
141
139
        f = fsm.StateMachine(p("test_param_na.ods"))
142
140
        f.validate()
143
141
        self.assertEqual(f.events["EVENT_2"].transitions[0].parameters.keys(),
144
142
                         [u"MV2"],)
145
143
 
146
144
    def test_func_na(self):
147
 
        'test that na param columns are ignored'
 
145
        """Test that na param columns are ignored."""
148
146
        f = fsm.StateMachine(p("test_func_na.ods"))
149
147
        f.validate()
150
148
        # the state
153
151
        t = "EVENT_1", fsm.hash_dict(dict(MV1="T", MV2="T"))
154
152
        self.assertFalse(t in s.transitions)
155
153
 
156
 
    
157
 
    
 
154
 
158
155
def test_suite():
159
156
    # pylint: disable-msg=C0111
160
157
    if "HAS_OOFFICE" in os.environ:
161
158
        return unittest.TestLoader().loadTestsFromName(__name__)
162
159
    else:
163
160
        return unittest.TestSuite()
164
 
        
165
 
        
 
161
 
166
162
if __name__ == "__main__":
167
163
    unittest.main()