Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions js/tests/cwd.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { expect } from 'vitest'

import { isDebug, sandboxTest } from './setup'

// Skip these tests in debug mode — the pwd and user in the testing docker container
// are not the same as in the actual sandbox.

sandboxTest.skipIf(isDebug)('cwd python', async ({ sandbox }) => {
const result = await sandbox.runCode(
'from pathlib import Path; print(Path.cwd())',
{ language: 'python' }
)
expect(result.logs.stdout.join().trim()).toEqual('/home/user')
})

sandboxTest.skipIf(isDebug)('cwd javascript', async ({ sandbox }) => {
const result = await sandbox.runCode('process.cwd()', {
language: 'js',
})
expect(result.text).toEqual('/home/user')
})

sandboxTest.skipIf(isDebug)('cwd typescript', async ({ sandbox }) => {
const result = await sandbox.runCode('process.cwd()', {
language: 'ts',
})
expect(result.text).toEqual('/home/user')
})

sandboxTest.skipIf(isDebug)('cwd r', async ({ sandbox }) => {
const result = await sandbox.runCode('getwd()', {
language: 'r',
})
expect(result.results[0]?.text.trim()).toEqual('[1] "/home/user"')
})

sandboxTest.skipIf(isDebug)('cwd java', async ({ sandbox }) => {
const result = await sandbox.runCode('System.getProperty("user.dir")', {
language: 'java',
})
expect(result.results[0]?.text.trim()).toEqual('/home/user')
})
35 changes: 35 additions & 0 deletions python/tests/async/test_async_cwd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pytest

from e2b_code_interpreter.code_interpreter_async import AsyncSandbox


@pytest.mark.skip_debug()
async def test_cwd_python(async_sandbox: AsyncSandbox):
result = await async_sandbox.run_code("from pathlib import Path; print(Path.cwd())")
assert "".join(result.logs.stdout).strip() == "/home/user"


@pytest.mark.skip_debug()
async def test_cwd_javascript(async_sandbox: AsyncSandbox):
result = await async_sandbox.run_code("process.cwd()", language="js")
assert result.text == "/home/user"


@pytest.mark.skip_debug()
async def test_cwd_typescript(async_sandbox: AsyncSandbox):
result = await async_sandbox.run_code("process.cwd()", language="ts")
assert result.text == "/home/user"


@pytest.mark.skip_debug()
async def test_cwd_r(async_sandbox: AsyncSandbox):
result = await async_sandbox.run_code("getwd()", language="r")
assert result.results[0].text.strip() == '[1] "/home/user"'


@pytest.mark.skip_debug()
async def test_cwd_java(async_sandbox: AsyncSandbox):
result = await async_sandbox.run_code(
'System.getProperty("user.dir")', language="java"
)
assert result.results[0].text.strip() == "/home/user"
33 changes: 33 additions & 0 deletions python/tests/sync/test_cwd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pytest

from e2b_code_interpreter.code_interpreter_sync import Sandbox


@pytest.mark.skip_debug()
def test_cwd_python(sandbox: Sandbox):
result = sandbox.run_code("from pathlib import Path; print(Path.cwd())")
assert "".join(result.logs.stdout).strip() == "/home/user"


@pytest.mark.skip_debug()
def test_cwd_javascript(sandbox: Sandbox):
result = sandbox.run_code("process.cwd()", language="js")
assert result.text == "/home/user"


@pytest.mark.skip_debug()
def test_cwd_typescript(sandbox: Sandbox):
result = sandbox.run_code("process.cwd()", language="ts")
assert result.text == "/home/user"


@pytest.mark.skip_debug()
def test_cwd_r(sandbox: Sandbox):
result = sandbox.run_code("getwd()", language="r")
assert result.results[0].text.strip() == '[1] "/home/user"'


@pytest.mark.skip_debug()
def test_cwd_java(sandbox: Sandbox):
result = sandbox.run_code('System.getProperty("user.dir")', language="java")
assert result.results[0].text.strip() == "/home/user"
Loading