Skip to content

Commit b5bb16b

Browse files
committed
fix tests
1 parent 39835c2 commit b5bb16b

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

channels/layers.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,13 @@ class BaseChannelLayer(ABC):
147147

148148
MAX_NAME_LENGTH = 100
149149
extensions: Iterable[str] = ()
150+
expiry: int
151+
capacity: int
152+
channel_capacity: Dict[str, int]
150153

151154
def __init__(
152155
self,
153-
expiry=60,
156+
expiry: int = 60,
154157
capacity: Optional[int] = 100,
155158
channel_capacity: Optional[int] = None,
156159
):
@@ -263,7 +266,12 @@ async def new_channel(self, prefix: str = "specific.") -> str:
263266
"""
264267

265268

266-
class InMemoryChannelLayer(WithFlushExtension, WithGroupsExtension, BaseChannelLayer):
269+
# WARNING: Protocols must be last
270+
class InMemoryChannelLayer(
271+
BaseChannelLayer,
272+
WithFlushExtension,
273+
WithGroupsExtension,
274+
):
267275
"""
268276
In-memory channel layer implementation
269277
"""

tests/test_layers.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
)
1414

1515

16+
# when starting with Test it would be tried to collect by pytest
17+
class StubChannelLayer(BaseChannelLayer):
18+
async def send(self, channel: str, message: dict):
19+
raise NotImplementedError()
20+
21+
async def receive(self, channel: str) -> dict:
22+
raise NotImplementedError()
23+
24+
async def new_channel(self, prefix: str = "specific.") -> str:
25+
raise NotImplementedError()
26+
27+
1628
class TestChannelLayerManager(unittest.TestCase):
1729
@override_settings(
1830
CHANNEL_LAYERS={"default": {"BACKEND": "channels.layers.InMemoryChannelLayer"}}
@@ -72,7 +84,7 @@ async def test_send_receive():
7284

7385
@pytest.mark.parametrize(
7486
"method",
75-
[BaseChannelLayer().valid_channel_name, BaseChannelLayer().valid_group_name],
87+
[StubChannelLayer().valid_channel_name, StubChannelLayer().valid_group_name],
7688
)
7789
@pytest.mark.parametrize(
7890
"channel_name,expected_valid",

0 commit comments

Comments
 (0)