comparison tests/unit/frontends/test_webrtc.py @ 4285:f1d0cde61af7

tests (unit): fix tests + black reformatting.
author Goffi <goffi@goffi.org>
date Sun, 14 Jul 2024 17:42:53 +0200
parents 0fbe5c605eb6
children
comparison
equal deleted inserted replaced
4284:3a550e9a2b55 4285:f1d0cde61af7
25 pytest.skip("Gst not available.", allow_module_level=True) 25 pytest.skip("Gst not available.", allow_module_level=True)
26 26
27 from libervia.backend.core import exceptions 27 from libervia.backend.core import exceptions
28 from libervia.backend.tools.common import data_format 28 from libervia.backend.tools.common import data_format
29 from libervia.frontends.tools import webrtc as webrtc_mod 29 from libervia.frontends.tools import webrtc as webrtc_mod
30
31 30
32 31
33 @pytest.fixture 32 @pytest.fixture
34 def host(monkeypatch): 33 def host(monkeypatch):
35 host = MagicMock() 34 host = MagicMock()
36 host.bridge = AsyncMock() 35 host.bridge = AsyncMock()
37 host.app.expand = lambda s: s 36 host.app.expand = lambda s: s
38 return host 37 return host
38
39 39
40 @pytest.fixture(scope="function") 40 @pytest.fixture(scope="function")
41 def webrtc(host): 41 def webrtc(host):
42 """Fixture for WebRTC instantiation.""" 42 """Fixture for WebRTC instantiation."""
43 profile = "test_profile" 43 profile = "test_profile"
183 183
184 @pytest.mark.asyncio 184 @pytest.mark.asyncio
185 async def test_setup_call_test_mode(self, host, webrtc, monkeypatch): 185 async def test_setup_call_test_mode(self, host, webrtc, monkeypatch):
186 """Test mode use fake video and audio in setup_call.""" 186 """Test mode use fake video and audio in setup_call."""
187 monkeypatch.setattr(data_format, "deserialise", MagicMock(return_value=[])) 187 monkeypatch.setattr(data_format, "deserialise", MagicMock(return_value=[]))
188 monkeypatch.setattr(webrtc, "sources", webrtc_mod.SINKS_TEST) 188 monkeypatch.setattr(webrtc, "sources_data", webrtc_mod.SourcesTest())
189 await webrtc.setup_call("initiator") 189 await webrtc.setup_call("initiator")
190 assert "videotestsrc" in webrtc.gst_pipe_desc 190 assert "videotestsrc" in webrtc.gst_pipe_desc
191 assert "audiotestsrc" in webrtc.gst_pipe_desc 191 assert "audiotestsrc" in webrtc.gst_pipe_desc
192 192
193 @pytest.mark.asyncio 193 @pytest.mark.asyncio
194 async def test_setup_call_normal_mode(self, host, webrtc, monkeypatch): 194 async def test_setup_call_normal_mode(self, host, webrtc, monkeypatch):
195 """Normal mode use real video and audio in setup_call.""" 195 """Normal mode use real video and audio in setup_call."""
196 monkeypatch.setattr(data_format, "deserialise", MagicMock(return_value=[])) 196 monkeypatch.setattr(data_format, "deserialise", MagicMock(return_value=[]))
197 monkeypatch.setattr(webrtc, "sources", webrtc_mod.SOURCES_AUTO) 197 monkeypatch.setattr(webrtc, "sources_data", webrtc_mod.SourcesAuto())
198 await webrtc.setup_call("initiator") 198 await webrtc.setup_call("initiator")
199 assert "v4l2src" in webrtc.gst_pipe_desc 199 assert "v4l2src" in webrtc.gst_pipe_desc
200 assert "pulsesrc" in webrtc.gst_pipe_desc 200 assert "pulsesrc" in webrtc.gst_pipe_desc
201 201
202 @pytest.mark.skipif(Gst is None, reason="GStreamer is not available") 202 @pytest.mark.skipif(Gst is None, reason="GStreamer is not available")