示例#1
0
def test_forbidden_sandbox_run():
    try:
        write_to_file('trash.dat', 'foo')
        with pytest.raises(PermissionError):
            run(os.unlink, args=('trash.dat',))
    finally:
        os.unlink('trash.dat')
示例#2
0
def test_forbidden_sandbox_run():
    try:
        write_to_file('trash.dat', 'foo')
        with pytest.raises(PermissionError):
            run(os.unlink, args=('trash.dat', ))
    finally:
        os.unlink('trash.dat')
示例#3
0
def test_output_pass_through_sandbox():
    out = io.StringIO()
    stdout, sys.stdout = sys.stdout, out
    try:
        result = run(print, args=('hello world',), print_messages=False)
    finally:
        sys.stdout = stdout

    assert result is None
    assert out.getvalue() == 'hello world\n'
示例#4
0
def test_output_pass_through_sandbox():
    out = io.StringIO()
    stdout, sys.stdout = sys.stdout, out
    try:
        result = run(print, args=('hello world', ), print_messages=False)
    finally:
        sys.stdout = stdout

    assert result is None
    assert out.getvalue() == 'hello world\n'
示例#5
0
def test_json_serializer():
    assert run(math.sqrt, (4,), serializer='json') == 2
示例#6
0
def test_serialization_error():
    with pytest.raises(SerializationError):
        run(return_non_picklable_object)
示例#7
0
def test_cannot_run_as_invalid_user():
    with pytest.raises(PermissionError):
        run(math.sqrt, (2,), user='******')
示例#8
0
def test_cannot_run_as_root():
    with pytest.raises(PermissionError):
        run(math.sqrt, (2,), user='******')
示例#9
0
def test_error_propagates_from_sandbox():
    with pytest.raises(ValueError):
        run(math.sqrt, args=(-1,))
示例#10
0
def test_basic_sandbox_run():
    assert run(math.sqrt, args=(4.0,)) == 2.0
示例#11
0
def test_json_serializer():
    assert run(math.sqrt, (4, ), serializer='json') == 2
示例#12
0
def test_serialization_error():
    with pytest.raises(SerializationError):
        run(return_non_picklable_object)
示例#13
0
def test_cannot_run_as_invalid_user():
    with pytest.raises(PermissionError):
        run(math.sqrt, (2, ), user='******')
示例#14
0
def test_cannot_run_as_root():
    with pytest.raises(PermissionError):
        run(math.sqrt, (2, ), user='******')
示例#15
0
def test_error_propagates_from_sandbox():
    with pytest.raises(ValueError):
        run(math.sqrt, args=(-1, ))
示例#16
0
def test_basic_sandbox_run():
    assert run(math.sqrt, args=(4.0, )) == 2.0