Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed bug in add_suffix and added test #2921

Merged
merged 2 commits into from
May 30, 2024
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 src/spikeinterface/core/core_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def add_suffix(file_path, possible_suffix):
possible_suffix = [possible_suffix]
possible_suffix = [s if s.startswith(".") else "." + s for s in possible_suffix]
if file_path.suffix not in possible_suffix:
file_path = file_path.parent / (file_path.name + "." + possible_suffix[0])
file_path = file_path.parent / (file_path.name + possible_suffix[0])
return file_path


Expand Down
17 changes: 17 additions & 0 deletions src/spikeinterface/core/tests/test_core_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
check_paths_relative,
normal_pdf,
convert_string_to_bytes,
add_suffix,
)


Expand All @@ -20,6 +21,22 @@
cache_folder = Path("cache_folder") / "core"


def test_add_suffix():
# first case - no dot provided before extension
file_path = "testpath"
possible_suffix = ["raw", "bin", "path"]
file_path_with_suffix = add_suffix(file_path, possible_suffix)
expected_path = "testpath.raw"
assert str(file_path_with_suffix) == expected_path

# second case - dot provided before extension
file_path = "testpath"
possible_suffix = [".raw", ".bin", ".path"]
file_path_with_suffix = add_suffix(file_path, possible_suffix)
expected_path = "testpath.raw"
assert str(file_path_with_suffix) == expected_path


def test_path_utils_functions():
if platform.system() != "Windows":
# posix path
Expand Down
Loading