Esempio n. 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')
Esempio n. 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')
Esempio n. 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'
Esempio 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'
Esempio n. 5
0
def test_json_serializer():
    assert run(math.sqrt, (4,), serializer='json') == 2
Esempio n. 6
0
def test_serialization_error():
    with pytest.raises(SerializationError):
        run(return_non_picklable_object)
Esempio n. 7
0
def test_cannot_run_as_invalid_user():
    with pytest.raises(PermissionError):
        run(math.sqrt, (2,), user='******')
Esempio n. 8
0
def test_cannot_run_as_root():
    with pytest.raises(PermissionError):
        run(math.sqrt, (2,), user='******')
Esempio n. 9
0
def test_error_propagates_from_sandbox():
    with pytest.raises(ValueError):
        run(math.sqrt, args=(-1,))
Esempio n. 10
0
def test_basic_sandbox_run():
    assert run(math.sqrt, args=(4.0,)) == 2.0
Esempio n. 11
0
def test_json_serializer():
    assert run(math.sqrt, (4, ), serializer='json') == 2
Esempio n. 12
0
def test_serialization_error():
    with pytest.raises(SerializationError):
        run(return_non_picklable_object)
Esempio n. 13
0
def test_cannot_run_as_invalid_user():
    with pytest.raises(PermissionError):
        run(math.sqrt, (2, ), user='******')
Esempio n. 14
0
def test_cannot_run_as_root():
    with pytest.raises(PermissionError):
        run(math.sqrt, (2, ), user='******')
Esempio n. 15
0
def test_error_propagates_from_sandbox():
    with pytest.raises(ValueError):
        run(math.sqrt, args=(-1, ))
Esempio n. 16
0
def test_basic_sandbox_run():
    assert run(math.sqrt, args=(4.0, )) == 2.0