Files
StashHandler/tests/test_stash_handler.py
bvandeusen 31217498ce
CI / lint (push) Successful in 3s
CI / unit (push) Successful in 4s
CI / publish (push) Successful in 13s
Add Forgejo CI: ruff lint + pytest unit + gated image publish
Family-consistent CI for StashHandler (mirrors the NhenArchiver Python
sibling, minus the integration lane — StashHandler is SQLite-only with no
service containers).

- .forgejo/workflows/ci.yml: lint (ruff) -> unit (pytest) -> publish.
  publish builds + pushes git.fabledsword.com/bvandeusen/stashhandler with
  the family rule-46 tag scheme (dev->:dev+:c-<sha>, main->:latest+:c-<sha>,
  v* tag->:<version>+:latest). Gated on lint+unit. Needs REGISTRY_TOKEN.
- tests/: starter unit suite — hashing, SQLite dedup, media filter, transfer
  modes.
- pyproject.toml: ruff target + pytest pythonpath/testpaths.
- ci-requirements.md (family rule 39), .dockerignore.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016nyYC9dTQ78SqhpNFtpMvT
2026-06-26 10:44:49 -04:00

48 lines
1.4 KiB
Python

from pathlib import Path
import stash_handler
EXTS = {".mp4", ".mkv"}
def test_is_media_is_case_insensitive():
assert stash_handler.is_media(Path("a.mp4"), EXTS)
assert stash_handler.is_media(Path("A.MKV"), EXTS)
assert not stash_handler.is_media(Path("notes.txt"), EXTS)
def test_walk_media_recurses_and_filters(tmp_path):
(tmp_path / "sub").mkdir()
(tmp_path / "a.mp4").write_bytes(b"x")
(tmp_path / "sub" / "b.mkv").write_bytes(b"x")
(tmp_path / "c.txt").write_bytes(b"x")
found = {p.name for p in stash_handler.walk_media(tmp_path, EXTS)}
assert found == {"a.mp4", "b.mkv"}
def test_transfer_copy_preserves_original(tmp_path):
src = tmp_path / "src.mp4"
src.write_bytes(b"data")
dst = tmp_path / "out" / "src.mp4"
stash_handler.transfer_file(src, dst, "copy")
assert dst.read_bytes() == b"data"
assert src.exists() # seeding can continue
def test_transfer_hardlink_preserves_original(tmp_path):
src = tmp_path / "src.mp4"
src.write_bytes(b"data")
dst = tmp_path / "out" / "src.mp4"
stash_handler.transfer_file(src, dst, "hardlink")
assert dst.read_bytes() == b"data"
assert src.exists()
def test_transfer_move_removes_original(tmp_path):
src = tmp_path / "src.mp4"
src.write_bytes(b"data")
dst = tmp_path / "out" / "src.mp4"
stash_handler.transfer_file(src, dst, "move")
assert dst.read_bytes() == b"data"
assert not src.exists()