1
# ubuntuone.syncdaemon.fsm.tests.test_fsm_run
3
# Author: Lucio Torre <lucio.torre@canonical.com>
5
# Copyright 2009 Canonical Ltd.
7
# This program is free software: you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License version 3, as published
9
# by the Free Software Foundation.
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranties of
13
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
# PURPOSE. See the GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License along
17
# with this program. If not, see <http://www.gnu.org/licenses/>.
19
tests for running fsms
25
from ubuntuone.syncdaemon.fsm import fsm
28
"""make a full path from here."""
29
if "HAS_OOFICE" in os.environ:
30
return os.path.join(os.path.dirname(__file__), name+".ods")
32
return os.path.join(os.path.dirname(__file__), name+".py")
34
class TestRun(unittest.TestCase):
38
'test running a hello world machine'
39
f = fsm.StateMachine(p("test_run_hello"))
43
def make(out, outstates):
44
"make action_func functions"
45
def maker(self, event, params):
48
self.state = outstates[int(params["MV1"])-1]
51
class HelloRunner(fsm.StateMachineRunner):
52
"our implementation of the runner"
60
D = make("d", ["NL"]*3)
61
newline = make("\n", "HHH")
63
def get_state_values(self):
64
"return the stateval of this fsm."
65
return dict(SV1=self.state)
68
runner = HelloRunner(f)
69
for i in [1, 1, 1, 2, 1, 2, 2, 3, 3, 1, 1]:
70
runner.on_event("EVENT_1", dict(MV1=str(i)))
71
self.assertEquals("helloworld\n", "".join(result))
74
if __name__ == "__main__":