Skip to navigation

nemo_gym.sandbox.testing

View as MarkdownOpen in Claude

A fake sandbox provider for tests of code that owns or borrows sandboxes.

Tests drive a real AsyncSandbox over FakeSandboxProvider, so what the sandbox guarantees, such as a stop that survives cancellation and is bounded in time, holds in the test as it does in production. A test scripts the provider, not the sandbox: a slow, failing or hanging stop is a side effect on provider.on_close.

Module Contents

Classes

NameDescription
FakeSandboxProviderAn in-memory provider: sandboxes start at once, commands succeed with no output, and nothing leaves the process.

Functions

NameDescription
fake_sandboxA started sandbox on provider (a new FakeSandboxProvider by default), built without awaiting.

API

class nemo_gym.sandbox.testing.FakeSandboxProvider()

An in-memory provider: sandboxes start at once, commands succeed with no output, and nothing leaves the process.

_created
= 0
client_closed
= False

Whether the provider’s client was released (aclose).

closed
list[str] = []

The ids of the sandboxes whose close succeeded, in order.

name
= 'fake'
on_close
= AsyncMock()

Awaited, with no arguments, every time a sandbox is closed. Give it a side effect to make the provider’s close slow, fail or hang: an async function, or a plain one that raises or returns an awaitable, which the close awaits too.

nemo_gym.sandbox.testing.FakeSandboxProvider.aclose() -> None
async
nemo_gym.sandbox.testing.FakeSandboxProvider.close(
) -> None
async
nemo_gym.sandbox.testing.FakeSandboxProvider.connect(
descriptor: collections.abc.Mapping[str, typing.Any]
async
nemo_gym.sandbox.testing.FakeSandboxProvider.create(
async
nemo_gym.sandbox.testing.FakeSandboxProvider.download_file(
source_path: str,
target_path: pathlib.Path
) -> None
async
nemo_gym.sandbox.testing.FakeSandboxProvider.exec(
command: str,
kwargs: typing.Any = {}
async
nemo_gym.sandbox.testing.FakeSandboxProvider.serialize_handle(
scope: str | None = None
) -> dict[str, typing.Any]
async
nemo_gym.sandbox.testing.FakeSandboxProvider.status(
async
nemo_gym.sandbox.testing.FakeSandboxProvider.upload_file(
source_path: pathlib.Path,
target_path: str
) -> None
async
nemo_gym.sandbox.testing.fake_sandbox(
sandbox_id: str = 'fake-1',
owns_provider: bool = False

A started sandbox on provider (a new FakeSandboxProvider by default), built without awaiting.

It is what await AsyncSandbox(provider, spec).start() returns, for tests that need one in a synchronous fixture, and sandbox.provider is the provider to script. By default the sandbox does not own the provider, so stopping it leaves the provider’s client open; with owns_provider a successful stop closes it too.