async def test_run_ftl_module(): os.chdir(HERE) ftl_gate = build_ftl_gate() proc = await asyncio.create_subprocess_shell( ftl_gate, stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE) try: send_message(proc.stdin, 'Hello', {}) message = await read_message(proc.stdout) assert message[0] == "Hello" assert message[1] == {} with open(find_module(['ftl_modules'], 'argtest'), 'rb') as f: module = base64.b64encode(f.read()).decode() send_message(proc.stdin, 'FTLModule', dict(module=module, module_name='argtest')) message = await read_message(proc.stdout) assert message[0] != "GateSystemError", message[1] assert message[0] == "FTLModuleResult" assert message[1] != {} assert message[1]['result'] finally: send_message(proc.stdin, 'Shutdown', {}) await proc.wait() os.unlink(ftl_gate) clean_up_tmp()
def main(args: Optional[List[str]] = None) -> int: if args is None: args = sys.argv[1:] parsed_args = docopt(__doc__, args) if parsed_args['--debug']: logging.basicConfig(level=logging.DEBUG) elif parsed_args['--verbose']: logging.basicConfig(level=logging.INFO) else: logging.basicConfig(level=logging.WARNING) dependencies = None if parsed_args['--requirements']: with open(parsed_args['--requirements']) as f: dependencies = [x for x in f.read().splitlines() if x] modules = [] module_dirs = [] if parsed_args['--module']: modules.append(parsed_args['--module']) if parsed_args['--module-dir']: module_dirs.append(parsed_args['--module-dir']) interpreter = sys.executable if parsed_args['--interpreter']: interpreter = parsed_args['--interpreter'] gate = build_ftl_gate(modules, module_dirs, dependencies, interpreter) print(gate) return 0
async def test_build_ftl_gate(): os.chdir(HERE) ftl_gate = build_ftl_gate() proc = await asyncio.create_subprocess_shell( ftl_gate, stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE) try: send_message(proc.stdin, 'Hello', {}) message = await read_message(proc.stdout) assert message[0] == "Hello" assert message[1] == {} finally: send_message(proc.stdin, 'Shutdown', {}) await proc.wait() os.unlink(ftl_gate) clean_up_ftl_cache() clean_up_tmp()
async def test_read_message(): os.chdir(HERE) ftl_gate = build_ftl_gate() proc = await asyncio.create_subprocess_shell( ftl_gate, stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE) try: proc.stdin.write(b'0000000d["Hello", {}]') message = await read_message(proc.stdout) assert message[0] == "Hello" assert message[1] == {} except Exception: print((await proc.stderr.read()).decode()) raise finally: send_message(proc.stdin, 'Shutdown', {}) await proc.wait() os.unlink(ftl_gate) clean_up_ftl_cache() clean_up_tmp()