本文整理汇总了Python中fysom.Fysom.warn方法的典型用法代码示例。如果您正苦于以下问题:Python Fysom.warn方法的具体用法?Python Fysom.warn怎么用?Python Fysom.warn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fysom.Fysom
的用法示例。
在下文中一共展示了Fysom.warn方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FysomStateTests
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import warn [as 别名]
class FysomStateTests(unittest.TestCase):
def setUp(self):
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'}
]
})
def test_is_state_should_succeed_for_initial_state(self):
self.assertTrue(self.fsm.isstate('green'))
def test_identity_transition_should_not_be_allowed_by_default(self):
self.assertFalse(self.fsm.can('clear'))
self.assertTrue(self.fsm.cannot('clear'))
def test_configured_transition_should_work(self):
self.assertTrue(self.fsm.can('warn'))
def test_transition_should_change_state(self):
self.fsm.warn()
self.assertTrue(self.fsm.isstate('yellow'))
def test_should_raise_exception_when_state_transition_is_not_allowed(self):
self.assertRaises(FysomError, self.fsm.panic)
self.assertRaises(FysomError, self.fsm.calm)
self.assertRaises(FysomError, self.fsm.clear)
示例2: test_pickling
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import warn [as 别名]
def test_pickling(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'}
]
})
pickled = dumps(fsm)
assert pickled
fsm = loads(pickled)
self.assertTrue(isinstance(fsm, Fysom))
self.assertEquals('green', fsm.current)
fsm.warn()
pickled = dumps(fsm)
assert pickled
fsm = loads(pickled)
self.assertEquals('yellow', fsm.current)
示例3: test_never_finished_if_final_is_unspecified
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import warn [as 别名]
def test_never_finished_if_final_is_unspecified(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'}
]
})
self.assertFalse(fsm.is_finished())
fsm.warn()
self.assertFalse(fsm.is_finished())
fsm.panic()
self.assertFalse(fsm.is_finished())
示例4: test_gc_should_not_break_callback
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import warn [as 别名]
def test_gc_should_not_break_callback(self):
class MyTestObject(object):
def __init__(self):
self._states = []
self._fsm = None
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')
obj = MyTestObject()
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': obj._on_green,
'onyellow': obj._on_yellow,
'onred': obj._on_red
}
})
obj._fsm = fsm
obj.warn()
obj.clear()
del obj
fsm.warn()
示例5: test_it_should_indicate_whether_fsm_in_finished_state
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import warn [as 别名]
def test_it_should_indicate_whether_fsm_in_finished_state(self):
fsm = Fysom({
'initial': 'green',
'final': 'red',
'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'}
]
})
self.assertFalse(fsm.is_finished())
fsm.warn()
self.assertFalse(fsm.is_finished())
fsm.panic()
self.assertTrue(fsm.is_finished())
示例6: test_tuples_as_trasition_spec
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import warn [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')
示例7: FysomStateTests
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import warn [as 别名]
class FysomStateTests(unittest.TestCase):
def setUp(self):
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'},
{'name': 'warm', 'src': 'green', 'dst': 'blue'}
]
})
def test_is_state_should_succeed_for_initial_state(self):
self.assertTrue(self.fsm.isstate('green'))
def test_identity_transition_should_not_be_allowed_by_default(self):
self.assertFalse(self.fsm.can('clear'))
self.assertTrue(self.fsm.cannot('clear'))
def test_configured_transition_should_work(self):
self.assertTrue(self.fsm.can('warn'))
def test_transition_should_change_state(self):
self.fsm.warn()
self.assertTrue(self.fsm.isstate('yellow'))
def test_should_raise_exception_when_state_transition_is_not_allowed(self):
self.assertRaises(FysomError, self.fsm.panic)
self.assertRaises(FysomError, self.fsm.calm)
self.assertRaises(FysomError, self.fsm.clear)
def test_event_handler_has_name_and_docstring(self):
self.assertEqual(self.fsm.warm.__name__, "warm", "Event handlers do not have appropriate name.")
self.assertNotEqual(self.fsm.warm.__name__, None, "Docstring for event handler is None!")
def test_trigger_should_trigger_the_event_handler(self):
self.assertEqual(self.fsm.current, "green", "The initial state isn't the expected state.")
self.fsm.trigger("warm")
make_callable = lambda: self.fsm.trigger("unknowevent")
self.assertRaises(FysomError, make_callable)
self.assertEqual(self.fsm.current, "blue", "The initial state isn't the expected state.")
示例8: StatesTestCase
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import warn [as 别名]
class StatesTestCase(unittest.TestCase):
def setUp(self):
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'}
]
})
def test_invalid_state(self):
self.assertRaises(AttributeError, getattr, self.fsm, 'wtfbbq')
def test_state_conditions(self):
"""
This will check for example, if state is in clear, will be able to emit
warn and will not be able to emit panic, calm or clear again.
"""
self.assertTrue(self.fsm.isstate('green'))
self.assertTrue(self.fsm.can('warn'))
self.assertFalse(self.fsm.can('panic'))
self.assertTrue(self.fsm.cannot('panic'))
self.assertFalse(self.fsm.can('clam'))
self.assertFalse(self.fsm.can('clear'))
def test_state_changing(self):
self.assertTrue(self.fsm.isstate('green'))
self.fsm.warn()
self.assertTrue(self.fsm.isstate('yellow'))
def test_state_cannot_be_called_twice(self):
self.fsm.warn()
self.assertTrue(self.fsm.isstate('yellow'))
self.assertRaises(FysomError, self.fsm.warn)
def test_auto_next_state(self):
self.assertEqual('green', self.fsm.current)
self.assertEqual('yellow', self.fsm.next())
self.assertEqual('yellow', self.fsm.current)
def test_multiple_possibilities_for_next(self):
fsm = Fysom({
'initial': 'green',
'events': [
{'name': 'warn', 'src': 'green', 'dst': 'yellow'},
{'name': 'panic', 'src': 'yellow', 'dst': 'red'},
{'name': 'panic', 'src': 'green', 'dst': 'red'},
{'name': 'calm', 'src': 'red', 'dst': 'yellow'},
{'name': 'clear', 'src': 'yellow', 'dst': 'green'}
]
})
self.assertRaises(MultiplePossibilitesFound, fsm.next)
def test_no_possibility_for_next(self):
fsm = Fysom({
'initial': 'green',
'events': [
{'name': 'panic', 'src': 'yellow', 'dst': 'red'},
{'name': 'calm', 'src': 'red', 'dst': 'yellow'},
{'name': 'clear', 'src': 'yellow', 'dst': 'green'}
]
})
self.assertRaises(NoPossibilityFound, fsm.next)
def test_goto(self):
fsm = Fysom({
'initial': 'green',
'events': [
{'name': 'warn', 'src': 'green', 'dst': 'yellow'},
{'name': 'panic', 'src': 'yellow', 'dst': 'red'},
{'name': 'panic', 'src': 'green', 'dst': 'red'},
{'name': 'calm', 'src': 'red', 'dst': 'yellow'},
{'name': 'clear', 'src': 'yellow', 'dst': 'green'}
]
})
self.assertRaises(MultiplePossibilitesFound, fsm.next)
self.assertEqual('red', fsm.goto('panic'))
def test_no_possibility_for_goto(self):
fsm = Fysom({
'initial': 'green',
'events': [
{'name': 'warn', 'src': 'green', 'dst': 'yellow'},
{'name': 'panic', 'src': 'yellow', 'dst': 'red'},
{'name': 'panic', 'src': 'green', 'dst': 'red'},
# when call panic from green, we go to red, from red we
# should go to yellow, but it is commented and we should
# have a exception
# {'name': 'calm', 'src': 'red', 'dst': 'yellow'},
{'name': 'clear', 'src': 'yellow', 'dst': 'green'}
]
})
self.assertRaises(MultiplePossibilitesFound, fsm.next)
self.assertEqual('red', fsm.goto('panic'))
#.........这里部分代码省略.........
示例9: Fysom
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import warn [as 别名]
#!/usr/bin/python
from fysom import Fysom
print "Experimenting finite state machine package."
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' }
]})
print "Current state = " + fsm.current
print "Is in state 'red? = %r" % fsm.isstate('red')
print "Is in state 'green? = %r" % fsm.isstate('green')
print "Can fire event %s from state %s? = %r" % ('warn', fsm.current, fsm.can('warn'))
print "Can fire event %s from state %s? = %r" % ('panic', fsm.current, fsm.can('panic'))
print "Can fire event %s from state %s? = %r" % ('clear', fsm.current, fsm.can('clear'))
print ""
print "Firing event warn"
fsm.warn()
print "Current state = " + fsm.current
print "Is in state 'red? = %r" % fsm.isstate('red')
print "Is in state 'green? = %r" % fsm.isstate('green')
print "Can fire event %s from state %s? = %r" % ('warn', fsm.current, fsm.can('warn'))
print "Can fire event %s from state %s? = %r" % ('panic', fsm.current, fsm.can('panic'))
print "Can fire event %s from state %s? = %r" % ('clear', fsm.current, fsm.can('clear'))