def test_stdout(): with capture_stdout() as stdout: config = SandboxConfig() def print_denied(): print "Hello Sandbox 1" try: Sandbox(config).call(print_denied) except SandboxError: pass else: assert False def print_allowed(): print "Hello Sandbox 2" Sandbox(createSandboxConfig("stdout")).call(print_allowed) print "Hello Sandbox 3" stdout.seek(0) output = stdout.read() assert output == "Hello Sandbox 2\nHello Sandbox 3\n"
def test_stdout(): import sys config = createSandboxConfig(disable_debug=True) with capture_stdout() as stdout: def print_denied(): print "Hello Sandbox 1" try: Sandbox(config).call(print_denied) except SandboxError: pass else: assert False def print_allowed(): print "Hello Sandbox 2" config2 = createSandboxConfig('stdout') Sandbox(config2).call(print_allowed) print "Hello Sandbox 3" sys.stdout.flush() stdout.seek(0) output = stdout.read() assert output == "Hello Sandbox 2\nHello Sandbox 3\n"
def test_stdout(): with capture_stdout() as stdout: config = SandboxConfig() def print_denied(): try: print "Hello Sandbox 1" except SandboxError: pass else: assert False Sandbox(config).call(print_denied) def print_allowed(): print "Hello Sandbox 2" Sandbox(createSandboxConfig('stdout')).call(print_allowed) print "Hello Sandbox 3" output = stdout.getvalue() assert output == "Hello Sandbox 2\nHello Sandbox 3\n"
def test_stdout(): with capture_stdout() as stdout: config = SandboxConfig() def print_denied(): print "Hello Sandbox 1" try: Sandbox(config).call(print_denied) except SandboxError: pass else: assert False def print_allowed(): print "Hello Sandbox 2" Sandbox(createSandboxConfig('stdout')).call(print_allowed) print "Hello Sandbox 3" stdout.seek(0) output = stdout.read() assert output == "Hello Sandbox 2\nHello Sandbox 3\n"
with NamedTemporaryFile() as script: print >>script, "print('Hello World!')" script.flush() filename = script.name config = createSandboxConfig('stdout') try: Sandbox(config).call(execfile_test, filename) except NameError, err: assert str(err) == "global name 'execfile' is not defined" else: assert False with capture_stdout() as stdout: execfile_test(filename) stdout.seek(0) output = stdout.read() print(repr(output)) assert output.startswith('Hello World') def test_compile(): import sys orig_displayhook = sys.displayhook try: results = [] def displayhook(value): results.append(value)
with NamedTemporaryFile() as script: print >> script, "print('Hello World!')" script.flush() filename = script.name config = createSandboxConfig('stdout') try: Sandbox(config).call(execfile_test, filename) except NameError, err: assert str(err) == "global name 'execfile' is not defined" else: assert False with capture_stdout() as stdout: execfile_test(filename) stdout.seek(0) output = stdout.read() print(repr(output)) assert output.startswith('Hello World') def test_compile(): import sys orig_displayhook = sys.displayhook try: results = [] def displayhook(value):