|
16 | 16 | from fsspec.registry import _registry |
17 | 17 | from fsspec.registry import register_implementation |
18 | 18 | from fsspec.utils import stringify_path |
| 19 | +from packaging.version import Version |
19 | 20 |
|
20 | 21 | from .utils import posixify |
21 | 22 |
|
@@ -464,3 +465,61 @@ def smb_fixture(local_testdir, smb_url, smb_container): |
464 | 465 | smb.put(local_testdir, "/home/testdir", recursive=True) |
465 | 466 | yield url |
466 | 467 | smb.delete("/home/testdir", recursive=True) |
| 468 | + |
| 469 | + |
| 470 | +@pytest.fixture(scope="module") |
| 471 | +def ssh_container(): |
| 472 | + if shutil.which("docker") is None: |
| 473 | + pytest.skip("docker not installed") |
| 474 | + |
| 475 | + name = "fsspec_test_ssh" |
| 476 | + stop_docker(name) |
| 477 | + cmd = ( |
| 478 | + "docker run" |
| 479 | + " -d" |
| 480 | + f" --name {name}" |
| 481 | + " -e USER_NAME=user" |
| 482 | + " -e PASSWORD_ACCESS=true" |
| 483 | + " -e USER_PASSWORD=pass" |
| 484 | + " -p 2222:2222" |
| 485 | + " linuxserver/openssh-server:latest" |
| 486 | + ) |
| 487 | + try: |
| 488 | + subprocess.run(shlex.split(cmd)) |
| 489 | + time.sleep(1) |
| 490 | + yield { |
| 491 | + "host": "localhost", |
| 492 | + "port": 2222, |
| 493 | + "username": "user", |
| 494 | + "password": "pass", |
| 495 | + } |
| 496 | + finally: |
| 497 | + stop_docker(name) |
| 498 | + |
| 499 | + |
| 500 | +@pytest.fixture |
| 501 | +def ssh_fixture(ssh_container, local_testdir, monkeypatch): |
| 502 | + pytest.importorskip("paramiko", reason="sftp tests require paramiko") |
| 503 | + |
| 504 | + cls = fsspec.get_filesystem_class("ssh") |
| 505 | + if cls.put != fsspec.AbstractFileSystem.put: |
| 506 | + monkeypatch.setattr(cls, "put", fsspec.AbstractFileSystem.put) |
| 507 | + if Version(fsspec.__version__) < Version("2022.10.0"): |
| 508 | + from fsspec.callbacks import _DEFAULT_CALLBACK |
| 509 | + |
| 510 | + monkeypatch.setattr(_DEFAULT_CALLBACK, "relative_update", lambda *args: None) |
| 511 | + |
| 512 | + fs = fsspec.filesystem( |
| 513 | + "ssh", |
| 514 | + host=ssh_container["host"], |
| 515 | + port=ssh_container["port"], |
| 516 | + username=ssh_container["username"], |
| 517 | + password=ssh_container["password"], |
| 518 | + ) |
| 519 | + fs.put(local_testdir, "/app/testdir", recursive=True) |
| 520 | + try: |
| 521 | + yield "ssh://{username}:{password}@{host}:{port}/app/testdir/".format( |
| 522 | + **ssh_container |
| 523 | + ) |
| 524 | + finally: |
| 525 | + fs.delete("/app/testdir", recursive=True) |
0 commit comments