def run(self, entry_point, args, expected): exe = compile(entry_point) from pypy.translator.sandbox.sandlib import SimpleIOSandboxedProc proc = SimpleIOSandboxedProc([exe] + args) output, error = proc.communicate() assert error == '' assert output == expected
def run(self, entry_point, args, expected): t = Translation(entry_point, backend='c', standalone=True, sandbox=True) exe = t.compile() from pypy.translator.sandbox.sandlib import SimpleIOSandboxedProc proc = SimpleIOSandboxedProc([exe] + args) output, error = proc.communicate() assert error == '' assert output == expected
def test_simpleio(): def entry_point(argv): print "Please enter a number:" buf = "" while True: t = os.read(0, 1) # 1 character from stdin if not t: raise EOFError if t == '\n': break buf += t num = int(buf) print "The double is:", num * 2 return 0 exe = compile(entry_point) proc = SimpleIOSandboxedProc([exe, 'x1', 'y2']) output, error = proc.communicate("21\n") assert output == "Please enter a number:\nThe double is: 42\n" assert error == ""