fly-trader distribution: code, fly #62, selector #59, connectome, seed (branch distribution @ 5cb1652)
0f038be verified Download tests/test_guards.py from bryceweiner/fly-trader: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/bryceweiner/fly-trader/resolve/main/tests/test_guards.py
- Command line
-
hf download hf://bryceweiner/fly-trader/tests/test_guards.py
-
curl -L -o test_guards.py https://huggingface.co/bryceweiner/fly-trader/resolve/main/tests/test_guards.py
1.31 kB
| """Small guards found by the review: finite JSON for status/events, worker-thread log routing.""" | |
| import logging | |
| import math | |
| import threading | |
| from fly_trader.db import apilog | |
| from fly_trader.logging_setup import _ThreadFilter | |
| from fly_trader.train import progress | |
| def test_finite_json_guards(): | |
| x = {"a": float("inf"), "b": [1.0, float("nan"), {"c": -math.inf}], "d": 2.5} | |
| assert progress._finite(x) == {"a": None, "b": [1.0, None, {"c": None}], "d": 2.5} | |
| assert apilog._finite(x) == progress._finite(x) | |
| def test_thread_filter_routes_helper_threads(): | |
| got = [] | |
| def _in_worker(): | |
| f = _ThreadFilter("replay") | |
| for tn in ("replay", "replay-dl-0", "replay-assemble", "corpus", "MainThread"): | |
| rec = logging.LogRecord("x", logging.INFO, "", 0, "m", (), None); rec.threadName = tn | |
| got.append((tn, f.filter(rec))) | |
| t = threading.Thread(target=_in_worker, name="replay"); t.start(); t.join() | |
| assert dict(got) == {"replay": True, "replay-dl-0": True, "replay-assemble": True, "corpus": False, "MainThread": False} | |
| f = _ThreadFilter("capture") # created on the main thread (CLI use): MainThread records pass | |
| rec = logging.LogRecord("x", logging.INFO, "", 0, "m", (), None); rec.threadName = "MainThread" | |
| assert f.filter(rec) is True | |