本文整理汇总了Python中fysom.Fysom.calm方法的典型用法代码示例。如果您正苦于以下问题:Python Fysom.calm方法的具体用法?Python Fysom.calm怎么用?Python Fysom.calm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fysom.Fysom
的用法示例。
在下文中一共展示了Fysom.calm方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_init_kwargs_only
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import calm [as 别名]
def test_init_kwargs_only(self):
fsm = Fysom(initial='green',
events=[('panic', 'green', 'red'),
('calm', 'red', 'green')])
self.assertEqual(fsm.current, "green")
fsm.panic()
self.assertEqual(fsm.current, "red")
fsm.calm()
self.assertEqual(fsm.current, "green")
示例2: test_kwargs_override_cfg
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import calm [as 别名]
def test_kwargs_override_cfg(self):
fsm = Fysom({
'initial': 'green',
'events': [
{'name': 'panic', 'src': 'green', 'dst': 'red'},
{'name': 'calm', 'src': 'red', 'dst': 'green'},
]},
# override initial state and calm event
initial='red', events=[('calm', 'red', 'black')])
self.assertEqual(fsm.current, "red")
fsm.calm()
self.assertEqual(fsm.current, "black")
示例3: test_tuples_as_trasition_spec
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import calm [as 别名]
def test_tuples_as_trasition_spec(self):
fsm = Fysom({
'initial': 'green',
'events': [ # freely mix dicts and tuples
{'name': 'warn', 'src': 'green', 'dst': 'yellow'},
('panic', 'yellow', 'red'),
('calm', 'red', 'yellow'),
{'name': 'clear', 'src': 'yellow', 'dst': 'green'}
]
})
fsm.warn()
fsm.panic()
self.assertEqual(fsm.current, 'red')
fsm.calm()
fsm.clear()
self.assertEqual(fsm.current, 'green')
示例4: MyTestObject
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import calm [as 别名]
class MyTestObject(object):
def __init__(self):
self._states = []
self._fsm = Fysom({
'initial': 'green',
'events': [
{'name': 'warn', 'src': 'green', 'dst': 'yellow'},
{'name': 'panic', 'src': 'yellow', 'dst': 'red'},
{'name': 'calm', 'src': 'red', 'dst': 'yellow'},
{'name': 'clear', 'src': 'yellow', 'dst': 'green'}
],
'callbacks': {
'ongreen': self._on_green,
'onyellow': self._on_yellow,
'onred': self._on_red
}
})
def warn(self):
self._fsm.warn()
def panic(self):
self._fsm.panic()
def calm(self):
self._fsm.calm()
def clear(self):
self._fsm.clear()
def _on_green(self, *args, **kwargs):
self._states.append('green')
def _on_yellow(self, *args, **kwargs):
self._states.append('yellow')
def _on_red(self, *args, **kwargs):
self._states.append('red')