Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion datashuttle/tui/screens/create_folder_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def compose(self) -> ComposeResult:
sub_on = True if self.input_mode == "sub" else False
ses_on = not sub_on

explanation = """
explanation = r"""
A 'Template' can be set check subject or session names are
formatted in a specific way.

Expand Down
2 changes: 1 addition & 1 deletion datashuttle/utils/getters.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def get_num_value_digits_from_project(
def get_num_value_digits_from_regexp(
prefix: Prefix, name_template_regexp: str
) -> Union[Literal[False], int]:
"""
r"""
Given a name template regexp, find the number of values for the
sub or ses key. These will be fixed with "\d" (digit) or ".?" (wildcard).
If there is length-unspecific wildcard (.*) in the sub key, then skip.
Expand Down
6 changes: 3 additions & 3 deletions datashuttle/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def get_path_and_name(path_or_name: Path | str) -> Tuple[Optional[Path], str]:


def replace_tags_in_regexp(regexp: str) -> str:
"""
r"""
Before validation, all tags in the names are converted to
their final values (e.g. @DATE@ -> _date-<date>). We also want to
allow template to be formatted like `sub-\d\d_@DATE@` as it
Expand All @@ -321,8 +321,8 @@ def replace_tags_in_regexp(regexp: str) -> str:
Note `replace_date_time_tags_in_name()` operates in place on a list.
"""
regexp_list = [regexp]
date_regexp = "\d\d\d\d\d\d\d\d"
time_regexp = "\d\d\d\d\d\d"
date_regexp = r"\d\d\d\d\d\d\d\d"
time_regexp = r"\d\d\d\d\d\d"

formatting.replace_date_time_tags_in_name(
regexp_list,
Expand Down
17 changes: 9 additions & 8 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,12 @@ def setup_project_default_configs(
"""
delete_project_if_it_exists(project_name)

warnings.filterwarnings("ignore")

project = DataShuttle(project_name)
project = make_project(project_name)

default_configs = get_test_config_arguments_dict(
tmp_path, project_name, set_as_defaults=True
)

# make_project_paths(default_configs)

project.make_config_file(**default_configs)

rclone.setup_rclone_config_for_ssh(
Expand All @@ -52,8 +48,6 @@ def setup_project_default_configs(
project.cfg.ssh_key_path,
)

warnings.filterwarnings("default")

if local_path:
os.makedirs(local_path, exist_ok=True)
project.update_config_file(local_path=local_path)
Expand Down Expand Up @@ -147,7 +141,7 @@ def setup_project_fixture(tmp_path, test_project_name, project_type="full"):
),
)
elif project_type == "local":
project = DataShuttle(test_project_name)
project = make_project(test_project_name)
project.make_config_file(
local_path=make_test_path(tmp_path, "local", test_project_name)
)
Expand Down Expand Up @@ -699,3 +693,10 @@ def get_task_by_name(name):
async def await_task_by_name_if_present(name: str) -> None:
if task := get_task_by_name(name):
await task


def make_project(project_name):
warnings.filterwarnings("ignore")
project = DataShuttle(project_name)
warnings.filterwarnings("default")
return project
6 changes: 2 additions & 4 deletions tests/tests_integration/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import pytest
import test_utils

from datashuttle import DataShuttle

TEST_PROJECT_NAME = "test_project"


Expand All @@ -19,7 +17,7 @@ def no_cfg_project(test):
test_utils.delete_project_if_it_exists(TEST_PROJECT_NAME)

warnings.filterwarnings("ignore")
no_cfg_project = DataShuttle(TEST_PROJECT_NAME)
no_cfg_project = test_utils.make_project(TEST_PROJECT_NAME)
warnings.filterwarnings("default")

yield no_cfg_project
Expand Down Expand Up @@ -51,7 +49,7 @@ def project(self, tmp_path, request):
)
elif project_type == "local":
test_utils.delete_project_if_it_exists(TEST_PROJECT_NAME)
project = DataShuttle(TEST_PROJECT_NAME)
project = test_utils.make_project(TEST_PROJECT_NAME)
project.make_config_file(local_path=tmp_path / TEST_PROJECT_NAME)

else:
Expand Down
8 changes: 5 additions & 3 deletions tests/tests_integration/test_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def test_bad_path_syntax(self, project, bad_pattern, path_type, tmp_path):

Note pathlib strips "./" so not checked.
"""
os.chdir(tmp_path)

if bad_pattern != ".":
bad_pattern = f"{bad_pattern}/{project.project_name}"
good_pattern = f"{tmp_path}/my/path/{project.project_name}"
Expand Down Expand Up @@ -236,7 +238,7 @@ def patch_get_datashuttle_path():
patch_get_datashuttle_path,
)

project_1 = DataShuttle("project_1")
project_1 = test_utils.make_project("project_1")
project_1.make_config_file(
tmp_path / "project_1",
tmp_path / "project_1",
Expand All @@ -247,7 +249,7 @@ def patch_get_datashuttle_path():
# have a config file.
os.mkdir(tmp_path / "projects" / "project_2")

project_2 = DataShuttle("project_3")
project_2 = test_utils.make_project("project_3")
project_2.make_config_file(
tmp_path / "project_3",
tmp_path / "project_3",
Expand Down Expand Up @@ -276,6 +278,6 @@ def check_config_reopen_and_check_config_again(self, project, *kwargs):

del project # del project is almost certainly unnecessary

project = DataShuttle(project_name)
project = test_utils.make_project(project_name)

test_utils.check_configs(project, kwargs[0])
2 changes: 1 addition & 1 deletion tests/tests_integration/test_filesystem_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def test_transfer_with_keyword_parameters(
(base_local / "rawdata" / sub / "ses*").as_posix()
)

datetime_regexp = "datetime-\d{8}T\d{6}"
datetime_regexp = r"datetime-\d{8}T\d{6}"

assert re.fullmatch(
"ses-001_" + datetime_regexp, sessions_in_path[0]
Expand Down
3 changes: 1 addition & 2 deletions tests/tests_integration/test_local_only_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import test_utils
from base import BaseTest

from datashuttle import DataShuttle
from datashuttle.utils.custom_exceptions import (
ConfigError,
)
Expand All @@ -21,7 +20,7 @@ def test_bad_setup(self, tmp_path):
"""
local_path = tmp_path / "test_local"

project = DataShuttle("this_project_is_not_torn_down")
project = test_utils.make_project("this_project_is_not_torn_down")

with pytest.raises(ConfigError) as e:
project.make_config_file(
Expand Down
7 changes: 3 additions & 4 deletions tests/tests_integration/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import pytest
import test_utils

from datashuttle import DataShuttle
from datashuttle.configs import canonical_configs
from datashuttle.configs.canonical_tags import tags
from datashuttle.utils import ds_logger
Expand Down Expand Up @@ -154,7 +153,7 @@ def test_log_filename(self, project):

def test_logs_make_config_file(self, clean_project_name, tmp_path):
""""""
project = DataShuttle(clean_project_name)
project = test_utils.make_project(clean_project_name)

project.make_config_file(
tmp_path / clean_project_name,
Expand Down Expand Up @@ -358,7 +357,7 @@ def test_temp_log_folder_moved_make_config_file(
logs are moved to the passed `local_path` when
`make_config_file()` is passed.
"""
project = DataShuttle(clean_project_name)
project = test_utils.make_project(clean_project_name)

configs = test_utils.get_test_config_arguments_dict(
tmp_path, clean_project_name
Expand Down Expand Up @@ -389,7 +388,7 @@ def test_clear_logging_path(self, clean_project_name, tmp_path):
begins, this test checks the `_temp_log_path`
is cleared correctly.
"""
project = DataShuttle(clean_project_name)
project = test_utils.make_project(clean_project_name)

configs = test_utils.get_test_config_arguments_dict(
tmp_path, clean_project_name
Expand Down
12 changes: 6 additions & 6 deletions tests/tests_integration/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import shutil

import pytest
import test_utils
from base import BaseTest

from datashuttle import DataShuttle
from datashuttle.configs import canonical_configs
from datashuttle.utils import validation
from datashuttle.utils.custom_exceptions import NeuroBlueprintError
Expand Down Expand Up @@ -32,8 +32,8 @@ def test_persistent_settings_name_templates(self, project):
assert name_templates["ses"] is None

# Set some new settings and check they become persistent
sub_regexp = "sub-\d_id-.?.?_random-.*"
ses_regexp = "ses-\d\d_id-.?.?.?_random-.*"
sub_regexp = r"sub-\d_id-.?.?_random-.*"
ses_regexp = r"ses-\d\d_id-.?.?.?_random-.*"

new_name_templates = {
"on": True,
Expand All @@ -43,7 +43,7 @@ def test_persistent_settings_name_templates(self, project):

project.set_name_templates(new_name_templates)

project_reload = DataShuttle(project.project_name)
project_reload = test_utils.make_project(project.project_name)

reload_name_templates = project_reload.get_name_templates()

Expand Down Expand Up @@ -138,7 +138,7 @@ def test_persistent_settings_tui(self, project):
project._update_persistent_setting("tui", new_tui_settings)

# Reload and check
project = DataShuttle(project.project_name)
project = test_utils.make_project(project.project_name)

reloaded_settings = project._load_persistent_settings()
assert reloaded_settings["tui"] == new_tui_settings
Expand All @@ -155,7 +155,7 @@ def test_bypass_validation(self, project):
# should not raise
project.create_folders("rawdata", "sub-@@@", bypass_validation=True)

project = DataShuttle(project.project_name)
project = test_utils.make_project(project.project_name)

with pytest.raises(BaseException) as e:
project.create_folders("rawdata", "sub-@@@")
Expand Down
23 changes: 15 additions & 8 deletions tests/tests_integration/test_validation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os.path
import shutil
import warnings

import pytest
from base import BaseTest
Expand Down Expand Up @@ -408,9 +409,12 @@ def test_validate_project_returned_list(self, project, prefix):
"rawdata", "sub-001", bad_names, bypass_validation=True
)

warnings.filterwarnings("ignore")
error_messages = project.validate_project(
"rawdata", "warn", include_central=False
)
warnings.filterwarnings("default")

concat_error = "".join(error_messages)

assert "DATETIME" in concat_error
Expand All @@ -426,9 +430,11 @@ def test_output_paths_are_valid(self, project):
"rawdata", sub_name, ses_name, bypass_validation=True
)

warnings.filterwarnings("ignore")
error_messages = project.validate_project(
"rawdata", "warn", include_central=False
)
warnings.filterwarnings("default")

sub_path = error_messages[0].split("Path: ")[-1]
ses_path = error_messages[1].split("Path: ")[-1]
Expand Down Expand Up @@ -717,8 +723,8 @@ def test_tags_in_name_templates_pass_validation(self, project):
"""
name_templates = {
"on": True,
"sub": "sub-\d\d_@DATE@",
"ses": "ses-\d\d\d@DATETIME@",
"sub": r"sub-\d\d_@DATE@",
"ses": r"ses-\d\d\d@DATETIME@",
}

project.set_name_templates(name_templates)
Expand All @@ -745,7 +751,7 @@ def test_tags_in_name_templates_pass_validation(self, project):
assert "TEMPLATE: The name: ses-001_datex-20241212" in str(e.value)

# Do a quick test for time
name_templates["sub"] = "sub-\d\d_@TIME@"
name_templates["sub"] = r"sub-\d\d_@TIME@"
project.set_name_templates(name_templates)

# use time tag, should not raise
Expand All @@ -760,22 +766,23 @@ def test_tags_in_name_templates_pass_validation(self, project):
assert "TEMPLATE: The name: ses-001_datex-20241212" in str(e.value)

def test_name_templates_validate_project(self, project):
"""
TODO
"""

# set up name templates
name_templates = {
"on": True,
"sub": "sub-\d\d_id-\d.?",
"ses": "ses-\d\d_id-\d.?",
"sub": r"sub-\d\d_id-\d.?",
"ses": r"ses-\d\d_id-\d.?",
}
project.set_name_templates(name_templates)

# Create names that match, check this does not error
project.create_folders(
"rawdata", "sub-01_id-2b", "ses-01_id-1a", bypass_validation=True
)

project.validate_project("rawdata", "error", include_central=False)

# Create names that don't match, check they error
project.create_folders(
"rawdata", "sub-02_id-a1", "ses-02_id-aa", bypass_validation=True
)
Expand Down
8 changes: 3 additions & 5 deletions tests/tests_regression/test_backwards_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import pytest
import test_utils

from datashuttle import DataShuttle

TEST_PROJECT_NAME = "test_project"


Expand All @@ -20,7 +18,7 @@ def project(self):
"""
test_utils.delete_project_if_it_exists(TEST_PROJECT_NAME)

project = DataShuttle(TEST_PROJECT_NAME)
project = test_utils.make_project(TEST_PROJECT_NAME)

yield project

Expand Down Expand Up @@ -104,7 +102,7 @@ def load_and_check_old_version_yamls(

# In the current version of datashuttle, get the settings. These are
# thus correct for the most recent datashuttle version.
project = DataShuttle(TEST_PROJECT_NAME)
project = test_utils.make_project(TEST_PROJECT_NAME)
project.make_config_file("cur_ver", "cur_ver", "local_filesystem")

current_ver_configs = project.get_configs()
Expand All @@ -117,7 +115,7 @@ def load_and_check_old_version_yamls(
shutil.copy(old_version_path / "config.yaml", config_path)
shutil.copy(old_version_path / "persistent_settings.yaml", config_path)

project = DataShuttle(TEST_PROJECT_NAME)
project = test_utils.make_project(TEST_PROJECT_NAME)

reloaded_ver_configs = project.get_configs()
reloaded_ver_persistent_settings = project._load_persistent_settings()
Expand Down
Loading
Loading