Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
5dc9cf0
lots of changes, sort out.
JoeZiminski Oct 6, 2023
01691a2
still working, needs a bit more tidying up.
JoeZiminski Oct 9, 2023
fa01259
Continue working.
JoeZiminski Oct 9, 2023
2c2b8ee
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 24, 2023
abda5c1
Tidy ups.
JoeZiminski Nov 10, 2023
2a5f7c8
Fix linting.
JoeZiminski Nov 10, 2023
518223e
Tidy ups and documentation.
JoeZiminski Nov 10, 2023
23bc818
Add documentation.
JoeZiminski Nov 10, 2023
981b1d9
Try different Dockerfile for linux.
JoeZiminski Nov 23, 2023
56b311e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 23, 2023
2435965
Fix issue after rebase.
JoeZiminski Apr 10, 2024
a0bf3af
Remove breakpoint.
JoeZiminski Apr 10, 2024
73bd6c8
Don't use singularity, docker or nothing.
JoeZiminski Apr 10, 2024
0679992
Rework ssh setup.
JoeZiminski Apr 10, 2024
29ed32a
Fix connection refused issue.
JoeZiminski Apr 11, 2024
9848b3e
Use run not POpen for actions.
JoeZiminski Apr 11, 2024
2e9132c
try in detachted state.
JoeZiminski Apr 11, 2024
b71f3c9
Add error messages on docker setup.
JoeZiminski Apr 18, 2024
99d9392
run linting.
JoeZiminski Apr 18, 2024
0225359
update connection failed error message.
JoeZiminski Apr 18, 2024
c8d0118
Test version working locally on linux but only can connect with sudo.
JoeZiminski Apr 19, 2024
a19212a
Try freeing up and using the free port.
JoeZiminski Apr 19, 2024
687bea3
Test sudo service only on linux.
JoeZiminski Apr 19, 2024
767a832
Add sudo to docker setup commands.
JoeZiminski Apr 19, 2024
9d287de
test with auto add policy.
JoeZiminski Apr 19, 2024
5dd2b21
Really restrict to the connect call.
JoeZiminski Apr 19, 2024
a9af048
restrict to tests of interest temporarily.
JoeZiminski Apr 19, 2024
197e051
Fix to port 3306 in tests and for paramiko.
JoeZiminski Apr 19, 2024
4b0b765
Extend port to rclone.
JoeZiminski Apr 19, 2024
aa6dfd4
Use environment variable to set port.
JoeZiminski Apr 19, 2024
4ae1c08
Add all OS back.
JoeZiminski Apr 19, 2024
c9dbe70
try remove tag for windows.
JoeZiminski Apr 19, 2024
8196aa9
Update docker commands for windows.
JoeZiminski Apr 20, 2024
c4bfe46
Fix nonsense docker build command.
JoeZiminski Apr 20, 2024
941f506
Only run when docker running and on ubuntu on runners.
JoeZiminski Apr 22, 2024
372407b
Try build and run docker only once per session.
JoeZiminski Apr 22, 2024
fa83eec
Teardown image at end of ssh tests, factor out ssh tests.
JoeZiminski Apr 22, 2024
1975226
SPlit ssh tests.
JoeZiminski Apr 22, 2024
81e4668
Add sudo to the docker teardown commands for Linux.
JoeZiminski Apr 22, 2024
a6d4446
try class scope of setup ssh container.
JoeZiminski Apr 22, 2024
01e0301
Try move ssh fixture to classes.
JoeZiminski Apr 22, 2024
6ea3034
Try a different command to shutdown on linux.
JoeZiminski Apr 22, 2024
8481bda
Tidy ups and some docs.
JoeZiminski Apr 22, 2024
5317eee
Extend to macOS.
JoeZiminski Apr 22, 2024
8c3d9d0
Finish tidying up docstrings.
JoeZiminski Apr 22, 2024
c7b4907
Change ssh test image name and fix docstring.
JoeZiminski Apr 22, 2024
7db2a14
Small tidy ups.
JoeZiminski Apr 22, 2024
d1db67e
Small fixes after rebase.
JoeZiminski Jun 20, 2025
54d25dc
More fix.es
JoeZiminski Jun 20, 2025
c03fa62
Fix CI.
JoeZiminski Jun 20, 2025
dab447f
Skip tests on macOS.
JoeZiminski Jun 21, 2025
4074295
Refactor transfer tests.
JoeZiminski Jun 21, 2025
d0f4aa4
Continue refactoring.
JoeZiminski Jun 21, 2025
ba8a5a6
Fix tests again.
JoeZiminski Jun 21, 2025
87c09b8
Update CI script.
JoeZiminski Jun 21, 2025
8e91179
Update CI.
JoeZiminski Jun 21, 2025
1958363
Fix imports after rebase.
JoeZiminski Jun 21, 2025
1d2d745
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 21, 2025
c2406cb
Merge branch 'main' into test_ssh_with_image
JoeZiminski Jun 22, 2025
33881f6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 22, 2025
1bb5f6c
Delete config to fix tests.
JoeZiminski Jun 23, 2025
25ba932
Remove test module that was accidentally readded by git.
JoeZiminski Jun 23, 2025
c8363cf
Delete now unused file.
JoeZiminski Jun 26, 2025
4a1fbdb
Do not append por with : if it is default (22).
JoeZiminski Jun 26, 2025
745887a
Move test setup_rclone_config_for_ssh into setup_ssh_connection.
JoeZiminski Jun 26, 2025
acaf9a9
Extend SSH tests not run message.
JoeZiminski Jun 26, 2025
669d050
Improve test skipped message.
JoeZiminski Jun 26, 2025
9991bda
Fix duplicate if / else statement.
JoeZiminski Jun 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .github/workflows/code_test_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
# macos-14 is M1, macos-13 is intel. Run on earliest and
# latest python versions. All python versions are tested in
# the weekly cron job.
os: [windows-latest, ubuntu-latest, macos-14, macos-13]
os: [ ubuntu-latest, windows-latest, macos-14, macos-13]
# Test all Python versions for cron job, and only first/last for other triggers
python-version: ${{ fromJson(github.event_name == 'schedule' && '["3.9", "3.10", "3.11", "3.12"]' || '["3.9", "3.12"]') }}

Expand All @@ -57,8 +57,17 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install .[dev]
- name: Test
run: pytest
# run SSH tests only on Linux because Windows and macOS
# are already run within a virtual container and so cannot
# run Linux containers because nested containerisation is disabled.
- name: Test SSH (Linux only)
if: runner.os == 'Linux'
run: |
sudo service mysql stop # free up port 3306 for ssh tests
pytest tests/tests_transfers/ssh
- name: All Other Tests
run: |
pytest --ignore tests/tests_transfers/ssh

build_sdist_wheels:
name: Build source distribution
Expand Down
9 changes: 9 additions & 0 deletions datashuttle/configs/canonical_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from __future__ import annotations

import os
from typing import (
TYPE_CHECKING,
Dict,
Expand Down Expand Up @@ -52,6 +53,14 @@ def keys_str_on_file_but_path_in_class() -> list[str]:
]


def get_default_ssh_port() -> int:
"""Get the default port used for SSH connections."""
if "DS_SSH_PORT" in os.environ:
return int(os.environ["DS_SSH_PORT"])
else:
return 22


# -----------------------------------------------------------------------------
# Check Configs
# -----------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion datashuttle/utils/data_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ def build_a_list_of_all_files_and_folders_to_transfer(self) -> List[str]:
self.update_list_with_non_ses_sub_level_folders(
extra_folder_names, extra_filenames, sub
)

continue

# Datatype (sub and ses level) --------------------------------
Expand Down
3 changes: 2 additions & 1 deletion datashuttle/utils/rclone.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from subprocess import CompletedProcess
from typing import Dict, List, Literal

from datashuttle.configs import canonical_configs
from datashuttle.configs.config_class import Configs
from datashuttle.utils import utils
from datashuttle.utils.custom_types import TopLevelFolder
Expand Down Expand Up @@ -161,7 +162,7 @@ def setup_rclone_config_for_ssh(
f"sftp "
f"host {cfg['central_host_id']} "
f"user {cfg['central_host_username']} "
f"port 22 "
f"port {canonical_configs.get_default_ssh_port()} "
f"key_file {ssh_key_path.as_posix()}",
pipe_std=True,
)
Expand Down
21 changes: 17 additions & 4 deletions datashuttle/utils/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import paramiko

from datashuttle.configs import canonical_configs
from datashuttle.utils import utils

# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -58,6 +59,7 @@ def connect_client_core(
else None
),
look_for_keys=True,
port=canonical_configs.get_default_ssh_port(),
)


Expand Down Expand Up @@ -122,7 +124,9 @@ def get_remote_server_key(central_host_id: str):

"""
transport: paramiko.Transport
with paramiko.Transport(central_host_id) as transport:
with paramiko.Transport(
(central_host_id, canonical_configs.get_default_ssh_port())
) as transport:
transport.connect()
key = transport.get_remote_server_key()
return key
Expand All @@ -148,7 +152,15 @@ def save_hostkey_locally(key, central_host_id, hostkeys_path) -> None:

"""
client = paramiko.SSHClient()
client.get_host_keys().add(central_host_id, key.get_name(), key)

port = canonical_configs.get_default_ssh_port()
host_key = f"[{central_host_id}]:{port}" if port != 22 else central_host_id

client.get_host_keys().add(
host_key,
key.get_name(),
key,
)
client.get_host_keys().save(hostkeys_path.as_posix())


Expand Down Expand Up @@ -242,15 +254,16 @@ def connect_client_with_logging(
f"Connection to {cfg['central_host_id']} made successfully."
)

except Exception:
except Exception as e:
utils.log_and_raise_error(
f"Could not connect to server. Ensure that \n"
f"1) You have run setup_ssh_connection() \n"
f"2) You are on VPN network if required. \n"
f"3) The central_host_id: {cfg['central_host_id']} is"
f" correct.\n"
f"4) The central username:"
f" {cfg['central_host_username']}, and password are correct.",
f" {cfg['central_host_username']}, and password are correct."
f"Original error: {e}",
ConnectionError,
)

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ select = [
"D", # pydocstyle
]
per-file-ignores = { "tests/*" = [
"D" # ignore docstring formatting in tests for now
"D", # ignore docstring formatting in tests for now
"TID252"
], "examples/*" = [
"D400", # first line should end with a period.
"D415", # first line should end with a period, question mark...
Expand Down
Empty file added tests/__init__.py
Empty file.
3 changes: 2 additions & 1 deletion tests/tests_integration/base.py → tests/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import warnings

import pytest
import test_utils

from . import test_utils

TEST_PROJECT_NAME = "test_project"

Expand Down
46 changes: 0 additions & 46 deletions tests/conftest.py

This file was deleted.

49 changes: 0 additions & 49 deletions tests/ssh_test_utils.py

This file was deleted.

13 changes: 0 additions & 13 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from pathlib import Path

import yaml
from file_conflicts_pathtable import get_pathtable

from datashuttle import DataShuttle
from datashuttle.configs import canonical_configs, canonical_folders
Expand Down Expand Up @@ -146,18 +145,6 @@ def make_test_path(base_path, local_or_central, test_project_name):
return Path(base_path) / local_or_central / test_project_name


def create_all_pathtable_files(pathtable):
for i in range(pathtable.shape[0]):
filepath = pathtable["base_folder"][i] / pathtable["path"][i]
filepath.parents[0].mkdir(parents=True, exist_ok=True)
write_file(filepath, contents="test_entry")


def quick_create_project(base_path):
pathtable = get_pathtable(base_path)
create_all_pathtable_files(pathtable)


# -----------------------------------------------------------------------------
# Test Configs
# -----------------------------------------------------------------------------
Expand Down
Empty file.
5 changes: 3 additions & 2 deletions tests/tests_integration/test_configs.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os

import pytest
import test_utils
from base import BaseTest

from datashuttle import DataShuttle
from datashuttle.utils import getters
from datashuttle.utils.custom_exceptions import ConfigError

from .. import test_utils
from ..base import BaseTest


class TestConfigs(BaseTest):
# Test Errors
Expand Down
5 changes: 3 additions & 2 deletions tests/tests_integration/test_create_folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
from os.path import join

import pytest
import test_utils
from base import BaseTest

from datashuttle.configs import canonical_configs, canonical_folders
from datashuttle.configs.canonical_tags import tags

from .. import test_utils
from ..base import BaseTest


class TestCreateFolders(BaseTest):
@pytest.mark.parametrize("project", ["local", "full"], indirect=True)
Expand Down
5 changes: 3 additions & 2 deletions tests/tests_integration/test_datatypes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import os

import pytest
import test_utils
from base import BaseTest

from datashuttle.configs import canonical_configs

from .. import test_utils
from ..base import BaseTest


class TestDatatypes(BaseTest):
"""Tests for creating folders and transfer (very similar to other tests)
Expand Down
3 changes: 2 additions & 1 deletion tests/tests_integration/test_formatting.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import pytest
from base import BaseTest

from datashuttle.utils import formatting
from datashuttle.utils.custom_exceptions import NeuroBlueprintError

from ..base import BaseTest


class TestFormatting(BaseTest):
@pytest.mark.parametrize("prefix", ["sub", "ses"])
Expand Down
5 changes: 3 additions & 2 deletions tests/tests_integration/test_local_only_mode.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import shutil

import pytest
import test_utils
from base import BaseTest

from datashuttle.utils.custom_exceptions import (
ConfigError,
)

from .. import test_utils
from ..base import BaseTest

TEST_PROJECT_NAME = "test_project"


Expand Down
3 changes: 2 additions & 1 deletion tests/tests_integration/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from pathlib import Path

import pytest
import test_utils

from datashuttle.configs import canonical_configs
from datashuttle.configs.canonical_tags import tags
Expand All @@ -15,6 +14,8 @@
NeuroBlueprintError,
)

from .. import test_utils


class TestLogging:
@pytest.fixture(scope="function")
Expand Down
5 changes: 3 additions & 2 deletions tests/tests_integration/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
import shutil

import pytest
import test_utils
from base import BaseTest

from datashuttle.configs import canonical_configs
from datashuttle.utils import validation
from datashuttle.utils.custom_exceptions import NeuroBlueprintError

from .. import test_utils
from ..base import BaseTest


class TestPersistentSettings(BaseTest):
@pytest.mark.parametrize("project", ["local", "full"], indirect=True)
Expand Down
Loading
Loading