Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Add tests for infra

Jakub Novak7a1830ebc385
diff --git a/packages/python-sdk/example.py b/packages/python-sdk/example.py
index 0e7a1a2ab..c1178fa47 100644
--- a/packages/python-sdk/example.py
+++ b/packages/python-sdk/example.py
@@ -2,23 +2,22 @@ import asyncio
import logging
from os import getenv
-from e2b import Session, run_code
+from e2b import Session
id = "Python3"
E2B_API_KEY = getenv("E2B_API_KEY")
-
logging.basicConfig(level=logging.ERROR)
async def main():
- # s = Session("Nodejs", api_key=E2B_API_KEY)
- # await s.open()
- # await s.close()
+ s = Session("Nodejs", api_key=E2B_API_KEY)
+ await s.open()
- stdout, stderr = await run_code("Node16", "console.log('hello world'); throw new Error('error')")
- print(stdout)
- print(stderr)
+ a = await s.process.start("ls -la /var ")
+ await a
+ print(a.stdout)
+ print(a.stderr)
return
session = await Session.create(id)
diff --git a/packages/python-sdk/tests/infra/test_install_package.py b/packages/python-sdk/tests/infra/test_install_package.py
new file mode 100644
index 000000000..ad4a0cbb1
--- /dev/null
+++ b/packages/python-sdk/tests/infra/test_install_package.py
@@ -0,0 +1,14 @@
+from e2b import Session
+
+
+async def test_python_package():
+ session = await Session.create("Python3")
+
+ process = await session.process.start("pip install pip-install-test")
+ await process
+
+ process = await session.process.start('python -c "import pip_install_test"')
+ await process
+ output = process.stdout
+ assert "Good job!" in output
+ await session.close()
diff --git a/packages/python-sdk/tests/infra/test_sudo.py b/packages/python-sdk/tests/infra/test_sudo.py
index 0c2b39448..53e905503 100644
--- a/packages/python-sdk/tests/infra/test_sudo.py
+++ b/packages/python-sdk/tests/infra/test_sudo.py
@@ -7,5 +7,5 @@ async def test_sudo():
process = await session.process.start("sudo echo test")
await process
output = process.stdout
- assert output == "/home/user"
+ assert output == "test"
await session.close()