| 1 |
"""WatchStatus + render_status format stability.""" |
| 2 |
|
| 3 |
from __future__ import annotations |
| 4 |
|
| 5 |
from dlm.watch.status import WatchState, WatchStatus, render_status |
| 6 |
|
| 7 |
|
| 8 |
class TestRenderStatus: |
| 9 |
def test_initial_state_shows_idle(self) -> None: |
| 10 |
status = WatchStatus(doc_path="mydoc.dlm", sections=12) |
| 11 |
line = render_status(status, now=0.0) |
| 12 |
assert "Watching mydoc.dlm" in line |
| 13 |
assert "state: idle" in line |
| 14 |
assert "sections: 12" in line |
| 15 |
assert "last train: never" in line |
| 16 |
|
| 17 |
def test_after_cycle_shows_loss_and_steps(self) -> None: |
| 18 |
status = WatchStatus(doc_path="mydoc.dlm", sections=12) |
| 19 |
status.mark_cycle_done(train_loss=1.2, val_loss=1.35, steps=50, coalesced=1) |
| 20 |
line = render_status(status) |
| 21 |
assert "val loss: 1.35" in line |
| 22 |
assert "steps: 50" in line |
| 23 |
|
| 24 |
def test_coalesced_only_shown_when_plural(self) -> None: |
| 25 |
status = WatchStatus(doc_path="d") |
| 26 |
status.mark_cycle_done(train_loss=None, val_loss=None, steps=10, coalesced=1) |
| 27 |
assert "coalesced" not in render_status(status) |
| 28 |
|
| 29 |
status.mark_cycle_done(train_loss=None, val_loss=None, steps=10, coalesced=5) |
| 30 |
assert "coalesced: 5" in render_status(status) |
| 31 |
|
| 32 |
def test_age_buckets(self) -> None: |
| 33 |
status = WatchStatus(doc_path="d") |
| 34 |
status.last_cycle_at = 0.0 |
| 35 |
assert "12s ago" in render_status(status, now=12.0) |
| 36 |
assert "2m ago" in render_status(status, now=125.0) |
| 37 |
assert "1h ago" in render_status(status, now=3700.0) |
| 38 |
|
| 39 |
|
| 40 |
class TestWatchState: |
| 41 |
def test_enum_values(self) -> None: |
| 42 |
assert WatchState.IDLE.value == "idle" |
| 43 |
assert WatchState.TRAINING.value == "training" |
| 44 |
assert WatchState.CANCELLED.value == "cancelled" |