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


Python EventManager.b_event方法代码示例

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


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

示例1: TestEventManager

# 需要导入模块: from event_manager import EventManager [as 别名]
# 或者: from event_manager.EventManager import b_event [as 别名]
class TestEventManager(unittest.TestCase):
    def setUp(self):
        self.event_manager = EventManager()
        self.client = MockClient(user_id='60')
        self.client2 = MockClient(user_id='50')

    def test_add_client(self):
        self.assertEqual(len(self.event_manager.clients), 0)

        self.event_manager.add_client(self.client)
        self.assertEqual(len(self.event_manager.clients), 1)
        self.assertEqual(self.event_manager.clients[self.client.user_id].user_id, self.client.user_id)

    def test_remove_client(self):
        self.event_manager.clients[self.client.user_id] = self.client
        self.assertEqual(len(self.event_manager.clients), 1)
        self.assertEqual(self.event_manager.clients[self.client.user_id].user_id, self.client.user_id)

        self.event_manager.remove_client(self.client.user_id)
        self.assertEqual(len(self.event_manager.clients), 0)

    def test_wrong_event(self):
        bogus_event = '666\F/60D50'
        with self.assertRaises(AssertionError):
            self.event_manager.receive_event(bogus_event)

    def test_follow_event_no_user(self):
        follow_event = '666|F|60|50'
        self.assertEqual(len(self.event_manager.clients), 0)
        self.assertEqual(len(self.event_manager.followers), 0)
        self.event_manager.receive_event(follow_event)
        self.assertEqual(len(self.event_manager.clients), 0)
        self.assertEqual(len(self.event_manager.followers), 1)
        self.assertIn('50', self.event_manager.followers)
        self.assertIn('60', self.event_manager.followers['50'])

    def test_follow_event_with_user(self):
        follow_event = '666|F|60|50'
        self.event_manager.add_client(self.client)
        self.event_manager.add_client(self.client2)
        self.assertEqual(len(self.event_manager.clients), 2)
        self.assertEqual(len(self.event_manager.followers), 0)
        self.event_manager.receive_event(follow_event)
        self.assertEqual(len(self.event_manager.clients), 2)
        self.assertEqual(len(self.event_manager.followers), 1)
        self.assertIn('50', self.event_manager.followers)
        self.assertIn('60', self.event_manager.followers['50'])

    def test_un_follow(self):
        self.event_manager.followers.setdefault('60', set()).add('50')
        response = self.event_manager.u_event('50', '60')
        self.assertEqual(len(self.event_manager.followers['60']), 0)
        self.assertEqual(len(response), 0)  # no one is informed

    def test_broadcast_event(self):
        self.event_manager.add_client(self.client)
        self.event_manager.add_client(self.client2)
        response = self.event_manager.b_event()
        self.assertEqual(len(response), 2)
        self.assertIn(self.client.user_id, response)
        self.assertIn(self.client2.user_id, response)

    def test_status_event(self):
        self.event_manager.followers.setdefault(self.client.user_id, set()).add(self.client2.user_id)
        response = self.event_manager.s_event(self.client.user_id)
        self.assertEqual(len(response), 1)
        self.assertIn(self.client2.user_id, response)

    def test_send_message_event(self):
        self.event_manager.followers.setdefault(self.client.user_id, set()).add(self.client2.user_id)
        response = self.event_manager.p_event(self.client.user_id, self.client2.user_id)
        self.assertEqual(len(response), 1)
        self.assertIn(self.client2.user_id, response)
开发者ID:ashkan18,项目名称:sc,代码行数:75,代码来源:test-event-manager.py


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