From 0d0ccabb602df2d81afafefc196bf3cd0395fc85 Mon Sep 17 00:00:00 2001 From: 0div Date: Sat, 14 Dec 2024 11:31:17 -0800 Subject: [PATCH] add basic snapshot testing to python-sdk --- .../tests/async/sandbox_async/test_snapshot.py | 17 +++++++++++++++++ packages/python-sdk/tests/conftest.py | 13 ++++++++----- .../tests/sync/sandbox_sync/test_snapshot.py | 17 +++++++++++++++++ 3 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 packages/python-sdk/tests/async/sandbox_async/test_snapshot.py create mode 100644 packages/python-sdk/tests/sync/sandbox_sync/test_snapshot.py diff --git a/packages/python-sdk/tests/async/sandbox_async/test_snapshot.py b/packages/python-sdk/tests/async/sandbox_async/test_snapshot.py new file mode 100644 index 000000000..b5e2d3a2f --- /dev/null +++ b/packages/python-sdk/tests/async/sandbox_async/test_snapshot.py @@ -0,0 +1,17 @@ +import pytest +from e2b import AsyncSandbox + + +@pytest.mark.skip_debug() +async def test_snapshot(template): + sbx = await AsyncSandbox.create(template, timeout=5) + try: + assert await sbx.is_running() + + sandbox_id = await sbx.pause() + assert not await sbx.is_running() + + await sbx.resume(sandbox_id) + assert await sbx.is_running() + finally: + await sbx.kill() diff --git a/packages/python-sdk/tests/conftest.py b/packages/python-sdk/tests/conftest.py index 7de27aa39..2fa1d6a6a 100644 --- a/packages/python-sdk/tests/conftest.py +++ b/packages/python-sdk/tests/conftest.py @@ -1,15 +1,14 @@ -import pytest -import pytest_asyncio import os - from logging import warning -from e2b import Sandbox, AsyncSandbox +import pytest +import pytest_asyncio +from e2b import AsyncSandbox, Sandbox @pytest.fixture() def template(): - return "base" + return "base_01" @pytest.fixture() @@ -17,6 +16,8 @@ def sandbox(template, debug): sandbox = Sandbox(template) try: + sandbox_id = sandbox.pause() + sandbox.resume(sandbox_id) yield sandbox finally: try: @@ -33,6 +34,8 @@ async def async_sandbox(template, debug): sandbox = await AsyncSandbox.create(template) try: + sandbox_id = await sandbox.pause() + await sandbox.resume(sandbox_id) yield sandbox finally: try: diff --git a/packages/python-sdk/tests/sync/sandbox_sync/test_snapshot.py b/packages/python-sdk/tests/sync/sandbox_sync/test_snapshot.py new file mode 100644 index 000000000..a7fef2902 --- /dev/null +++ b/packages/python-sdk/tests/sync/sandbox_sync/test_snapshot.py @@ -0,0 +1,17 @@ +import pytest +from e2b import Sandbox + + +@pytest.mark.skip_debug() +def test_snapshot(template): + sbx = Sandbox(template, timeout=5) + try: + assert sbx.is_running() + + sandbox_id = sbx.pause() + assert not sbx.is_running() + + sbx.resume(sandbox_id) + assert sbx.is_running() + finally: + sbx.kill()