当前位置: 首页>>代码示例>>Python>>正文


Python Machine._identify_callback方法代码示例

本文整理汇总了Python中transitions.Machine._identify_callback方法的典型用法代码示例。如果您正苦于以下问题:Python Machine._identify_callback方法的具体用法?Python Machine._identify_callback怎么用?Python Machine._identify_callback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在transitions.Machine的用法示例。


在下文中一共展示了Machine._identify_callback方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test___getattr___and_identify_callback

# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import _identify_callback [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)
开发者ID:Ak47slayer,项目名称:transitions,代码行数:65,代码来源:test_core.py

示例2: test___getattr___and_identify_callback

# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import _identify_callback [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)
开发者ID:khigia,项目名称:transitions,代码行数:65,代码来源:test_core.py


注:本文中的transitions.Machine._identify_callback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。