Files
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

43 lines
1.2 KiB
Python

import builtins
import hashlib
import pytest
from hasher import hash_file
def test_sha256_matches_hashlib(tmp_path):
p = tmp_path / "f.bin"
# Larger than the 64KB read chunk so the streaming loop iterates.
data = b"hello world\n" * 10000
p.write_bytes(data)
assert hash_file(p, "sha256") == hashlib.sha256(data).hexdigest()
def test_default_algorithm_is_sha256(tmp_path):
p = tmp_path / "f.bin"
p.write_bytes(b"abc")
assert hash_file(p) == hashlib.sha256(b"abc").hexdigest()
def test_blake3_produces_expected_digest(tmp_path):
blake3 = pytest.importorskip("blake3")
p = tmp_path / "f.bin"
p.write_bytes(b"abc")
assert hash_file(p, "blake3") == blake3.blake3(b"abc").hexdigest()
def test_blake3_missing_raises_importerror(tmp_path, monkeypatch):
p = tmp_path / "f.bin"
p.write_bytes(b"abc")
real_import = builtins.__import__
def fake_import(name, *args, **kwargs):
if name == "blake3":
raise ImportError("simulated missing blake3")
return real_import(name, *args, **kwargs)
monkeypatch.setattr(builtins, "__import__", fake_import)
with pytest.raises(ImportError):
hash_file(p, "blake3")