Skip to content

MockExecutionEnvironmentConfig

Base classes

Name Children Inherits
BaseExecutionEnvironmentConfig
exxec_config.configs
Base execution environment configuration.

â‹” Inheritance diagram

graph TD
  2128889722["configs.MockExecutionEnvironmentConfig"]
  2844377061["configs.BaseExecutionEnvironmentConfig"]
  330168112["schema.Schema"]
  3879467795["main.BaseModel"]
  2751680898["builtins.object"]
  2844377061 --> 2128889722
  330168112 --> 2844377061
  3879467795 --> 330168112
  2751680898 --> 3879467795

🛈 DocStrings

Bases: BaseExecutionEnvironmentConfig

Mock execution environment configuration.

For testing purposes. Uses an in-memory filesystem and configurable results. Dicts are passed as **kwargs to ExecutionResult/ProcessOutput constructors.

Source code in src/exxec_config/configs.py
class MockExecutionEnvironmentConfig(BaseExecutionEnvironmentConfig):
    """Mock execution environment configuration.

    For testing purposes. Uses an in-memory filesystem and configurable results.
    Dicts are passed as **kwargs to ExecutionResult/ProcessOutput constructors.
    """

    model_config = ConfigDict(json_schema_extra={"x-doc-title": "Mock Execution Environment"})

    type: Literal["mock"] = Field("mock", init=False)

    code_results: dict[str, dict[str, Any]] | None = Field(
        default=None,
        title="Code Results",
        examples=[{"print('hello')": {"stdout": "hello", "success": True}}],
    )
    """Map of code string to ExecutionResult kwargs dict."""

    command_results: dict[str, dict[str, Any]] | None = Field(
        default=None,
        title="Command Results",
        examples=[{"ls": {"stdout": "file1.txt", "success": True}}],
    )
    """Map of command string to ExecutionResult kwargs dict."""

    default_result: dict[str, Any] | None = Field(
        default=None,
        title="Default Result",
        examples=[{"stdout": "", "success": True}],
    )
    """Default ExecutionResult kwargs when no specific match is found."""

    deterministic_ids: bool = Field(
        default=False,
        title="Deterministic IDs",
    )
    """Use sequential IDs instead of UUIDs for processes (useful for snapshot testing)."""

    files: dict[str, str] | None = Field(
        default=None,
        title="Files",
        examples=[{"/test/hello.txt": "Hello, World!", "/data/config.json": '{"key": "value"}'}],
    )
    """Map of file paths to contents to pre-populate in the in-memory filesystem."""

    def get_provider(
        self, lifespan_handler: AbstractAsyncContextManager[ServerInfo] | None = None
    ) -> MockExecutionEnvironment:
        """Create mock execution environment instance."""
        from exxec.mock_provider import MockExecutionEnvironment
        from exxec.models import ExecutionResult

        code_results = None
        if self.code_results:
            code_results = {k: ExecutionResult(**v) for k, v in self.code_results.items()}

        command_results = None
        if self.command_results:
            command_results = {k: ExecutionResult(**v) for k, v in self.command_results.items()}

        default_result = None
        if self.default_result:
            default_result = ExecutionResult(**self.default_result)

        env = MockExecutionEnvironment(
            code_results=code_results,
            command_results=command_results,
            default_result=default_result,
            deterministic_ids=self.deterministic_ids,
            cwd=self.cwd,
            env_vars=self.env_vars,
            inherit_env=self.inherit_env,
        )

        # Pre-populate files in the in-memory filesystem
        if self.files:
            for path, content in self.files.items():
                env._sync_fs.pipe_file(
                    path, content.encode() if isinstance(content, str) else content
                )

        return env

code_results class-attribute instance-attribute

code_results: dict[str, dict[str, Any]] | None = Field(
    default=None,
    title="Code Results",
    examples=[{"print('hello')": {"stdout": "hello", "success": True}}],
)

Map of code string to ExecutionResult kwargs dict.

command_results class-attribute instance-attribute

command_results: dict[str, dict[str, Any]] | None = Field(
    default=None,
    title="Command Results",
    examples=[{"ls": {"stdout": "file1.txt", "success": True}}],
)

Map of command string to ExecutionResult kwargs dict.

default_result class-attribute instance-attribute

default_result: dict[str, Any] | None = Field(
    default=None, title="Default Result", examples=[{"stdout": "", "success": True}]
)

Default ExecutionResult kwargs when no specific match is found.

deterministic_ids class-attribute instance-attribute

deterministic_ids: bool = Field(default=False, title='Deterministic IDs')

Use sequential IDs instead of UUIDs for processes (useful for snapshot testing).

files class-attribute instance-attribute

files: dict[str, str] | None = Field(
    default=None,
    title="Files",
    examples=[{"/test/hello.txt": "Hello, World!", "/data/config.json": '{"key": "value"}'}],
)

Map of file paths to contents to pre-populate in the in-memory filesystem.

get_provider

get_provider(
    lifespan_handler: AbstractAsyncContextManager[ServerInfo] | None = None,
) -> MockExecutionEnvironment

Create mock execution environment instance.

Source code in src/exxec_config/configs.py
def get_provider(
    self, lifespan_handler: AbstractAsyncContextManager[ServerInfo] | None = None
) -> MockExecutionEnvironment:
    """Create mock execution environment instance."""
    from exxec.mock_provider import MockExecutionEnvironment
    from exxec.models import ExecutionResult

    code_results = None
    if self.code_results:
        code_results = {k: ExecutionResult(**v) for k, v in self.code_results.items()}

    command_results = None
    if self.command_results:
        command_results = {k: ExecutionResult(**v) for k, v in self.command_results.items()}

    default_result = None
    if self.default_result:
        default_result = ExecutionResult(**self.default_result)

    env = MockExecutionEnvironment(
        code_results=code_results,
        command_results=command_results,
        default_result=default_result,
        deterministic_ids=self.deterministic_ids,
        cwd=self.cwd,
        env_vars=self.env_vars,
        inherit_env=self.inherit_env,
    )

    # Pre-populate files in the in-memory filesystem
    if self.files:
        for path, content in self.files.items():
            env._sync_fs.pipe_file(
                path, content.encode() if isinstance(content, str) else content
            )

    return env

:fa-brands-github: Show source on GitHub