import json import sys from pathlib import Path COMPRESSORS_DIR = Path(__file__).resolve().parents[1] / "mini-nav" / "compressors" sys.path.insert(0, str(COMPRESSORS_DIR)) from training_metrics import write_training_metrics # noqa: E402 def test_write_training_metrics_appends_jsonl_rows(tmp_path): metrics_path = tmp_path / "hash_training_metrics.jsonl" write_training_metrics( metrics_path, epoch=2, step=17, lr=1e-4, components={ "total": 1.25, "contrastive": 0.75, "distill": 0.4, "quantization": 0.1, }, ) write_training_metrics( metrics_path, epoch=2, step=18, lr=1e-4, components={ "total": 1.0, "contrastive": 0.6, "distill": 0.3, "quantization": 0.1, }, ) rows = [json.loads(line) for line in metrics_path.read_text().splitlines()] assert rows == [ { "epoch": 2, "step": 17, "lr": 1e-4, "total": 1.25, "contrastive": 0.75, "distill": 0.4, "quantization": 0.1, }, { "epoch": 2, "step": 18, "lr": 1e-4, "total": 1.0, "contrastive": 0.6, "distill": 0.3, "quantization": 0.1, }, ]