From 3952954c12ac2a908f3ba13c070dedc9a7bca3cf Mon Sep 17 00:00:00 2001 From: mntng Date: Mon, 28 Aug 2017 22:39:32 +0800 Subject: [PATCH] add unitttest for artiq_rpctool --- artiq/test/test_rpctool.py | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 artiq/test/test_rpctool.py diff --git a/artiq/test/test_rpctool.py b/artiq/test/test_rpctool.py new file mode 100644 index 000000000..f07b2cb78 --- /dev/null +++ b/artiq/test/test_rpctool.py @@ -0,0 +1,39 @@ +import os +import sys +import asyncio +import unittest + +from artiq.protocols.pc_rpc import Server + + +class Target: + def output_value(self): + return 4125380 + + +class TestRPCTool(unittest.TestCase): + async def check_value(self): + proc = await asyncio.create_subprocess_exec( + sys.executable, "-m", "artiq.frontend.artiq_rpctool", "::1", "7777", "call", "output_value", + stdout = asyncio.subprocess.PIPE) + (value, err) = await proc.communicate() + self.assertEqual(value.decode('ascii').rstrip(), '4125380') + await proc.wait() + + async def do_test(self): + server = Server({"target": Target()}) + await server.start("::1", 7777) + await self.check_value() + await server.stop() + + def test_rpc(self): + if os.name == "nt": + loop = asyncio.ProactorEventLoop() + asyncio.set_event_loop(loop) + else: + loop = asyncio.get_event_loop() + try: + loop.run_until_complete(self.do_test()) + finally: + loop.close() +