本文整理汇总了Python中context.Context.add_app_handler方法的典型用法代码示例。如果您正苦于以下问题:Python Context.add_app_handler方法的具体用法?Python Context.add_app_handler怎么用?Python Context.add_app_handler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类context.Context
的用法示例。
在下文中一共展示了Context.add_app_handler方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestContext
# 需要导入模块: from context import Context [as 别名]
# 或者: from context.Context import add_app_handler [as 别名]
class TestContext(unittest.TestCase):
def setUp(self):
self.target_method1 = MagicMock()
self.target_method2 = MagicMock()
self.context = Context()
def test_append_one_handler_to_one_control(self):
control_name = 'test'
self.context.add_app_handler('ActionEvent', control_name, self.target_method1)
event_arg = ActionEvent(control_name)
self.context.invoke(event_arg)
self.target_method1.assert_called_with(event_arg)
def test_append_two_handlers_to_one_control(self):
control_name = 'test'
self.context.add_app_handler('ActionEvent', control_name, self.target_method1)
self.context.add_app_handler('ActionEvent', control_name, self.target_method2)
event_arg = ActionEvent(control_name)
self.context.invoke(event_arg)
self.target_method1.assert_called_with(event_arg)
self.target_method2.assert_called_with(event_arg)
def test_append_handler_to_two_controls_and_invoke_one_crontrol(self):
control_name1 = 'test1'
control_name2 = 'test2'
self.context.add_app_handler('ActionEvent', control_name1, self.target_method1)
self.context.add_app_handler('ActionEvent', control_name2, self.target_method2)
event_arg = ActionEvent(control_name1)
self.context.invoke(event_arg)
self.target_method1.assert_called_with(event_arg)
self.target_method2.assert_not_called()
def test_append_two_command_types(self):
control_name = 'test'
self.context.add_app_handler('ActionEvent', control_name, self.target_method1)
self.context.add_app_handler('OpenEvent', control_name, self.target_method2)
event_arg = ActionEvent(control_name)
self.context.invoke(event_arg)
self.target_method1.assert_called_with(event_arg)
self.target_method2.assert_not_called()