-
Notifications
You must be signed in to change notification settings - Fork 205
Expand file tree
/
Copy pathpython.test.ts
More file actions
69 lines (58 loc) · 1.71 KB
/
python.test.ts
File metadata and controls
69 lines (58 loc) · 1.71 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
import { expect } from 'vitest'
import { isDebug, sandboxTest } from '../setup'
import { Sandbox } from '../../src'
// Python Env Vars
sandboxTest.skipIf(isDebug)('env vars on sandbox (python)', async ({ template }) => {
const sandbox = await Sandbox.create(template, {
envs: { TEST_ENV_VAR: 'supertest' },
})
try {
const result = await sandbox.runCode(
`import os; os.getenv('TEST_ENV_VAR')`,
{
language: 'python',
}
)
expect(result.results[0]?.text.trim()).toEqual('supertest')
} finally {
await sandbox.kill()
}
})
sandboxTest('env vars per execution (python)', async ({ sandbox }) => {
const result = await sandbox.runCode("import os; os.getenv('FOO')", {
envs: { FOO: 'bar' },
language: 'python',
})
const result_empty = await sandbox.runCode(
"import os; os.getenv('FOO', 'default')",
{
language: 'python',
}
)
expect(result.results[0]?.text.trim()).toEqual('bar')
expect(result_empty.results[0]?.text.trim()).toEqual('default')
})
sandboxTest.skipIf(isDebug)('env vars overwrite', async ({ template }) => {
const sandbox = await Sandbox.create(template, {
envs: { TEST_ENV_VAR: 'supertest' },
})
try {
const result = await sandbox.runCode(
`import os; os.getenv('TEST_ENV_VAR')`,
{
language: 'python',
envs: { TEST_ENV_VAR: 'overwrite' },
}
)
const result_global_default = await sandbox.runCode(
`import os; os.getenv('TEST_ENV_VAR')`,
{
language: 'python',
}
)
expect(result.results[0]?.text.trim()).toEqual('overwrite')
expect(result_global_default.results[0]?.text.trim()).toEqual('supertest')
} finally {
await sandbox.kill()
}
})