Skip to content

Commit bd11a98

Browse files
committed
added tests for pwd
1 parent 6a3e536 commit bd11a98

File tree

3 files changed

+130
-0
lines changed

3 files changed

+130
-0
lines changed

js/tests/cwd.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { expect } from 'vitest'
2+
3+
import { isDebug, sandboxTest } from './setup'
4+
5+
// Skip these tests in debug mode — the pwd and user in the testing docker container
6+
// are not the same as in the actual sandbox.
7+
8+
sandboxTest.skipIf(isDebug)('cwd python', async ({ sandbox }) => {
9+
const result = await sandbox.runCode(
10+
'from pathlib import Path; print(Path.cwd())',
11+
{ language: 'python' }
12+
)
13+
expect(result.logs.stdout.join().trim()).toEqual('/home/user')
14+
})
15+
16+
sandboxTest.skipIf(isDebug)('cwd javascript', async ({ sandbox }) => {
17+
const result = await sandbox.runCode('process.cwd()', {
18+
language: 'js',
19+
})
20+
expect(result.text).toEqual('/home/user')
21+
})
22+
23+
sandboxTest.skipIf(isDebug)('cwd typescript', async ({ sandbox }) => {
24+
const result = await sandbox.runCode('process.cwd()', {
25+
language: 'ts',
26+
})
27+
expect(result.text).toEqual('/home/user')
28+
})
29+
30+
sandboxTest.skipIf(isDebug)('cwd deno', async ({ sandbox }) => {
31+
const result = await sandbox.runCode('Deno.cwd()', {
32+
language: 'deno',
33+
})
34+
expect(result.text).toEqual('/home/user')
35+
})
36+
37+
sandboxTest.skipIf(isDebug)('cwd r', async ({ sandbox }) => {
38+
const result = await sandbox.runCode('getwd()', {
39+
language: 'r',
40+
})
41+
expect(result.results[0]?.text.trim()).toEqual('[1] "/home/user"')
42+
})
43+
44+
sandboxTest.skipIf(isDebug)('cwd java', async ({ sandbox }) => {
45+
const result = await sandbox.runCode(
46+
'System.getProperty("user.dir")',
47+
{ language: 'java' }
48+
)
49+
expect(result.results[0]?.text.trim()).toEqual('/home/user')
50+
})
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import pytest
2+
3+
from e2b_code_interpreter.code_interpreter_async import AsyncSandbox
4+
5+
6+
@pytest.mark.skip_debug()
7+
async def test_cwd_python(async_sandbox: AsyncSandbox):
8+
result = await async_sandbox.run_code("from pathlib import Path; print(Path.cwd())")
9+
assert "".join(result.logs.stdout).strip() == "/home/user"
10+
11+
12+
@pytest.mark.skip_debug()
13+
async def test_cwd_javascript(async_sandbox: AsyncSandbox):
14+
result = await async_sandbox.run_code("process.cwd()", language="js")
15+
assert result.text == "/home/user"
16+
17+
18+
@pytest.mark.skip_debug()
19+
async def test_cwd_typescript(async_sandbox: AsyncSandbox):
20+
result = await async_sandbox.run_code("process.cwd()", language="ts")
21+
assert result.text == "/home/user"
22+
23+
24+
@pytest.mark.skip_debug()
25+
async def test_cwd_deno(async_sandbox: AsyncSandbox):
26+
result = await async_sandbox.run_code("Deno.cwd()", language="deno")
27+
assert result.text == "/home/user"
28+
29+
30+
@pytest.mark.skip_debug()
31+
async def test_cwd_r(async_sandbox: AsyncSandbox):
32+
result = await async_sandbox.run_code("getwd()", language="r")
33+
assert result.results[0].text.strip() == '[1] "/home/user"'
34+
35+
36+
@pytest.mark.skip_debug()
37+
async def test_cwd_java(async_sandbox: AsyncSandbox):
38+
result = await async_sandbox.run_code(
39+
'System.getProperty("user.dir")', language="java"
40+
)
41+
assert result.results[0].text.strip() == "/home/user"

python/tests/sync/test_cwd.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import pytest
2+
3+
from e2b_code_interpreter.code_interpreter_sync import Sandbox
4+
5+
6+
@pytest.mark.skip_debug()
7+
def test_cwd_python(sandbox: Sandbox):
8+
result = sandbox.run_code("from pathlib import Path; print(Path.cwd())")
9+
assert "".join(result.logs.stdout).strip() == "/home/user"
10+
11+
12+
@pytest.mark.skip_debug()
13+
def test_cwd_javascript(sandbox: Sandbox):
14+
result = sandbox.run_code("process.cwd()", language="js")
15+
assert result.text == "/home/user"
16+
17+
18+
@pytest.mark.skip_debug()
19+
def test_cwd_typescript(sandbox: Sandbox):
20+
result = sandbox.run_code("process.cwd()", language="ts")
21+
assert result.text == "/home/user"
22+
23+
24+
@pytest.mark.skip_debug()
25+
def test_cwd_deno(sandbox: Sandbox):
26+
result = sandbox.run_code("Deno.cwd()", language="deno")
27+
assert result.text == "/home/user"
28+
29+
30+
@pytest.mark.skip_debug()
31+
def test_cwd_r(sandbox: Sandbox):
32+
result = sandbox.run_code("getwd()", language="r")
33+
assert result.results[0].text.strip() == '[1] "/home/user"'
34+
35+
36+
@pytest.mark.skip_debug()
37+
def test_cwd_java(sandbox: Sandbox):
38+
result = sandbox.run_code('System.getProperty("user.dir")', language="java")
39+
assert result.results[0].text.strip() == "/home/user"

0 commit comments

Comments
 (0)