Skip to content

Commit

Permalink
Fix linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeZiminski committed Nov 10, 2023
1 parent 699c22e commit 9442694
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
30 changes: 20 additions & 10 deletions tests/ssh_test_utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import builtins
import copy
import os
import platform
import stat
import subprocess
import sys
import warnings
import os
import subprocess
from pathlib import Path

import paramiko

from datashuttle.utils import rclone, ssh
Expand Down Expand Up @@ -62,7 +62,7 @@ def setup_hostkeys(project, setup_ssh_key_pair=True): # TODO: RENAME FUNCTION
This requires monkeypatching a number of functions involved
in the SSH setup process. `input()` is patched to always
return the required hostkey confirmation "y". `getpass()` is
patched to allways return the password for the container in which
patched to always return the password for the container in which
SSH tests are run. `isatty()` is patched because when running this
for some reason it appears to be in a TTY - this might be a
container thing.
Expand Down Expand Up @@ -95,8 +95,10 @@ def setup_hostkeys(project, setup_ssh_key_pair=True): # TODO: RENAME FUNCTION
def build_docker_image(project):
""""""
container_software = is_docker_or_singularity_installed()
assert container_software is not False, ("docker or singularity not installed, "
"this should be checked at the top of test script")
assert container_software is not False, (
"docker or singularity not installed, "
"this should be checked at the top of test script"
)

image_path = Path(__file__).parent / "ssh_test_images"
os.chdir(image_path)
Expand Down Expand Up @@ -152,18 +154,26 @@ def get_test_ssh():
if is_docker_or_singularity_installed():
test_ssh = True
else:
warnings.warn("SSH tests are not run as docker (Windows, macOS) "
"or singularity (Linux) is not installed.")
warnings.warn(
"SSH tests are not run as docker (Windows, macOS) "
"or singularity (Linux) is not installed."
)
test_ssh = False

return test_ssh


def is_docker_or_singularity_installed(): # TODO: need to test
""""""
check_install = lambda command: subprocess.run(
command, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
).returncode == 0
check_install = (
lambda command: subprocess.run(
command,
shell=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
).returncode
== 0
)

installed = False
if platform.system() == "Linux":
Expand Down
28 changes: 17 additions & 11 deletions tests/tests_integration/test_ssh_file_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,15 @@ def test_combinations_filesystem_transfer(
pass

@pytest.mark.skipif("not TEST_SSH", reason="TEST_SSH is false")
@pytest.mark.parametrize("sub_names", [["all"], ["all_non_sub", "sub-002"]])
@pytest.mark.parametrize("ses_names", [["all"], ["ses-002_random-key"], ["all_non_ses"]])
@pytest.mark.parametrize("datatype", [["all"], ["anat", "all_ses_level_non_datatype"]])
@pytest.mark.parametrize(
"sub_names", [["all"], ["all_non_sub", "sub-002"]]
)
@pytest.mark.parametrize(
"ses_names", [["all"], ["ses-002_random-key"], ["all_non_ses"]]
)
@pytest.mark.parametrize(
"datatype", [["all"], ["anat", "all_ses_level_non_datatype"]]
)
def test_combinations_ssh_transfer(
self,
ssh_setup,
Expand All @@ -160,7 +166,9 @@ def test_combinations_ssh_transfer(
pathtable, project = ssh_setup

true_central_path = project.cfg["central_path"]
tmp_central_path = project.cfg["central_path"] / "tmp" / project.project_name
tmp_central_path = (
project.cfg["central_path"] / "tmp" / project.project_name
)
project.update_config("central_path", tmp_central_path)

project.upload(sub_names, ses_names, datatype, init_log=False)
Expand All @@ -185,20 +193,18 @@ def test_combinations_ssh_transfer(

with paramiko.SSHClient() as client:
ssh.connect_client(client, project.cfg)
client.exec_command(
f"rm -rf {(tmp_central_path).as_posix()}"
)
client.exec_command(f"rm -rf {(tmp_central_path).as_posix()}")

true_local_path = project.cfg["local_path"]
tmp_local_path = project.cfg["local_path"] / "tmp" / project.project_name
tmp_local_path = (
project.cfg["local_path"] / "tmp" / project.project_name
)
tmp_local_path.mkdir(exist_ok=True, parents=True)

project.update_config("local_path", tmp_local_path)
project.update_config("central_path", true_central_path)

project.download(
sub_names, ses_names, datatype, init_log=False
)
project.download(sub_names, ses_names, datatype, init_log=False)

all_transferred = list((tmp_local_path / "rawdata").glob("**/*"))
all_transferred = [
Expand Down

0 comments on commit 9442694

Please sign in to comment.