Skip to content

Commit

Permalink
fixed bug in add_suffix and added test
Browse files Browse the repository at this point in the history
  • Loading branch information
h21ak9 committed May 29, 2024
1 parent 790715c commit 75c7a83
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
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
15 changes: 15 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 @@ -19,6 +20,20 @@
else:
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":
Expand Down

0 comments on commit 75c7a83

Please sign in to comment.