Skip to content

Commit 8d0f0a3

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 699c22e commit 8d0f0a3

2 files changed

Lines changed: 36 additions & 20 deletions

File tree

tests/ssh_test_utils.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import builtins
22
import copy
3+
import os
34
import platform
45
import stat
56
import subprocess
67
import sys
78
import warnings
8-
import os
9-
import subprocess
109
from pathlib import Path
10+
1111
import paramiko
1212

1313
from datashuttle.utils import rclone, ssh
@@ -95,8 +95,10 @@ def setup_hostkeys(project, setup_ssh_key_pair=True): # TODO: RENAME FUNCTION
9595
def build_docker_image(project):
9696
""""""
9797
container_software = is_docker_or_singularity_installed()
98-
assert container_software is not False, ("docker or singularity not installed, "
99-
"this should be checked at the top of test script")
98+
assert container_software is not False, (
99+
"docker or singularity not installed, "
100+
"this should be checked at the top of test script"
101+
)
100102

101103
image_path = Path(__file__).parent / "ssh_test_images"
102104
os.chdir(image_path)
@@ -152,18 +154,26 @@ def get_test_ssh():
152154
if is_docker_or_singularity_installed():
153155
test_ssh = True
154156
else:
155-
warnings.warn("SSH tests are not run as docker (Windows, macOS) "
156-
"or singularity (Linux) is not installed.")
157+
warnings.warn(
158+
"SSH tests are not run as docker (Windows, macOS) "
159+
"or singularity (Linux) is not installed."
160+
)
157161
test_ssh = False
158162

159163
return test_ssh
160164

161165

162166
def is_docker_or_singularity_installed(): # TODO: need to test
163167
""""""
164-
check_install = lambda command: subprocess.run(
165-
command, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
166-
).returncode == 0
168+
check_install = (
169+
lambda command: subprocess.run(
170+
command,
171+
shell=True,
172+
stdout=subprocess.DEVNULL,
173+
stderr=subprocess.DEVNULL,
174+
).returncode
175+
== 0
176+
)
167177

168178
installed = False
169179
if platform.system() == "Linux":

tests/tests_integration/test_ssh_file_transfer.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,15 @@ def test_combinations_filesystem_transfer(
142142
pass
143143

144144
@pytest.mark.skipif("not TEST_SSH", reason="TEST_SSH is false")
145-
@pytest.mark.parametrize("sub_names", [["all"], ["all_non_sub", "sub-002"]])
146-
@pytest.mark.parametrize("ses_names", [["all"], ["ses-002_random-key"], ["all_non_ses"]])
147-
@pytest.mark.parametrize("datatype", [["all"], ["anat", "all_ses_level_non_datatype"]])
145+
@pytest.mark.parametrize(
146+
"sub_names", [["all"], ["all_non_sub", "sub-002"]]
147+
)
148+
@pytest.mark.parametrize(
149+
"ses_names", [["all"], ["ses-002_random-key"], ["all_non_ses"]]
150+
)
151+
@pytest.mark.parametrize(
152+
"datatype", [["all"], ["anat", "all_ses_level_non_datatype"]]
153+
)
148154
def test_combinations_ssh_transfer(
149155
self,
150156
ssh_setup,
@@ -160,7 +166,9 @@ def test_combinations_ssh_transfer(
160166
pathtable, project = ssh_setup
161167

162168
true_central_path = project.cfg["central_path"]
163-
tmp_central_path = project.cfg["central_path"] / "tmp" / project.project_name
169+
tmp_central_path = (
170+
project.cfg["central_path"] / "tmp" / project.project_name
171+
)
164172
project.update_config("central_path", tmp_central_path)
165173

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

186194
with paramiko.SSHClient() as client:
187195
ssh.connect_client(client, project.cfg)
188-
client.exec_command(
189-
f"rm -rf {(tmp_central_path).as_posix()}"
190-
)
196+
client.exec_command(f"rm -rf {(tmp_central_path).as_posix()}")
191197

192198
true_local_path = project.cfg["local_path"]
193-
tmp_local_path = project.cfg["local_path"] / "tmp" / project.project_name
199+
tmp_local_path = (
200+
project.cfg["local_path"] / "tmp" / project.project_name
201+
)
194202
tmp_local_path.mkdir(exist_ok=True, parents=True)
195203

196204
project.update_config("local_path", tmp_local_path)
197205
project.update_config("central_path", true_central_path)
198206

199-
project.download(
200-
sub_names, ses_names, datatype, init_log=False
201-
)
207+
project.download(sub_names, ses_names, datatype, init_log=False)
202208

203209
all_transferred = list((tmp_local_path / "rawdata").glob("**/*"))
204210
all_transferred = [

0 commit comments

Comments
 (0)