File: test_putty.py

package info (click to toggle)
python-plumbum 1.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,300 kB
  • sloc: python: 10,016; makefile: 130; sh: 8
file content (69 lines) | stat: -rw-r--r-- 1,974 bytes parent folder | download
1
2
3
4
5
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""Test that PuttyMachine initializes its SshMachine correctly"""

from __future__ import annotations

import pytest

from plumbum import PuttyMachine, SshMachine


@pytest.fixture(params=["default", "322"])
def ssh_port(request):
    return request.param


class TestPuttyMachine:
    def test_putty_command(self, mocker, ssh_port):
        local = mocker.patch("plumbum.machines.ssh_machine.local")
        init = mocker.spy(SshMachine, "__init__")
        mocker.patch("plumbum.machines.ssh_machine.BaseRemoteMachine")

        host = mocker.MagicMock()
        user = local.env.user
        port = keyfile = None
        ssh_command = local["plink"]
        scp_command = local["pscp"]
        ssh_opts = ["-ssh"]
        if ssh_port == "default":
            putty_port = None
            scp_opts = ()
        else:
            putty_port = int(ssh_port)
            ssh_opts.extend(["-P", ssh_port])
            scp_opts = ["-P", ssh_port]
        encoding = mocker.MagicMock()
        connect_timeout = 20
        new_session = True

        PuttyMachine(
            host,
            port=putty_port,
            connect_timeout=connect_timeout,
            new_session=new_session,
            encoding=encoding,
        )

        init.assert_called_with(
            mocker.ANY,
            host,
            user,
            port,
            keyfile=keyfile,
            ssh_command=ssh_command,
            scp_command=scp_command,
            ssh_opts=ssh_opts,
            scp_opts=scp_opts,
            encoding=encoding,
            connect_timeout=connect_timeout,
            new_session=new_session,
        )

    def test_putty_str(self, mocker):
        local = mocker.patch("plumbum.machines.ssh_machine.local")
        mocker.patch("plumbum.machines.ssh_machine.BaseRemoteMachine")

        host = mocker.MagicMock()
        user = local.env.user

        machine = PuttyMachine(host)
        assert str(machine) == f"putty-ssh://{user}@{host}"