-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathtest_async_env_vars.py
More file actions
102 lines (81 loc) · 2.96 KB
/
test_async_env_vars.py
File metadata and controls
102 lines (81 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import pytest
from e2b_code_interpreter.code_interpreter_async import AsyncSandbox
@pytest.mark.skip_debug()
async def test_env_vars_sandbox():
sbx = await AsyncSandbox.create(envs={"TEST_ENV_VAR": "supertest"})
try:
result = await sbx.run_code("import os; os.getenv('TEST_ENV_VAR')")
assert result.text is not None
assert result.text.strip() == "supertest"
finally:
await sbx.kill()
async def test_env_vars_in_run_code(async_sandbox: AsyncSandbox):
result = await async_sandbox.run_code(
"import os; os.getenv('FOO')", envs={"FOO": "bar"}
)
assert result.text is not None
assert result.text.strip() == "bar"
# JavaScript tests
@pytest.mark.skip_debug()
async def test_env_vars_javascript_sandbox():
sbx = await AsyncSandbox.create(envs={"TEST_ENV_VAR": "supertest"})
try:
result = await sbx.run_code("process.env.TEST_ENV_VAR")
assert result.text is not None
assert result.text.strip() == "supertest"
finally:
await sbx.kill()
async def test_env_vars_javascript(async_sandbox: AsyncSandbox):
result = await async_sandbox.run_code(
"process.env.FOO", envs={"FOO": "bar"}
)
assert result.text is not None
assert result.text.strip() == "bar"
# R tests
@pytest.mark.skip_debug()
async def test_env_vars_r_sandbox():
sbx = await AsyncSandbox.create(envs={"TEST_ENV_VAR": "supertest"})
try:
result = await sbx.run_code('Sys.getenv("TEST_ENV_VAR")')
assert result.text is not None
assert result.text.strip() == "supertest"
finally:
await sbx.kill()
async def test_env_vars_r(async_sandbox: AsyncSandbox):
result = await async_sandbox.run_code(
'Sys.getenv("FOO")', envs={"FOO": "bar"}
)
assert result.text is not None
assert result.text.strip() == "bar"
# Java tests
@pytest.mark.skip_debug()
async def test_env_vars_java_sandbox():
sbx = await AsyncSandbox.create(envs={"TEST_ENV_VAR": "supertest"})
try:
result = await sbx.run_code('System.getenv("TEST_ENV_VAR")')
assert result.text is not None
assert result.text.strip() == "supertest"
finally:
await sbx.kill()
async def test_env_vars_java(async_sandbox: AsyncSandbox):
result = await async_sandbox.run_code(
'System.getenv("FOO")', envs={"FOO": "bar"}
)
assert result.text is not None
assert result.text.strip() == "bar"
# Bash tests
@pytest.mark.skip_debug()
async def test_env_vars_bash_sandbox():
sbx = await AsyncSandbox.create(envs={"TEST_ENV_VAR": "supertest"})
try:
result = await sbx.run_code("echo $TEST_ENV_VAR")
assert result.text is not None
assert result.text.strip() == "supertest"
finally:
await sbx.kill()
async def test_env_vars_bash(async_sandbox: AsyncSandbox):
result = await async_sandbox.run_code(
"echo $FOO", envs={"FOO": "bar"}
)
assert result.text is not None
assert result.text.strip() == "bar"