Ejemplo n.º 1
0
    def test_comparison_the_same(self):
        async def simple_handler():
            pass

        self.assertEqual(Subscriber(simple_handler),
                         Subscriber(simple_handler))
        self.assertEqual(Subscriber(simple_handler), 'simple_handler')
Ejemplo n.º 2
0
    def test_subscriber_as_handler(self):
        async def just_handler():
            pass

        sub = Subscriber(just_handler)
        clone = Subscriber(sub)
        self.assertEqual(sub, clone)
        self.assertIsNot(sub, clone)
Ejemplo n.º 3
0
    def test_comparison_difference(self):
        async def first():
            pass

        async def second():
            pass

        self.assertNotEqual(Subscriber(first), Subscriber(second))
        self.assertNotEqual(Subscriber(first), second)
        self.assertIsNot(Subscriber(first), Subscriber(first))
Ejemplo n.º 4
0
    def test_identification(self):
        async def broadcaster():
            pass

        sub = Subscriber(broadcaster)
        expected_id = "<class 'eeee.event.Subscriber'>broadcaster</class>"
        self.assertEqual(sub.id, expected_id)
Ejemplo n.º 5
0
    def test_class_handler(self):
        class FooHandler:
            async def __call__(self):
                pass

        sub = Subscriber(FooHandler())
        self.assertIsInstance(sub.handler, FooHandler)
Ejemplo n.º 6
0
    def test_parse_handler_sub(self):
        async def some_coro():
            pass

        sub = Subscriber(some_coro)

        name, handler = _parse_handler(sub)
        self.assertEqual(name, 'some_coro')
        self.assertIs(handler, some_coro)
Ejemplo n.º 7
0
    def test_call_function_handler(self):
        async def test_func(message, publisher, event):
            return [message, publisher, event]

        sub = Subscriber(test_func)
        with Loop(sub('some message', None, 'test')) as loop:
            result = loop.run_until_complete()

        self.assertEqual(result[0], 'some message')
        self.assertIsNone(result[1])
        self.assertEqual(result[2], 'test')
Ejemplo n.º 8
0
    def test_call_class_handler(self):
        class TestCls:
            async def __call__(self, message, publisher, event):
                return [message, publisher, event]

        sub = Subscriber(TestCls())
        with Loop(sub('some message', None, 'test')) as loop:
            result = loop.run_until_complete()

        self.assertEqual(result[0], 'some message')
        self.assertIsNone(result[1])
        self.assertEqual(result[2], 'test')
Ejemplo n.º 9
0
 def test_raise_not_error(self):
     with self.assertRaises(exceptions.NotCallableError):
         Subscriber('foo')
Ejemplo n.º 10
0
    def test_not_callable_object_handler(self):
        class NotCallable:
            name = 'test'

        with self.assertRaises(exceptions.HandlerError):
            Subscriber(NotCallable())
Ejemplo n.º 11
0
 def test_handler_of_wrong_type(self):
     with self.assertRaises(exceptions.HandlerError):
         Subscriber(tuple)
Ejemplo n.º 12
0
    def test_not_coroutine_error(self):
        def handler():
            pass

        with self.assertRaises(exceptions.NotCoroutineError):
            Subscriber(handler)
Ejemplo n.º 13
0
    def test_function_handler(self):
        async def foo_handler():
            pass

        sub = Subscriber(foo_handler)
        self.assertIs(sub.handler, foo_handler)