diff --git a/datashuttle/utils/formatting.py b/datashuttle/utils/formatting.py index 8c32ac48..cc653f0d 100644 --- a/datashuttle/utils/formatting.py +++ b/datashuttle/utils/formatting.py @@ -216,26 +216,28 @@ def update_names_with_datetime(names: List[str]) -> None: Format using key-value pair for bids, i.e. date-20221223_time- """ date = str(datetime.datetime.now().date().strftime("%Y%m%d")) - format_date = f"date-{date}" + date_with_key = f"date-{date}" time_ = datetime.datetime.now().time().strftime("%H%M%S") - format_time = f"time-{time_}" + time_with_key = f"time-{time_}" + + datetime_with_key = f"datetime-{date}T{time_}" for i, name in enumerate(names): - if tags("datetime") in name: # must come first + # datetime conditional must come first. + if tags("datetime") in name: name = add_underscore_before_after_if_not_there( name, tags("datetime") ) - datetime_ = f"{format_date}_{format_time}" - names[i] = name.replace(tags("datetime"), datetime_) + names[i] = name.replace(tags("datetime"), datetime_with_key) elif tags("date") in name: name = add_underscore_before_after_if_not_there(name, tags("date")) - names[i] = name.replace(tags("date"), format_date) + names[i] = name.replace(tags("date"), date_with_key) elif tags("time") in name: name = add_underscore_before_after_if_not_there(name, tags("time")) - names[i] = name.replace(tags("time"), format_time) + names[i] = name.replace(tags("time"), time_with_key) def add_underscore_before_after_if_not_there(string: str, key: str) -> str: diff --git a/docs/source/conf.py b/docs/source/conf.py index 2b58a585..9a21f6d1 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -114,7 +114,7 @@ html_favicon = "_static/logo_light.png" -# Cutomize the theme +# Customize the theme html_theme_options = { "icon_links": [ { diff --git a/tests/tests_integration/test_command_line_interface.py b/tests/tests_integration/test_command_line_interface.py index d087d932..4180a764 100644 --- a/tests/tests_integration/test_command_line_interface.py +++ b/tests/tests_integration/test_command_line_interface.py @@ -611,7 +611,7 @@ def convert_kwargs_to_cli(self, kwargs, sep="-"): Take a list of key-value pairs that make up the arguments we want to pass to CLI, and put them in correct format. This involves - pre-pending "--argument_name" for non-positional + prepending "--argument_name" for non-positional arguments, and wrapping paths in quotes. """ positionals = ["local_path", "central_path", "connection_method"] diff --git a/tests/tests_integration/test_filesystem_transfer.py b/tests/tests_integration/test_filesystem_transfer.py index d13d04fc..9685886c 100644 --- a/tests/tests_integration/test_filesystem_transfer.py +++ b/tests/tests_integration/test_filesystem_transfer.py @@ -318,7 +318,7 @@ def test_transfer_with_keyword_parameters( (base_local / "rawdata" / sub / "ses*").as_posix() ) - datetime_regexp = r"date-\d\d\d\d\d\d\d\d_time-\d\d\d\d\d\d" + datetime_regexp = "datetime-\d{8}T\d{6}" assert re.match( "ses-001_" + datetime_regexp, sessions_in_path[0] diff --git a/tests/tests_integration/test_make_folders.py b/tests/tests_integration/test_make_folders.py index e3c37a26..9247adce 100644 --- a/tests/tests_integration/test_make_folders.py +++ b/tests/tests_integration/test_make_folders.py @@ -317,8 +317,8 @@ def test_datetime_flag_in_session(self, project): ) # Convert the minutes to regexp as could change during test runtime - regexp_time = r"\d\d\d\d\d\d" - datetime_regexp = f"{date}_time-{regexp_time}" + regexp_time = r"\d{6}" + datetime_regexp = f"datetime-{date}T{regexp_time}" assert all([re.search(datetime_regexp, name) for name in ses_names]) assert all([tags("time") not in name for name in ses_names]) diff --git a/tests/tests_unit/test_unit.py b/tests/tests_unit/test_unit.py index 25f5288e..dd9fe5a3 100644 --- a/tests/tests_unit/test_unit.py +++ b/tests/tests_unit/test_unit.py @@ -23,6 +23,8 @@ def test_datetime_string_replacement(self, key, underscore_position): keywords with the date / time / datetime. Also, it will pre/append underscores to the tags if they are not already there (e.g if user input "sub-001@DATE"). + Note cannot use regex \d{8} format because we are in an + f-string. """ start = "sub-001" end = "other-tag" @@ -34,13 +36,15 @@ def test_datetime_string_replacement(self, key, underscore_position): regex = re.compile(rf"{start}_time-\d\d\d\d\d\d_{end}") elif key == tags("datetime"): regex = re.compile( - rf"{start}_date-\d\d\d\d\d\d\d\d_time-\d\d\d\d\d\d_{end}" + rf"{start}_datetime-\d\d\d\d\d\d\d\dT\d\d\d\d\d\d_{end}" ) name_list = [name] formatting.update_names_with_datetime(name_list) - assert re.search(regex, name_list[0]) is not None + assert ( + re.search(regex, name_list[0]) is not None + ), "datetime formatting is incorrect." @pytest.mark.parametrize( "prefix_and_names",