tests (unit): Fix tests.

This commit is contained in:
Goffi 2025-12-03 17:43:06 +01:00
commit e68278a1ac

View file

@ -24,6 +24,8 @@ try:
except ImportError:
pytest.skip("Gst not available.", allow_module_level=True)
from pytest_twisted import ensureDeferred as ed
from libervia.backend.core import exceptions
from libervia.backend.tools.common import data_format
from libervia.frontends.tools import webrtc as webrtc_mod
@ -95,7 +97,7 @@ class TestWebRtc:
assert webrtc.webrtcbin.emit.call_count == 1
assert webrtc.webrtcbin.emit.call_args[0][0] == "set-remote-description"
@pytest.mark.asyncio
@ed
async def test_answer_call(self, webrtc, monkeypatch):
"""The method correctly answers an incoming call."""
mock_setup_call = AsyncMock()
@ -128,12 +130,11 @@ class TestWebRtc:
mock_pad.has_current_caps.return_value = True
mock_pad.get_current_caps.return_value = mock_caps
mock_caps.__len__.return_value = 1
mock_caps.__getitem__.return_value = mock_structure
mock_caps.get_structure.return_value = mock_structure
mock_structure.get_name.return_value = "video/x-h264"
# We use non-standard resolution as example to trigger the workaround
mock_structure.get_int.side_effect = lambda x: MagicMock(
value=990 if x == "width" else 557
mock_structure.get_int = MagicMock(
side_effect=lambda x: (0, 990) if x == "width" else (0, 557)
)
webrtc.on_remote_decodebin_stream(None, mock_pad)
@ -153,8 +154,7 @@ class TestWebRtc:
mock_pad.has_current_caps.return_value = True
mock_pad.get_current_caps.return_value = mock_caps
mock_caps.__len__.return_value = 1
mock_caps.__getitem__.return_value = mock_structure
mock_caps.get_structure.return_value = mock_structure
mock_structure.get_name.return_value = "audio/x-raw"
webrtc.on_remote_decodebin_stream(None, mock_pad)
@ -163,7 +163,7 @@ class TestWebRtc:
mock_pad.link.assert_called()
@pytest.mark.skipif(Gst is None, reason="GStreamer is not available")
@pytest.mark.asyncio
@ed
async def test_setup_call_correct_role(self, host, webrtc, monkeypatch):
"""Roles are set in setup_call."""
monkeypatch.setattr(Gst, "parse_launch", MagicMock())
@ -181,7 +181,7 @@ class TestWebRtc:
with pytest.raises(AssertionError):
await webrtc.setup_call("invalid_role")
@pytest.mark.asyncio
@ed
async def test_setup_call_test_mode(self, host, webrtc, monkeypatch):
"""Test mode use fake video and audio in setup_call."""
monkeypatch.setattr(data_format, "deserialise", MagicMock(return_value=[]))
@ -190,7 +190,7 @@ class TestWebRtc:
assert "videotestsrc" in webrtc.gst_pipe_desc
assert "audiotestsrc" in webrtc.gst_pipe_desc
@pytest.mark.asyncio
@ed
async def test_setup_call_normal_mode(self, host, webrtc, monkeypatch):
"""Normal mode use real video and audio in setup_call."""
monkeypatch.setattr(data_format, "deserialise", MagicMock(return_value=[]))
@ -200,7 +200,7 @@ class TestWebRtc:
assert "pulsesrc" in webrtc.gst_pipe_desc
@pytest.mark.skipif(Gst is None, reason="GStreamer is not available")
@pytest.mark.asyncio
@ed
async def test_setup_call_with_stun_and_turn(self, host, webrtc, monkeypatch):
"""STUN and TURN server configurations are done in setup_call."""
mock_pipeline = MagicMock()
@ -244,7 +244,7 @@ class TestWebRtc:
)
@pytest.mark.skipif(Gst is None, reason="GStreamer is not available")
@pytest.mark.asyncio
@ed
async def test_setup_call_gstreamer_pipeline_failure(self, webrtc, monkeypatch):
"""Test setup_call method handling Gstreamer pipeline failure."""
monkeypatch.setattr(Gst, "parse_launch", lambda _: None)