Skip to content

Commit

Permalink
Merge pull request #30 from sgibson91/filename-length-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sgibson91 authored Feb 26, 2022
2 parents a6394da + 14a6ca1 commit 83ac512
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion deduplify/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

from incremental import Version

__version__ = Version("deduplify", 0, 1, 4)
__version__ = Version("deduplify", 0, 1, 5)
__all__ = ["__version__"]
5 changes: 5 additions & 0 deletions deduplify/compare_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ def compare_filenames(file_list: list) -> str:
if len(name_freq) == 1:
file_list.remove(min(file_list, key=len))
return file_list
elif (len(name_freq) > 1) and (list(set(file_list)) == 1):
# there are multiple filepaths that are different,
# but by coincidence have the same length
file_list = file_list.sort()
file_list.remove(file_list[1:])
else:
raise ValueError(
f"The following filenames need investigation.\n{name_freq}\n{file_list}"
Expand Down
12 changes: 12 additions & 0 deletions tests/test_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ def test_compare_filenames():
assert out_file_list == ["different/path/to/test/file.txt"]


def test_compare_filenames_same_length():
test_file_list = [
"path/to/test/file.txt",
"diff/xy/path/file.txt",
]

out_file_list = compare_filenames(test_file_list)

assert len(out_file_list) == 1
assert out_file_list == ["path/to/test/file.txt"]


@patch("deduplify.compare_files.os.remove")
def test_delete_files(mock):
test_files = ["path/to/file_1.txt", "path/to/file_2.txt"]
Expand Down

0 comments on commit 83ac512

Please sign in to comment.