Skip to content

Dummy

swerex.runtime.dummy.DummyRuntime

DummyRuntime(*, logger: Logger | None = None, **kwargs: Any)

Bases: AbstractRuntime

This runtime returns blank or predefined outputs. Useful for testing.

Parameters:

Name Type Description Default
**kwargs Any

Keyword arguments (see DummyRuntimeConfig for details).

{}
Source code in swerex/runtime/dummy.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def __init__(
    self,
    *,
    logger: logging.Logger | None = None,
    **kwargs: Any,
):
    """This runtime returns blank or predefined outputs.
    Useful for testing.

    Args:
        **kwargs: Keyword arguments (see `DummyRuntimeConfig` for details).
    """
    self.run_in_session_outputs: list[BashObservation] | BashObservation = BashObservation(exit_code=0)
    """Predefine returns of run_in_session. If set to list, will pop from list, else will 
    return the same value.
    """
    self._config = DummyRuntimeConfig(**kwargs)
    self.logger = logger or get_logger("rex-runtime")

logger instance-attribute

logger = logger or get_logger('rex-runtime')

run_in_session_outputs instance-attribute

run_in_session_outputs: list[BashObservation] | BashObservation = BashObservation(exit_code=0)

Predefine returns of run_in_session. If set to list, will pop from list, else will return the same value.

close async

close() -> CloseResponse
Source code in swerex/runtime/dummy.py
93
94
async def close(self) -> CloseResponse:
    return CloseResponse()

close_session async

close_session(request: CloseSessionRequest) -> CloseSessionResponse
Source code in swerex/runtime/dummy.py
75
76
77
78
79
async def close_session(self, request: CloseSessionRequest) -> CloseSessionResponse:
    if request.session_type == "bash":
        return CloseBashSessionResponse()
    msg = f"Unknown session type: {request.session_type}"
    raise ValueError(msg)

create_session async

create_session(request: CreateSessionRequest) -> CreateSessionResponse
Source code in swerex/runtime/dummy.py
60
61
62
63
64
async def create_session(self, request: CreateSessionRequest) -> CreateSessionResponse:
    if request.session_type == "bash":
        return CreateBashSessionResponse()
    msg = f"Unknown session type: {request.session_type}"
    raise ValueError(msg)

execute async

execute(command: Command) -> CommandResponse
Source code in swerex/runtime/dummy.py
81
82
async def execute(self, command: Command) -> CommandResponse:
    return CommandResponse(exit_code=0)

from_config classmethod

from_config(config: DummyRuntimeConfig) -> Self
Source code in swerex/runtime/dummy.py
53
54
55
@classmethod
def from_config(cls, config: DummyRuntimeConfig) -> Self:
    return cls(**config.model_dump())

is_alive async

is_alive(*, timeout: float | None = None) -> IsAliveResponse
Source code in swerex/runtime/dummy.py
57
58
async def is_alive(self, *, timeout: float | None = None) -> IsAliveResponse:
    return IsAliveResponse(is_alive=True)

read_file async

read_file(request: ReadFileRequest) -> ReadFileResponse
Source code in swerex/runtime/dummy.py
84
85
async def read_file(self, request: ReadFileRequest) -> ReadFileResponse:
    return ReadFileResponse()

run_in_session async

run_in_session(action: Action) -> Observation
Source code in swerex/runtime/dummy.py
66
67
68
69
70
71
72
73
async def run_in_session(self, action: Action) -> Observation:
    if isinstance(self.run_in_session_outputs, list):
        try:
            return self.run_in_session_outputs.pop(0)
        except IndexError:
            msg = f"Dummy runtime's run_in_session_outputs list is empty: No output for {action.command!r}"
            raise DummyOutputsExhaustedError(msg) from None
    return self.run_in_session_outputs

upload async

upload(request: UploadRequest) -> UploadResponse
Source code in swerex/runtime/dummy.py
90
91
async def upload(self, request: UploadRequest) -> UploadResponse:
    return UploadResponse()

write_file async

write_file(request: WriteFileRequest) -> WriteFileResponse
Source code in swerex/runtime/dummy.py
87
88
async def write_file(self, request: WriteFileRequest) -> WriteFileResponse:
    return WriteFileResponse()