Beispiel #1
0
 def test_if_src_not_specified_then_is_wildcard(self):
     fsm = Fysom({
         'initial':
         'hungry',
         'events': [{
             'name': 'eat',
             'src': 'hungry',
             'dst': 'satisfied'
         }, {
             'name': 'eat',
             'src': 'satisfied',
             'dst': 'full'
         }, {
             'name': 'eat',
             'src': 'full',
             'dst': 'sick'
         }, {
             'name': 'rest',
             'dst': 'hungry'
         }]
     })
     fsm.eat()
     self.assertEqual(fsm.current, 'satisfied')
     fsm.rest()
     self.assertEqual(fsm.current, 'hungry')
     fsm.eat()
     fsm.eat()
     self.assertEqual(fsm.current, 'full')
     fsm.rest()
     self.assertEqual(fsm.current, 'hungry')
Beispiel #2
0
 def test_if_src_not_specified_then_is_wildcard(self):
     fsm = Fysom({
         'initial': 'hungry',
         'events': [
             {'name': 'eat', 'src': 'hungry', 'dst': 'satisfied'},
             {'name': 'eat', 'src': 'satisfied', 'dst': 'full'},
             {'name': 'eat', 'src': 'full', 'dst': 'sick'},
             {'name': 'rest', 'dst': 'hungry'}
         ]
     })
     fsm.eat()
     self.assertEqual(fsm.current, 'satisfied')
     fsm.rest()
     self.assertEqual(fsm.current, 'hungry')
     fsm.eat()
     fsm.eat()
     self.assertEqual(fsm.current, 'full')
     fsm.rest()
     self.assertEqual(fsm.current, 'hungry')
 def test_eat_should_transition_to_sick_when_full(self):
     fsm = Fysom(self._get_descr('full'))
     fsm.eat()
     self.assertEqual(fsm.current, 'sick')
Beispiel #4
0
fsm = Fysom({
  'initial': 'hungry',
  'events': [
    {'name': 'eat',  'src': 'hungry',    'dst': 'satisfied'},
    {'name': 'eat',  'src': 'satisfied', 'dst': 'full'},
    {'name': 'eat',  'src': 'full',      'dst': 'sick'},
    {'name': 'rest', 'src': ['hungry', 'satisfied', 'full', 'sick'],
                                         'dst': 'hungry'}
  ],
  'callbacks': {
    'oneat':  oneat
  }
})
#
# print(fsm.current)
fsm.eat(keyparameter=1)
print(fsm.current)
# kwargs testcase
def foo(**kwargs):
  print("foo:kwargs")
  print kwargs
foo(key1=1,key2="2")
# setattr for new function inject  testcase
print("setattr for new function inject  testcase")
class foo_c:
  def __init__(self):
    setattr(self,"inject_fun",self.build_fun())
  def build_fun(self):
    def foo(**kwargs):
      print("into foo for build_fun")
      print kwargs
 def test_eat_should_transition_to_full_when_satisfied(self):
     fsm = Fysom(self._get_descr('satisfied'))
     fsm.eat()
     self.assertEqual(fsm.current, 'full')
 def test_eat_should_transition_to_satisfied_when_hungry(self):
     fsm = Fysom(self._get_descr('hungry'))
     fsm.eat()
     self.assertEqual(fsm.current, 'satisfied')
 def test_eat_should_transition_to_sick_when_full(self):
     fsm = Fysom(self._get_descr('full'))
     fsm.eat()
     self.assertEqual(fsm.current, 'sick')
 def test_eat_should_transition_to_full_when_satisfied(self):
     fsm = Fysom(self._get_descr('satisfied'))
     fsm.eat()
     self.assertEqual(fsm.current, 'full')
 def test_eat_should_transition_to_satisfied_when_hungry(self):
     fsm = Fysom(self._get_descr('hungry'))
     fsm.eat()
     self.assertEqual(fsm.current, 'satisfied')