test: bunch of tests
Written with AI, still need to check them ref: N25B-449
This commit is contained in:
40
test/unit/test_main_sockets.py
Normal file
40
test/unit/test_main_sockets.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import zmq
|
||||
|
||||
from control_backend.main import setup_sockets
|
||||
|
||||
|
||||
def test_setup_sockets_proxy():
|
||||
mock_context = MagicMock()
|
||||
mock_pub = MagicMock()
|
||||
mock_sub = MagicMock()
|
||||
|
||||
mock_context.socket.side_effect = [mock_pub, mock_sub]
|
||||
|
||||
with patch("zmq.asyncio.Context.instance", return_value=mock_context):
|
||||
with patch("zmq.proxy") as mock_proxy:
|
||||
setup_sockets()
|
||||
|
||||
mock_pub.bind.assert_called()
|
||||
mock_sub.bind.assert_called()
|
||||
mock_proxy.assert_called_with(mock_sub, mock_pub)
|
||||
|
||||
# Check cleanup
|
||||
mock_pub.close.assert_called()
|
||||
mock_sub.close.assert_called()
|
||||
|
||||
|
||||
def test_setup_sockets_proxy_error():
|
||||
mock_context = MagicMock()
|
||||
mock_pub = MagicMock()
|
||||
mock_sub = MagicMock()
|
||||
mock_context.socket.side_effect = [mock_pub, mock_sub]
|
||||
|
||||
with patch("zmq.asyncio.Context.instance", return_value=mock_context):
|
||||
with patch("zmq.proxy", side_effect=zmq.ZMQError):
|
||||
with patch("control_backend.main.logger") as mock_logger:
|
||||
setup_sockets()
|
||||
mock_logger.warning.assert_called()
|
||||
mock_pub.close.assert_called()
|
||||
mock_sub.close.assert_called()
|
||||
Reference in New Issue
Block a user