本文整理汇总了Python中transitions.Machine.__getattr__方法的典型用法代码示例。如果您正苦于以下问题:Python Machine.__getattr__方法的具体用法?Python Machine.__getattr__怎么用?Python Machine.__getattr__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类transitions.Machine
的用法示例。
在下文中一共展示了Machine.__getattr__方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test___getattr___and_identify_callback
# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import __getattr__ [as 别名]
def test___getattr___and_identify_callback(self):
m = Machine(Stuff(), states=['A', 'B', 'C'], initial='A')
m.add_transition('move', 'A', 'B')
m.add_transition('move', 'B', 'C')
callback = m.__getattr__('before_move')
self.assertTrue(callable(callback))
with self.assertRaises(MachineError):
m.__getattr__('before_no_such_transition')
with self.assertRaises(MachineError):
m.__getattr__('before_no_such_transition')
with self.assertRaises(AttributeError):
m.__getattr__('__no_such_method__')
with self.assertRaises(AttributeError):
m.__getattr__('')
type, target = m._identify_callback('on_exit_foobar')
self.assertEqual(type, 'on_exit')
self.assertEqual(target, 'foobar')
type, target = m._identify_callback('on_exitfoobar')
self.assertEqual(type, None)
self.assertEqual(target, None)
type, target = m._identify_callback('notacallback_foobar')
self.assertEqual(type, None)
self.assertEqual(target, None)
type, target = m._identify_callback('totallyinvalid')
self.assertEqual(type, None)
self.assertEqual(target, None)
type, target = m._identify_callback('before__foobar')
self.assertEqual(type, 'before')
self.assertEqual(target, '_foobar')
type, target = m._identify_callback('before__this__user__likes__underscores___')
self.assertEqual(type, 'before')
self.assertEqual(target, '_this__user__likes__underscores___')
type, target = m._identify_callback('before_stuff')
self.assertEqual(type, 'before')
self.assertEqual(target, 'stuff')
type, target = m._identify_callback('before_trailing_underscore_')
self.assertEqual(type, 'before')
self.assertEqual(target, 'trailing_underscore_')
type, target = m._identify_callback('before_')
self.assertIs(type, None)
self.assertIs(target, None)
type, target = m._identify_callback('__')
self.assertIs(type, None)
self.assertIs(target, None)
type, target = m._identify_callback('')
self.assertIs(type, None)
self.assertIs(target, None)
示例2: test___getattr___and_identify_callback
# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import __getattr__ [as 别名]
def test___getattr___and_identify_callback(self):
m = Machine(Stuff(), states=["A", "B", "C"], initial="A")
m.add_transition("move", "A", "B")
m.add_transition("move", "B", "C")
callback = m.__getattr__("before_move")
self.assertTrue(callable(callback))
with self.assertRaises(MachineError):
m.__getattr__("before_no_such_transition")
with self.assertRaises(MachineError):
m.__getattr__("before_no_such_transition")
with self.assertRaises(AttributeError):
m.__getattr__("__no_such_method__")
with self.assertRaises(AttributeError):
m.__getattr__("")
type, target = m._identify_callback("on_exit_foobar")
self.assertEqual(type, "on_exit")
self.assertEqual(target, "foobar")
type, target = m._identify_callback("on_exitfoobar")
self.assertEqual(type, None)
self.assertEqual(target, None)
type, target = m._identify_callback("notacallback_foobar")
self.assertEqual(type, None)
self.assertEqual(target, None)
type, target = m._identify_callback("totallyinvalid")
self.assertEqual(type, None)
self.assertEqual(target, None)
type, target = m._identify_callback("before__foobar")
self.assertEqual(type, "before")
self.assertEqual(target, "_foobar")
type, target = m._identify_callback("before__this__user__likes__underscores___")
self.assertEqual(type, "before")
self.assertEqual(target, "_this__user__likes__underscores___")
type, target = m._identify_callback("before_stuff")
self.assertEqual(type, "before")
self.assertEqual(target, "stuff")
type, target = m._identify_callback("before_trailing_underscore_")
self.assertEqual(type, "before")
self.assertEqual(target, "trailing_underscore_")
type, target = m._identify_callback("before_")
self.assertIs(type, None)
self.assertIs(target, None)
type, target = m._identify_callback("__")
self.assertIs(type, None)
self.assertIs(target, None)
type, target = m._identify_callback("")
self.assertIs(type, None)
self.assertIs(target, None)