File: test_asgi_helpers.py

package info (click to toggle)
python-falcon 4.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,172 kB
  • sloc: python: 33,608; javascript: 92; sh: 50; makefile: 50
file content (32 lines) | stat: -rw-r--r-- 738 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import inspect

from falcon.asgi import _asgi_helpers


class IntricateApp:
    def unorthodox_call(self, scope, receive, send):
        return self._call_factory(scope, receive, send)

    async def _call_factory(self, scope, receive, send):
        await send('Hello!')
        await send('Bye.')

    __call__ = _asgi_helpers._wrap_asgi_coroutine_func(unorthodox_call)


async def test_intricate_app():
    async def receive():
        pass

    async def send(msg):
        messages.append(msg)

    app = IntricateApp()
    messages = []

    assert not inspect.iscoroutinefunction(app.unorthodox_call)
    assert inspect.iscoroutinefunction(app.__call__)

    await app({}, receive, send)

    assert messages == ['Hello!', 'Bye.']