test: cover easy missing branches in report/config/credentials/ssh/wait/job
Lint / pssa (push) Successful in 34s
Lint / python (push) Successful in 41s

This commit is contained in:
2026-05-14 23:23:55 +02:00
parent b2b31f4b6e
commit dc8449a0d7
6 changed files with 371 additions and 0 deletions
+85
View File
@@ -118,6 +118,91 @@ def test_run_raises_on_nonzero(monkeypatch: pytest.MonkeyPatch) -> None:
t.run("bad")
def test_close_is_idempotent_and_swallows(monkeypatch: pytest.MonkeyPatch) -> None:
class _ExplodingClient(_FakeSSHClient):
def close(self) -> None: # type: ignore[override]
raise RuntimeError("already closed")
client = _ExplodingClient()
_install_fake_paramiko(monkeypatch, client)
t = SshTransport("10.0.0.2", key_path="/tmp/key")
t._connect() # type: ignore[attr-defined]
t.close()
t.close() # idempotent on already-closed (no client)
def test_context_manager_connects_and_closes(monkeypatch: pytest.MonkeyPatch) -> None:
client = _FakeSSHClient()
_install_fake_paramiko(monkeypatch, client)
with SshTransport("10.0.0.2", key_path="/tmp/key") as t:
assert isinstance(t, SshTransport)
assert client.closed
def test_known_hosts_file_is_loaded(
monkeypatch: pytest.MonkeyPatch, tmp_path: Any
) -> None:
kh = tmp_path / "known_hosts"
kh.write_text("")
loaded: list[str] = []
class _RecordingClient(_FakeSSHClient):
def load_host_keys(self, p: str) -> None: # type: ignore[override]
loaded.append(p)
client = _RecordingClient()
_install_fake_paramiko(monkeypatch, client)
t = SshTransport("10.0.0.2", key_path="/tmp/key", known_hosts=str(kh))
t.run("ls")
assert loaded == [str(kh)]
def test_is_ready_returns_true_on_success(monkeypatch: pytest.MonkeyPatch) -> None:
client = _FakeSSHClient()
_install_fake_paramiko(monkeypatch, client)
t = SshTransport("10.0.0.2", key_path="/tmp/key")
assert t.is_ready() is True
def test_is_ready_returns_false_on_connect_error(
monkeypatch: pytest.MonkeyPatch,
) -> None:
class _BoomClient(_FakeSSHClient):
def connect(self, **_kw: Any) -> None: # type: ignore[override]
raise RuntimeError("net down")
client = _BoomClient()
_install_fake_paramiko(monkeypatch, client)
t = SshTransport("10.0.0.2", key_path="/tmp/key")
assert t.is_ready() is False
def test_copy_wraps_sftp_error(monkeypatch: pytest.MonkeyPatch, tmp_path: Any) -> None:
class _BadSFTP(_FakeSFTP):
def put(self, _l: str, _r: str) -> None: # type: ignore[override]
raise RuntimeError("sftp boom")
client = _FakeSSHClient()
client.sftp = _BadSFTP()
_install_fake_paramiko(monkeypatch, client)
t = SshTransport("10.0.0.2", key_path="/tmp/key")
with pytest.raises(TransportConnectError):
t.copy("/x", "/y")
def test_fetch_wraps_sftp_error(monkeypatch: pytest.MonkeyPatch) -> None:
class _BadSFTP(_FakeSFTP):
def get(self, _r: str, _l: str) -> None: # type: ignore[override]
raise RuntimeError("sftp boom")
client = _FakeSSHClient()
client.sftp = _BadSFTP()
_install_fake_paramiko(monkeypatch, client)
t = SshTransport("10.0.0.2", key_path="/tmp/key")
with pytest.raises(TransportConnectError):
t.fetch("/y", "/x")
def test_default_policy_is_auto_add(monkeypatch: pytest.MonkeyPatch) -> None:
"""Mirrors permissive `StrictHostKeyChecking=no` default for ephemeral CI VMs."""
client = _FakeSSHClient()