async def test_remote_clip_map(self):
        c_client, c_server = pipe_bidi()

        rs = MockScript({})
        rss = RemoteScriptServer(rs, c_server)
        rsc = RemoteScript(c_client)

        async with timeout_context(rss, 10), timeout_context(rsc, 10):
            clips = await wait_for(rsc.retrieve_clips(), 10)
            self.assertEqual(len(clips), 1)
            self.assertEqual(list(clips), ["test"])
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
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 test_get_script(self):
        c_client, c_server = pipe_bidi()

        ms = MockScript({"id": id(self)})
        sp = SingleScriptProvider(ms)

        rsps = RemoteScriptProviderServer(sp, c_server)
        rspc = RemoteScriptProvider(c_client)

        async with timeout_context(rsps, 10), timeout_context(rspc, 10):
            rsc = await rspc.get()
            async with timeout_context(rsc, 10):
                self.assertEqual(await wait_for(rsc.get_config("id"), 10),
                                 id(self))
Exemplo n.º 6
0
    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)})
Exemplo n.º 7
0
 async def test_pipe_close_while_read(self):
     r, w = pipe()
     with r, w:
         fis = FileInputStream(r)
         async with timeout_context(fis, 5):
             Timer(1, lambda: w.close()).start()
             self.assertEqual(await wait_for(fis.read(), 5), None)
    async def test_remote_script_run(self):
        c_client, c_server = pipe_bidi()

        rs = MockScript({})
        rss = RemoteScriptServer(rs, c_server)
        rsc = RemoteScript(c_client)

        async with timeout_context(rss, 10), timeout_context(rsc, 10):
            await wait_for(rsc.run("test-code-string"), 10)
            self.assertEqual(
                await wait_for(rsc.get_config("last-command"), 10),
                "test-code-string")

            await wait_for(rsc.run(b"test-code-binary"), 10)
            self.assertEqual(
                await wait_for(rsc.get_config("last-command"), 10),
                b"test-code-binary")
Exemplo n.º 9
0
 async def test_pipe_read(self):
     r, w = pipe()
     with r, w:
         fis = FileInputStream(r)
         async with timeout_context(fis, 5):
             msg = Message({"test": id(self)}, [])
             w.write(ByteOutputStream.write_message(msg))
             w.flush()
             self.assertEqual(await wait_for(fis.read(), 5), msg)
    async def test_remote_script_config(self):
        c_client, c_server = pipe_bidi()

        rs = MockScript({
            "test-int": 1,
            "test-bytes": b"abc",
            "test-null": None,
            "test-string": "foo",
            "test-float": 3.1415926
        })
        unset = object()

        rss = RemoteScriptServer(rs, c_server)
        rsc = RemoteScript(c_client)

        async with timeout_context(rss, 10), timeout_context(rsc, 10):
            self.assertEqual(await wait_for(rsc.list_config(), 10), [
                "test-int", "test-bytes", "test-null", "test-string",
                "test-float"
            ])
            self.assertEqual(await wait_for(rsc.get_config("test-int"), 10), 1)
            self.assertEqual(await wait_for(rsc.get_config("test-bytes"), 10),
                             b"abc")
            self.assertIsNone(await wait_for(rsc.get_config("test-null"), 10))
            self.assertEqual(await wait_for(rsc.get_config("test-float"), 10),
                             3.1415926)
            self.assertEqual(await wait_for(rsc.get_config("test-string"), 10),
                             "foo")
            with self.assertRaises(KeyError):
                await wait_for(rsc.get_config("test-unset"), 10)
            self.assertIs(
                await wait_for(rsc.get_config("test-unset", unset), 10), unset)

            for val in [2, b"def", None, 6.2831852, "bar"]:
                await wait_for(rsc.set_config("test-set", val), 10)
                self.assertEqual(await wait_for(rsc.list_config(), 10), [
                    "test-int", "test-bytes", "test-null", "test-string",
                    "test-float", "test-set"
                ])
                self.assertEqual(
                    await wait_for(rsc.get_config("test-set"), 10), val)