Skip to content

Commit

Permalink
fix tests and add typings for attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
devkral committed Jan 29, 2024
1 parent 39835c2 commit e4bd0cf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
12 changes: 10 additions & 2 deletions channels/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,13 @@ class BaseChannelLayer(ABC):

MAX_NAME_LENGTH = 100
extensions: Iterable[str] = ()
expiry: int
capacity: int
channel_capacity: Dict[str, int]

def __init__(
self,
expiry=60,
expiry: int = 60,
capacity: Optional[int] = 100,
channel_capacity: Optional[int] = None,
):
Expand Down Expand Up @@ -263,7 +266,12 @@ async def new_channel(self, prefix: str = "specific.") -> str:
"""


class InMemoryChannelLayer(WithFlushExtension, WithGroupsExtension, BaseChannelLayer):
# WARNING: Protocols must be last
class InMemoryChannelLayer(
BaseChannelLayer,
WithFlushExtension,
WithGroupsExtension,
):
"""
In-memory channel layer implementation
"""
Expand Down
14 changes: 13 additions & 1 deletion tests/test_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@
)


# when starting with Test it would be tried to collect by pytest
class StubChannelLayer(BaseChannelLayer):
async def send(self, channel: str, message: dict):
raise NotImplementedError()

async def receive(self, channel: str) -> dict:
raise NotImplementedError()

async def new_channel(self, prefix: str = "specific.") -> str:
raise NotImplementedError()


class TestChannelLayerManager(unittest.TestCase):
@override_settings(
CHANNEL_LAYERS={"default": {"BACKEND": "channels.layers.InMemoryChannelLayer"}}
Expand Down Expand Up @@ -72,7 +84,7 @@ async def test_send_receive():

@pytest.mark.parametrize(
"method",
[BaseChannelLayer().valid_channel_name, BaseChannelLayer().valid_group_name],
[StubChannelLayer().valid_channel_name, StubChannelLayer().valid_group_name],
)
@pytest.mark.parametrize(
"channel_name,expected_valid",
Expand Down

0 comments on commit e4bd0cf

Please sign in to comment.