Skip to content

channel_mock

Channel mock for simulating paramiko channel behavior with exit status support.

ChannelMock

Mock class that simulates paramiko channel behavior. This provides the recv_exit_status() method that real paramiko channels have.

Source code in src/paramiko_mock/channel_mock.py
 6
 7
 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
43
44
45
46
47
class ChannelMock:
    """
    Mock class that simulates paramiko channel behavior.
    This provides the recv_exit_status() method that real paramiko channels have.
    """

    def __init__(self, exit_status: int = 0):
        """
        Initialize the channel mock with an exit status.

        Args:
            exit_status: The exit status code to return (default: 0)
        """
        self._exit_status = exit_status
        self._closed = False

    def recv_exit_status(self) -> int:
        """
        Simulate the recv_exit_status method of paramiko channels.

        Returns:
            The exit status code
        """
        return self._exit_status

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

        Args:
            exit_status: The exit status code to set
        """
        self._exit_status = exit_status

    def close(self) -> None:
        """Close the channel."""
        self._closed = True

    @property
    def closed(self) -> bool:
        """Check if the channel is closed."""
        return self._closed

closed property

Check if the channel is closed.

__init__(exit_status=0)

Initialize the channel mock with an exit status.

Parameters:

Name Type Description Default
exit_status int

The exit status code to return (default: 0)

0
Source code in src/paramiko_mock/channel_mock.py
12
13
14
15
16
17
18
19
20
def __init__(self, exit_status: int = 0):
    """
    Initialize the channel mock with an exit status.

    Args:
        exit_status: The exit status code to return (default: 0)
    """
    self._exit_status = exit_status
    self._closed = False

close()

Close the channel.

Source code in src/paramiko_mock/channel_mock.py
40
41
42
def close(self) -> None:
    """Close the channel."""
    self._closed = True

recv_exit_status()

Simulate the recv_exit_status method of paramiko channels.

Returns:

Type Description
int

The exit status code

Source code in src/paramiko_mock/channel_mock.py
22
23
24
25
26
27
28
29
def recv_exit_status(self) -> int:
    """
    Simulate the recv_exit_status method of paramiko channels.

    Returns:
        The exit status code
    """
    return self._exit_status

set_exit_status(exit_status)

Set the exit status for this channel.

Parameters:

Name Type Description Default
exit_status int

The exit status code to set

required
Source code in src/paramiko_mock/channel_mock.py
31
32
33
34
35
36
37
38
def set_exit_status(self, exit_status: int) -> None:
    """
    Set the exit status for this channel.

    Args:
        exit_status: The exit status code to set
    """
    self._exit_status = exit_status