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/>.
19
tests for fsm that depend on python uno
19
"""Tests for fsm that depend on python uno."""
25
24
from ubuntuone.syncdaemon.fsm import fsm
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)
31
30
class TestParse(unittest.TestCase):
31
"""Test fsm validation."""
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"))
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"))
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"))
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)
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)
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)
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)
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"))
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"))
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"))
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"))
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"))
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"))
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)
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"))
115
113
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))
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)
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"))
143
141
self.assertEqual(f.events["EVENT_2"].transitions[0].parameters.keys(),
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"))