Skip to content

stderr_mock

Enhanced stderr mock that combines BytesIO functionality with channel support.

StderrMock

Bases: BytesIO

Enhanced stderr mock that extends BytesIO and adds channel functionality. This simulates the behavior of paramiko's stderr which has both read() capabilities and a channel with recv_exit_status() method.

Source code in src/paramiko_mock/stderr_mock.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class StderrMock(BytesIO):
    """
    Enhanced stderr mock that extends BytesIO and adds channel functionality.
    This simulates the behavior of paramiko's stderr which has both read() capabilities
    and a channel with recv_exit_status() method.
    """

    def __init__(self, initial_bytes: bytes = b'', exit_status: int = 0):
        """
        Initialize the stderr mock with initial data and exit status.

        Args:
            initial_bytes: Initial bytes for the stderr content
            exit_status: The exit status code for the channel
        """
        super().__init__(initial_bytes)
        self.channel = ChannelMock(exit_status)

    def set_exit_status(self, exit_status: int) -> None:
        """
        Set the exit status for the channel.

        Args:
            exit_status: The exit status code to set
        """
        self.channel.set_exit_status(exit_status)

    def get_exit_status(self) -> int:
        """
        Get the current exit status.

        Returns:
            The current exit status code
        """
        return self.channel.recv_exit_status()

__init__(initial_bytes=b'', exit_status=0)

Initialize the stderr mock with initial data and exit status.

Parameters:

Name Type Description Default
initial_bytes bytes

Initial bytes for the stderr content

b''
exit_status int

The exit status code for the channel

0
Source code in src/paramiko_mock/stderr_mock.py
15
16
17
18
19
20
21
22
23
24
def __init__(self, initial_bytes: bytes = b'', exit_status: int = 0):
    """
    Initialize the stderr mock with initial data and exit status.

    Args:
        initial_bytes: Initial bytes for the stderr content
        exit_status: The exit status code for the channel
    """
    super().__init__(initial_bytes)
    self.channel = ChannelMock(exit_status)

get_exit_status()

Get the current exit status.

Returns:

Type Description
int

The current exit status code

Source code in src/paramiko_mock/stderr_mock.py
35
36
37
38
39
40
41
42
def get_exit_status(self) -> int:
    """
    Get the current exit status.

    Returns:
        The current exit status code
    """
    return self.channel.recv_exit_status()

set_exit_status(exit_status)

Set the exit status for the channel.

Parameters:

Name Type Description Default
exit_status int

The exit status code to set

required
Source code in src/paramiko_mock/stderr_mock.py
26
27
28
29
30
31
32
33
def set_exit_status(self, exit_status: int) -> None:
    """
    Set the exit status for the channel.

    Args:
        exit_status: The exit status code to set
    """
    self.channel.set_exit_status(exit_status)