diff --git a/js/tests/cwd.test.ts b/js/tests/cwd.test.ts new file mode 100644 index 00000000..b9a35ca3 --- /dev/null +++ b/js/tests/cwd.test.ts @@ -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') +}) diff --git a/python/tests/async/test_async_cwd.py b/python/tests/async/test_async_cwd.py new file mode 100644 index 00000000..e03b3e68 --- /dev/null +++ b/python/tests/async/test_async_cwd.py @@ -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" diff --git a/python/tests/sync/test_cwd.py b/python/tests/sync/test_cwd.py new file mode 100644 index 00000000..35f91a2b --- /dev/null +++ b/python/tests/sync/test_cwd.py @@ -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"