mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-10-04 06:15:09 +00:00
perf: cheap per-frame and per-fetch savings (#725)
Six small savings with no behaviour change: the odds fetch no longer pretty-prints every response for a debug line; the scroll integer-slice path drops a redundant full-frame np.ascontiguousarray; ledmatrix-web.service gets MALLOC_ARENA_MAX=2 like the display unit; core ESPN responses are parsed via response_json (orjson when installed); and the scroll frame stats go to INFO only for degraded windows plus a 5-minute heartbeat. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -116,3 +116,24 @@ def test_response_json_prefers_orjson_and_falls_back():
|
||||
assert json_body.response_json(response) == payload
|
||||
# A response object without bytes content (a test double) still works.
|
||||
assert json_body.response_json(SimpleNamespace(json=lambda: payload)) == payload
|
||||
|
||||
|
||||
@pytest.mark.parametrize("body", [b"not json", b"", b'{"a": NaN}', b"\xef\xbb\xbf{}"])
|
||||
def test_response_json_raises_and_returns_what_requests_does(body):
|
||||
# The core fetch paths (api_helper, base_odds_manager, logo_downloader,
|
||||
# dynamic_team_resolver) catch requests' JSONDecodeError on a bad body, so
|
||||
# response_json must raise exactly that, and parse whatever requests
|
||||
# parses (NaN, which orjson rejects) to the same value.
|
||||
import requests
|
||||
|
||||
response = requests.models.Response()
|
||||
response._content = body
|
||||
response.status_code = 200
|
||||
response.headers["Content-Type"] = "application/json"
|
||||
try:
|
||||
expected = response.json()
|
||||
except requests.exceptions.JSONDecodeError:
|
||||
with pytest.raises(requests.exceptions.JSONDecodeError):
|
||||
json_body.response_json(response)
|
||||
else:
|
||||
assert json.dumps(json_body.response_json(response)) == json.dumps(expected)
|
||||
|
||||
Reference in New Issue
Block a user