Пример #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