本文整理汇总了Python中transitions.Machine.add_model方法的典型用法代码示例。如果您正苦于以下问题:Python Machine.add_model方法的具体用法?Python Machine.add_model怎么用?Python Machine.add_model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类transitions.Machine
的用法示例。
在下文中一共展示了Machine.add_model方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_garbage_collection
# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import add_model [as 别名]
def test_garbage_collection(self):
states = ['A', 'B', 'C', 'D', 'E', 'F']
machine = Machine(model=[], states=states, initial='A', name='Test Machine')
machine.add_transition('advance', 'A', 'B')
machine.add_transition('advance', 'B', 'C')
machine.add_transition('advance', 'C', 'D')
s1 = Dummy()
s2 = Dummy()
s2_collected = threading.Event()
s2_proxy = weakref.proxy(s2, lambda _: s2_collected.set())
machine.add_model([s1, s2])
self.assertTrue(s1.is_A())
self.assertTrue(s2.is_A())
s1.advance()
self.assertTrue(s1.is_B())
self.assertTrue(s2.is_A())
self.assertFalse(s2_collected.is_set())
machine.remove_model(s2)
del s2
gc.collect()
self.assertTrue(s2_collected.is_set())
s3 = Dummy()
machine.add_model(s3)
s3.advance()
s3.advance()
self.assertTrue(s3.is_C())
示例2: test_dispatch
# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import add_model [as 别名]
def test_dispatch(self):
s1, s2 = Stuff(), Stuff()
states = ['A', 'B', 'C']
m = Machine(model=s1, states=states, ignore_invalid_triggers=True,
initial=states[0], transitions=[['go', 'A', 'B'], ['go', 'B', 'C']])
m.add_model(s2, initial='B')
m.dispatch('go')
self.assertEqual(s1.state, 'B')
self.assertEqual(s2.state, 'C')
示例3: test_add_model_initial_state
# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import add_model [as 别名]
def test_add_model_initial_state(self):
states = ['A', 'B', 'C', 'D', 'E', 'F']
machine = Machine(model=[], states=states, initial='A', name='Test Machine')
machine.add_transition('advance', 'A', 'B')
machine.add_transition('advance', 'B', 'C')
machine.add_transition('advance', 'C', 'D')
s1 = Dummy()
s2 = Dummy()
s3 = Dummy()
machine.add_model(s1)
machine.add_model(s2, initial='B')
machine.add_model(s3, initial='C')
s1.advance()
s2.advance()
s3.advance()
self.assertTrue(s1.is_B())
self.assertTrue(s2.is_C())
self.assertTrue(s3.is_D())