File size: 1,122 Bytes
784f572 | 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 32 33 34 35 36 37 38 39 40 41 42 43 44 | import pytest
from dlb.io import atomic_json_write, sha256_file
from dlb.schema import SampleRecord
def test_sample_record_rejects_empty_text():
with pytest.raises(ValueError):
SampleRecord(
sample_id=0,
text="",
token_ids=[1],
seed=42,
generation_seconds=0.1,
)
def test_sample_record_rejects_negative_generation_time():
with pytest.raises(ValueError):
SampleRecord(
sample_id=0,
text="generated text",
token_ids=[1],
seed=42,
generation_seconds=-0.1,
)
def test_atomic_json_write_replaces_file_with_deterministic_json(tmp_path):
target = tmp_path / "nested" / "record.json"
atomic_json_write(target, {"z": 1, "a": [2]})
assert target.read_text() == '{\n "a": [\n 2\n ],\n "z": 1\n}\n'
def test_sha256_file_streams_known_content_digest(tmp_path):
target = tmp_path / "asset.bin"
target.write_bytes(b"abc")
assert sha256_file(target) == (
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
)
|