chore: import upstream snapshot with attribution
docs / deploy (push) Has been cancelled
docs / changes (push) Has been cancelled
docs / check-and-build (push) Has been cancelled
build container image / cpu (push) Has been cancelled
build container image / cuda (push) Has been cancelled
build container image / rocm (push) Has been cancelled
frontend checks / frontend-checks (push) Has been cancelled
frontend tests / frontend-tests (push) Has been cancelled
lfs checks / lfs-check (push) Has been cancelled
python checks / python-checks (push) Has been cancelled
python tests / py3.12: macos-default (push) Has been cancelled
python tests / py3.11: windows-cpu (push) Has been cancelled
python tests / py3.12: windows-cpu (push) Has been cancelled
python tests / py3.11: linux-cpu (push) Has been cancelled
typegen checks / typegen-checks (push) Has been cancelled
uv lock checks / uv-lock-checks (push) Has been cancelled
openapi checks / openapi-checks (push) Has been cancelled
python tests / py3.11: macos-default (push) Has been cancelled
python tests / py3.12: linux-cpu (push) Has been cancelled
docs / deploy (push) Has been cancelled
docs / changes (push) Has been cancelled
docs / check-and-build (push) Has been cancelled
build container image / cpu (push) Has been cancelled
build container image / cuda (push) Has been cancelled
build container image / rocm (push) Has been cancelled
frontend checks / frontend-checks (push) Has been cancelled
frontend tests / frontend-tests (push) Has been cancelled
lfs checks / lfs-check (push) Has been cancelled
python checks / python-checks (push) Has been cancelled
python tests / py3.12: macos-default (push) Has been cancelled
python tests / py3.11: windows-cpu (push) Has been cancelled
python tests / py3.12: windows-cpu (push) Has been cancelled
python tests / py3.11: linux-cpu (push) Has been cancelled
typegen checks / typegen-checks (push) Has been cancelled
uv lock checks / uv-lock-checks (push) Has been cancelled
openapi checks / openapi-checks (push) Has been cancelled
python tests / py3.11: macos-default (push) Has been cancelled
python tests / py3.12: linux-cpu (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
from tests.dangerously_run_function_in_subprocess import dangerously_run_function_in_subprocess
|
||||
|
||||
|
||||
def test_simple_function():
|
||||
def test_func():
|
||||
print("Hello, Test!")
|
||||
|
||||
stdout, stderr, returncode = dangerously_run_function_in_subprocess(test_func)
|
||||
|
||||
assert returncode == 0
|
||||
assert stdout.strip() == "Hello, Test!"
|
||||
assert stderr == ""
|
||||
|
||||
|
||||
def test_function_with_error():
|
||||
def test_func():
|
||||
raise ValueError("This is an error")
|
||||
|
||||
_stdout, stderr, returncode = dangerously_run_function_in_subprocess(test_func)
|
||||
|
||||
assert returncode != 0 # Should fail
|
||||
assert "ValueError: This is an error" in stderr
|
||||
|
||||
|
||||
def test_function_with_imports():
|
||||
def test_func():
|
||||
import math
|
||||
|
||||
print(math.sqrt(4))
|
||||
|
||||
stdout, stderr, returncode = dangerously_run_function_in_subprocess(test_func)
|
||||
|
||||
assert returncode == 0
|
||||
assert stdout.strip() == "2.0"
|
||||
assert stderr == ""
|
||||
|
||||
|
||||
def test_function_with_sys_exit():
|
||||
def test_func():
|
||||
import sys
|
||||
|
||||
sys.exit(42)
|
||||
|
||||
_stdout, _stderr, returncode = dangerously_run_function_in_subprocess(test_func)
|
||||
|
||||
assert returncode == 42 # Should return the custom exit code
|
||||
|
||||
|
||||
def test_function_with_closure():
|
||||
foo = "bar"
|
||||
|
||||
def test_func():
|
||||
print(foo)
|
||||
|
||||
_stdout, _stderr, returncode = dangerously_run_function_in_subprocess(test_func)
|
||||
|
||||
assert returncode == 1 # Should fail because of closure
|
||||
Reference in New Issue
Block a user