Skip to content

Commit

Permalink
updated test_compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
davitacols committed Dec 24, 2023
1 parent 701b0c7 commit 3e7989e
Showing 1 changed file with 19 additions and 43 deletions.
62 changes: 19 additions & 43 deletions tests/test_compatibility.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
import pytest

from asgiref.compatibility import double_to_single_callable, is_double_callable
from asgiref.testing import ApplicationCommunicator


def double_application_function(scope):
"""
A nested function based double-callable application.
"""

"""A nested function-based double-callable application."""
async def inner(receive, send):
message = await receive()
await send({"scope": scope["value"], "message": message["value"]})

return inner


class DoubleApplicationClass:
"""
A classic class-based double-callable application.
"""

"""A classic class-based double-callable application."""
def __init__(self, scope):
pass

Expand All @@ -29,66 +21,50 @@ async def __call__(self, receive, send):


class DoubleApplicationClassNestedFunction:
"""
A function closure inside a class!
"""

"""A function closure inside a class."""
def __init__(self):
pass

def __call__(self, scope):
async def inner(receive, send):
pass

return inner


async def single_application_function(scope, receive, send):
"""
A single-function single-callable application
"""
"""A single-function single-callable application."""
pass


class SingleApplicationClass:
"""
A single-callable class (where you'd pass the class instance in,
e.g. middleware)
"""

"""A single-callable class."""
def __init__(self):
pass

async def __call__(self, scope, receive, send):
pass


def test_is_double_callable():
"""
Tests that the signature matcher works as expected.
"""
assert is_double_callable(double_application_function) is True
assert is_double_callable(DoubleApplicationClass) is True
assert is_double_callable(DoubleApplicationClassNestedFunction()) is True
assert is_double_callable(single_application_function) is False
assert is_double_callable(SingleApplicationClass()) is False
@pytest.mark.asyncio
async def test_is_double_callable():
"""Test the behavior of is_double_callable function."""
assert is_double_callable(double_application_function)
assert is_double_callable(DoubleApplicationClass)
assert is_double_callable(DoubleApplicationClassNestedFunction())
assert not is_double_callable(single_application_function)
assert not is_double_callable(SingleApplicationClass())


def test_double_to_single_signature():
"""
Test that the new object passes a signature test.
"""
assert (
is_double_callable(double_to_single_callable(double_application_function))
is False
)
@pytest.mark.asyncio
async def test_double_to_single_callable():
"""Test the behavior of double_to_single_callable function."""
new_app = double_to_single_callable(double_application_function)
assert not is_double_callable(new_app)


@pytest.mark.asyncio
async def test_double_to_single_communicator():
"""
Test that the new application works
"""
"""Test the behavior of the new application using ApplicationCommunicator."""
new_app = double_to_single_callable(double_application_function)
instance = ApplicationCommunicator(new_app, {"value": "woohoo"})
await instance.send_input({"value": 42})
Expand Down

0 comments on commit 3e7989e

Please sign in to comment.