From 5fb83975649cae85231a02f6cd2275bed46b300e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 5 Aug 2024 00:41:12 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- organize/actions/common/conflict.py | 10 ++++++---- tests/actions/test_copy.py | 4 +++- tests/actions/test_move.py | 4 +++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/organize/actions/common/conflict.py b/organize/actions/common/conflict.py index ac8225c8..efca88ce 100644 --- a/organize/actions/common/conflict.py +++ b/organize/actions/common/conflict.py @@ -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 @@ -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): @@ -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( diff --git a/tests/actions/test_copy.py b/tests/actions/test_copy.py index 7ca9fd1c..3b38ac35 100644 --- a/tests/actions/test_copy.py +++ b/tests/actions/test_copy.py @@ -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", @@ -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": { @@ -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: diff --git a/tests/actions/test_move.py b/tests/actions/test_move.py index 691ac77d..fbacc035 100644 --- a/tests/actions/test_move.py +++ b/tests/actions/test_move.py @@ -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", @@ -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", @@ -91,6 +92,7 @@ def test_move_deduplicate_conflict(fs): "dst 2.txt": "src2", } + def test_move_folder_conflict(fs): make_files( {