Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Aug 5, 2024
1 parent 6eb29e9 commit 5fb8397
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
10 changes: 6 additions & 4 deletions organize/actions/common/conflict.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import annotations

import filecmp
from pathlib import Path
from typing import TYPE_CHECKING, Literal, NamedTuple
import filecmp

from organize.output import Output
from organize.resource import Resource
Expand All @@ -12,7 +12,9 @@
from jinja2 import Template

# TODO: keep_newer, keep_older, keep_bigger, keep_smaller
ConflictMode = Literal["skip", "overwrite", "deduplicate", "trash", "rename_new", "rename_existing"]
ConflictMode = Literal[
"skip", "overwrite", "deduplicate", "trash", "rename_new", "rename_existing"
]


class ConflictResult(NamedTuple):
Expand Down Expand Up @@ -104,10 +106,10 @@ def _print(msg: str):

delete(path=dst)
return ConflictResult(skip_action=False, use_dst=dst)

elif conflict_mode == "deduplicate":
if filecmp.cmp(res.path, dst, shallow=True):
_print(f"Duplicate skipped.")
_print("Duplicate skipped.")
return ConflictResult(skip_action=True, use_dst=res.path)
else:
new_path = next_free_name(
Expand Down
4 changes: 3 additions & 1 deletion tests/actions/test_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def test_copy_conflict(fs, mode, result):
Config.from_string(config).execute(simulate=False)
assert read_files("test") == result


def test_copy_deduplicate_conflict(fs):
files = {
"src.txt": "src",
Expand All @@ -162,7 +163,7 @@ def test_copy_deduplicate_conflict(fs):

Config.from_string(config).execute(simulate=False)
result = read_files("test")

assert result == {
"src.txt": "src",
"duplicate": {
Expand All @@ -175,6 +176,7 @@ def test_copy_deduplicate_conflict(fs):
"dst 2.txt": "src2",
}


def test_does_not_create_folder_in_simulation(fs):
config = """
rules:
Expand Down
4 changes: 3 additions & 1 deletion tests/actions/test_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def test_move_conflict(fs, mode, result):
Config.from_string(config).execute(simulate=False)
assert read_files("test") == result


def test_move_deduplicate_conflict(fs):
files = {
"src.txt": "src",
Expand All @@ -81,7 +82,7 @@ def test_move_deduplicate_conflict(fs):

Config.from_string(config).execute(simulate=False)
result = read_files("test")

assert result == {
"duplicate": {
"src.txt": "src",
Expand All @@ -91,6 +92,7 @@ def test_move_deduplicate_conflict(fs):
"dst 2.txt": "src2",
}


def test_move_folder_conflict(fs):
make_files(
{
Expand Down

0 comments on commit 5fb8397

Please sign in to comment.