From e24f2dec0ec4f008e618875919ad97928a1fcd2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saugat=20Pachhai=20=28=E0=A4=B8=E0=A5=8C=E0=A4=97=E0=A4=BE?= =?UTF-8?q?=E0=A4=A4=29?= Date: Thu, 17 Mar 2022 15:46:56 +0545 Subject: [PATCH] fix type-hints We were using wrong typehints - SSHConnection vs SSHClientConnection. And SSHFileProtocol.read() is typed as requiring `read` and `offset` explicitly now, which has been updated in the test. --- scmrepo/git/backend/dulwich/asyncssh_vendor.py | 10 ++++------ tests/conftest.py | 4 ++-- tests/test_git.py | 6 +++--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/scmrepo/git/backend/dulwich/asyncssh_vendor.py b/scmrepo/git/backend/dulwich/asyncssh_vendor.py index ae881a50..f84c63b2 100644 --- a/scmrepo/git/backend/dulwich/asyncssh_vendor.py +++ b/scmrepo/git/backend/dulwich/asyncssh_vendor.py @@ -7,7 +7,7 @@ from scmrepo.asyn import BaseAsyncObject, sync_wrapper if TYPE_CHECKING: - from asyncssh.connection import SSHClientConnection, SSHConnection + from asyncssh.connection import SSHClientConnection from asyncssh.process import SSHClientProcess from asyncssh.stream import SSHReader @@ -37,7 +37,7 @@ async def _read(self, n: Optional[int] = None) -> bytes: class AsyncSSHWrapper(BaseAsyncObject): def __init__( - self, conn: "SSHConnection", proc: "SSHClientProcess", **kwargs + self, conn: "SSHClientConnection", proc: "SSHClientProcess", **kwargs ): super().__init__(**kwargs) self.conn: "SSHClientConnection" = conn @@ -146,7 +146,7 @@ async def _run_command( MSG_USERAUTH_PK_OK ] = _process_public_key_ok_gh - conn: "SSHClientConnection" = await asyncssh.connect( + conn = await asyncssh.connect( host, port=port if port is not None else (), username=username if username is not None else (), @@ -156,9 +156,7 @@ async def _run_command( known_hosts=None, encoding=None, ) - proc: "SSHClientProcess" = await conn.create_process( - command, encoding=None - ) + proc = await conn.create_process(command, encoding=None) return AsyncSSHWrapper(conn, proc) run_command = sync_wrapper(_run_command) diff --git a/tests/conftest.py b/tests/conftest.py index d0c39e0a..794b1f77 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -126,14 +126,14 @@ def check() -> bool: @pytest.fixture async def ssh_connection( ssh_conn_info: Dict[str, Any], -) -> AsyncIterator[asyncssh.connection.SSHConnection]: +) -> AsyncIterator[asyncssh.connection.SSHClientConnection]: async with asyncssh.connect(**ssh_conn_info) as conn: yield conn @pytest.fixture async def sftp( - ssh_connection: asyncssh.connection.SSHConnection, + ssh_connection: asyncssh.connection.SSHClientConnection, ) -> AsyncIterator[asyncssh.SFTPClient]: async with ssh_connection.start_sftp_client() as sftp: yield sftp diff --git a/tests/test_git.py b/tests/test_git.py index 4a7c8d5a..adfc3de7 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -4,7 +4,7 @@ import pytest from asyncssh import SFTPClient -from asyncssh.connection import SSHConnection +from asyncssh.connection import SSHClientConnection from git import Repo as GitPythonRepo from pytest_test_utils import TempDirFactory, TmpDir from pytest_test_utils.matchers import Matcher @@ -844,7 +844,7 @@ async def test_git_ssh( scm: Git, git: Git, sftp: SFTPClient, - ssh_connection: SSHConnection, + ssh_connection: SSHClientConnection, ssh_conn_info: Dict[str, Any], ): host, port = ssh_conn_info["host"], ssh_conn_info["port"] @@ -868,7 +868,7 @@ async def test_git_ssh( ) async with sftp.open("test-repo.git/refs/heads/master") as fobj: - assert (await fobj.read()).strip() == rev + assert (await fobj.read(-1, 0)).strip() == rev shutil.rmtree(tmp_dir / ".git") (tmp_dir / "foo").unlink()