From 13b20caefaf9541d10bd7cc2e58cb200193636b1 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Wed, 4 Feb 2026 20:47:14 +0000 Subject: [PATCH] unit tests --- tests/async/test_pubsub_manager.py | 13 +++++++++++++ tests/async/test_redis_manager.py | 15 ++++++++++++++- tests/common/test_pubsub_manager.py | 13 +++++++++++++ tests/common/test_redis_manager.py | 15 ++++++++++++++- tox.ini | 2 +- 5 files changed, 55 insertions(+), 3 deletions(-) diff --git a/tests/async/test_pubsub_manager.py b/tests/async/test_pubsub_manager.py index abf41a2..40966bf 100644 --- a/tests/async/test_pubsub_manager.py +++ b/tests/async/test_pubsub_manager.py @@ -5,8 +5,10 @@ from unittest import mock import pytest +from engineio.packet import Packet as EIOPacket from socketio import async_manager from socketio import async_pubsub_manager +from socketio import async_server from socketio import packet @@ -846,3 +848,14 @@ class TestAsyncPubSubManager: self.pm._handle_emit.assert_awaited_with( {'method': 'emit', 'value': 'bar', 'host_id': 'x'} ) + + def test_custom_json(self): + saved_json = packet.Packet.json + + cm = async_pubsub_manager.AsyncPubSubManager(json='foo') + assert cm.json == 'foo' + async_server.AsyncServer(json='bar', client_manager=cm) + assert cm.json == 'bar' + + packet.Packet.json = saved_json + EIOPacket.json = saved_json diff --git a/tests/async/test_redis_manager.py b/tests/async/test_redis_manager.py index 046c26d..16fa4ca 100644 --- a/tests/async/test_redis_manager.py +++ b/tests/async/test_redis_manager.py @@ -2,8 +2,10 @@ import pytest import redis import valkey -from socketio import async_redis_manager +from engineio.packet import Packet as EIOPacket +from socketio import async_redis_manager, AsyncServer from socketio.async_redis_manager import AsyncRedisManager +from socketio.packet import Packet class TestAsyncRedisManager: @@ -109,3 +111,14 @@ class TestAsyncRedisManager: assert isinstance(c.redis, valkey.asyncio.Valkey) async_redis_manager.aioredis = saved_redis + + def test_custom_json(self): + saved_json = Packet.json + + cm = AsyncRedisManager('redis://', json='foo') + assert cm.json == 'foo' + AsyncServer(json='bar', client_manager=cm) + assert cm.json == 'bar' + + Packet.json = saved_json + EIOPacket.json = saved_json diff --git a/tests/common/test_pubsub_manager.py b/tests/common/test_pubsub_manager.py index 91b7785..252c77f 100644 --- a/tests/common/test_pubsub_manager.py +++ b/tests/common/test_pubsub_manager.py @@ -5,9 +5,11 @@ from unittest import mock import pytest +from engineio.packet import Packet as EIOPacket from socketio import manager from socketio import pubsub_manager from socketio import packet +from socketio import server class TestPubSubManager: @@ -822,3 +824,14 @@ class TestPubSubManager: self.pm._handle_emit.assert_called_with( {'method': 'emit', 'value': 'bar', 'host_id': 'x'} ) + + def test_custom_json(self): + saved_json = packet.Packet.json + + cm = pubsub_manager.PubSubManager(json='foo') + assert cm.json == 'foo' + server.Server(json='bar', client_manager=cm) + assert cm.json == 'bar' + + packet.Packet.json = saved_json + EIOPacket.json = saved_json diff --git a/tests/common/test_redis_manager.py b/tests/common/test_redis_manager.py index dbc927e..3f4e29c 100644 --- a/tests/common/test_redis_manager.py +++ b/tests/common/test_redis_manager.py @@ -2,7 +2,9 @@ import pytest import redis import valkey -from socketio import redis_manager +from engineio.packet import Packet as EIOPacket +from socketio import redis_manager, Server +from socketio.packet import Packet from socketio.redis_manager import RedisManager, parse_redis_sentinel_url @@ -144,3 +146,14 @@ class TestPubSubManager: 'myredis', {'username': 'user', 'password': 'password', 'db': 0} ) + + def test_custom_json(self): + saved_json = Packet.json + + cm = RedisManager('redis://', json='foo') + assert cm.json == 'foo' + Server(json='bar', client_manager=cm) + assert cm.json == 'bar' + + Packet.json = saved_json + EIOPacket.json = saved_json diff --git a/tox.ini b/tox.ini index 02297a2..0ffa92e 100644 --- a/tox.ini +++ b/tox.ini @@ -14,7 +14,7 @@ python = [testenv] commands= pip install -e . - pytest -p no:logging --timeout=60 --cov=socketio --cov-branch --cov-report=term-missing --cov-report=xml + pytest -p no:logging --timeout=60 --cov=socketio --cov-branch --cov-report=term-missing --cov-report=xml {posargs} deps= simple-websocket uvicorn