mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-12 11:11:04 +01:00
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (mypy, mypy) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (pylint, pylint) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (rest, ) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (shellcheck, shellcheck) (push) Waiting to run
Python tests / test (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / lib-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
Kept videos land in ~/data/cloud/Media/<year>/wsg (~/Downloads without the cloud folder); trash/ keeps only the newest 200 passes and marks the rest purged. Legacy keep/ is migrated once. Undo follows a keep through every place it can end up. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F8G3BNETGmbr6aM5cc18g4
93 lines
2.4 KiB
Python
93 lines
2.4 KiB
Python
"""Tests for the around-a-verdict chores and for undo finding moved keeps."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from typing import TYPE_CHECKING
|
|
|
|
import pytest
|
|
|
|
from python_pkg.wsg_grabber import housekeeping, paths
|
|
from python_pkg.wsg_grabber.models import Verdict
|
|
from python_pkg.wsg_grabber.tests.conftest import item, reviewed
|
|
|
|
if TYPE_CHECKING:
|
|
from collections.abc import Callable
|
|
|
|
|
|
@pytest.fixture
|
|
def prune_calls(monkeypatch: pytest.MonkeyPatch) -> list[object]:
|
|
"""Replace the prune with a recorder.
|
|
|
|
Args:
|
|
monkeypatch: Patching helper.
|
|
|
|
Returns:
|
|
list[object]: One entry per prune call.
|
|
"""
|
|
calls: list[object] = []
|
|
monkeypatch.setattr(
|
|
housekeeping,
|
|
"prune_trash",
|
|
calls.append,
|
|
)
|
|
return calls
|
|
|
|
|
|
def test_startup_migrates_then_prunes(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
prune_calls: list[object],
|
|
) -> None:
|
|
order: list[str] = []
|
|
monkeypatch.setattr(
|
|
housekeeping,
|
|
"migrate_keep",
|
|
lambda _conn: order.append("migrate"),
|
|
)
|
|
housekeeping.on_startup("conn")
|
|
assert order == ["migrate"]
|
|
assert prune_calls == ["conn"]
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("choice", "expected"),
|
|
[(Verdict.SKIP, ["conn"]), (Verdict.KEEP, [])],
|
|
)
|
|
def test_only_a_pass_triggers_a_prune(
|
|
prune_calls: list[object],
|
|
choice: Verdict,
|
|
expected: list[object],
|
|
) -> None:
|
|
housekeeping.after_verdict("conn", choice)
|
|
assert prune_calls == expected
|
|
|
|
|
|
def test_a_pass_is_located_in_trash() -> None:
|
|
action = reviewed(item(), Verdict.SKIP)
|
|
assert housekeeping.locate_reviewed(action) == paths.trash_dir() / "a.webm"
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"place",
|
|
[
|
|
paths.keep_dir,
|
|
lambda: paths.cloud_keep_dir(2001),
|
|
paths.legacy_keep_dir,
|
|
paths.downloads_dir,
|
|
lambda: paths.cloud_root() / "Media" / "2001" / "03",
|
|
],
|
|
)
|
|
def test_a_keep_is_found_wherever_it_ended_up(place: Callable[[], Path]) -> None:
|
|
paths.cloud_root().mkdir(parents=True)
|
|
directory = place()
|
|
directory.mkdir(parents=True, exist_ok=True)
|
|
(directory / "a.webm").write_bytes(b"v")
|
|
|
|
action = reviewed(item(), Verdict.KEEP)
|
|
assert housekeeping.locate_reviewed(action) == directory / "a.webm"
|
|
|
|
|
|
def test_a_keep_that_is_nowhere_points_at_the_current_keep_dir() -> None:
|
|
action = reviewed(item(), Verdict.KEEP)
|
|
assert housekeeping.locate_reviewed(action) == paths.keep_dir() / "a.webm"
|