async def test_clip_length(self): c_client, c_server = pipe_bidi() mock_clip = MockClip() async with mock_clip: server = ClipServer(mock_clip, c_server) client = RemoteClip(c_client) # Make sure the server is acquired first, as otherwise # there will be a deadlock. async with server, client: self.assertEqual(len(client), len(mock_clip))
async def test_clip_metadata_transmit(self): c_client, c_server = pipe_bidi() mock_clip = MockClip() async with mock_clip: server = ClipServer(mock_clip, c_server) client = RemoteClip(c_client) # Make sure the server is acquired first, as otherwise # there will be a deadlock. async with server, client: self.assertEqual(await wait_for(client.get_metadata(), 5), {"id": id(mock_clip)})
async def test_clip_frame_size(self): c_client, c_server = pipe_bidi() mock_frame = MockFrame() mock_clip = SingleFrameMockClip(mock_frame) async with mock_clip, mock_frame: server = ClipServer(mock_clip, c_server) client = RemoteClip(c_client) # Make sure the server is acquired first, as otherwise # there will be a deadlock. async with timeout_context(server, 10), timeout_context(client, 10): remote_frame = client[0] async with remote_frame: self.assertEqual(remote_frame.size, mock_frame.size)
async def test_clip_frame_render(self): c_client, c_server = pipe_bidi() mock_clip = MockClip() async with mock_clip: server = ClipServer(mock_clip, c_server) client = RemoteClip(c_client) # Make sure the server is acquired first, as otherwise # there will be a deadlock. async with timeout_context(server, 10), timeout_context(client, 10): remote_frame = client[0] async with remote_frame: data = bytearray(remote_frame.native_format.get_plane_size(0, remote_frame.size)) self.assertEqual(await remote_frame.render_into(data, 0, remote_frame.native_format, 0), 0)
async def test_clip_frame_can_render(self): c_client, c_server = pipe_bidi() mock_clip = MockClip() async with mock_clip: server = ClipServer(mock_clip, c_server) client = RemoteClip(c_client) # Make sure the server is acquired first, as otherwise # there will be a deadlock. async with timeout_context(server, 10), timeout_context(client, 10): remote_frame = client[0] async with remote_frame: self.assertFalse(await remote_frame.can_render(GRAY8)) self.assertTrue(await remote_frame.can_render(RGB24))
async def on_register_clip(self, channel: str, name: str): conn = self.multiplexer.connect(channel) register(self, conn) await conn.acquire() clips = await self.script.retrieve_clips() clip = clips[name] server = ClipServer(clip, conn) register(conn, server) await server.acquire() self.connections[channel] = conn return Message({}, [])
async def test_clip_frame_metadata(self): c_client, c_server = pipe_bidi() mock_frame = MockFrame() mock_clip = SingleFrameMockClip(mock_frame) async with mock_clip, mock_frame: server = ClipServer(mock_clip, c_server) client = RemoteClip(c_client) # Make sure the server is acquired first, as otherwise # there will be a deadlock. async with timeout_context(server, 10), timeout_context(client, 10): remote_frame = client[0] async with remote_frame: metadata = await wait_for(remote_frame.get_metadata(), 5) self.assertEqual(metadata, {"id": id(mock_frame)})