File size: 925 Bytes
3a2e5f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""Tests for ``captioning.utils.hashing.sha256_file``."""

from __future__ import annotations

import hashlib
from pathlib import Path

from captioning.utils.hashing import sha256_file


def test_matches_oneshot_hash(tmp_path: Path) -> None:
    """Streaming SHA-256 must equal the one-shot SHA-256."""
    p = tmp_path / "blob.bin"
    payload = b"hello world\n" * 1000
    p.write_bytes(payload)
    assert sha256_file(p) == hashlib.sha256(payload).hexdigest()


def test_handles_empty_file(tmp_path: Path) -> None:
    p = tmp_path / "empty.bin"
    p.touch()
    assert sha256_file(p) == hashlib.sha256(b"").hexdigest()


def test_handles_large_file(tmp_path: Path) -> None:
    """Larger than the internal 64 KB chunk to exercise the streaming path."""
    p = tmp_path / "large.bin"
    payload = b"x" * (256 * 1024)  # 256 KB
    p.write_bytes(payload)
    assert sha256_file(p) == hashlib.sha256(payload).hexdigest()