Skip to content

Commit deada76

Browse files
authored
Merge pull request #1815 from dbcli/RW/improve-ssh-utils-test-coverage
Improve `ssh_utils.py` test coverage
2 parents 5cc9354 + d9aeb9e commit deada76

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

test/pytests/test_ssh_utils.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
from __future__ import annotations
22

3+
import builtins
4+
import importlib
35
from pathlib import Path
6+
import sys
47
from typing import TextIO
58

69
import pytest
710

8-
from mycli.packages import ssh_utils
11+
from mycli.packages import paramiko_stub, ssh_utils
912

1013

1114
class FakeSSHConfig:
@@ -66,3 +69,22 @@ def test_read_ssh_config_reports_parse_errors_and_exits(monkeypatch: pytest.Monk
6669

6770
assert excinfo.value.code == 1
6871
assert secho_calls == [(f'Could not parse SSH configuration file {config_path}:\nbad config ', True, 'red')]
72+
73+
74+
def test_ssh_utils_falls_back_to_paramiko_stub_when_paramiko_is_unavailable(monkeypatch: pytest.MonkeyPatch) -> None:
75+
original_import = builtins.__import__
76+
77+
def fake_import(name: str, globals_=None, locals_=None, fromlist=(), level: int = 0):
78+
if name == 'paramiko':
79+
raise ImportError('paramiko not installed')
80+
return original_import(name, globals_, locals_, fromlist, level)
81+
82+
monkeypatch.delitem(sys.modules, 'paramiko', raising=False)
83+
monkeypatch.setattr(builtins, '__import__', fake_import)
84+
85+
reloaded = importlib.reload(ssh_utils)
86+
87+
assert reloaded.paramiko is paramiko_stub.paramiko
88+
89+
monkeypatch.undo()
90+
importlib.reload(ssh_utils)

0 commit comments

Comments
 (0)