Skip to content

Commit

Permalink
fix type-hints
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
skshetry committed Mar 17, 2022
1 parent 6230dfb commit e24f2de
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
10 changes: 4 additions & 6 deletions scmrepo/git/backend/dulwich/asyncssh_vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 (),
Expand All @@ -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)
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand All @@ -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()
Expand Down

0 comments on commit e24f2de

Please sign in to comment.