Rename NumberLineEdit.validator to range_validator: the instance attr shadowed QLineEdit.validator() and broke type checking at call sites. Annotate the smargon _move_axes dict and cast the stand-in self in the prediction subscriber test. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
28 lines
893 B
Python
28 lines
893 B
Python
"""Checks the binary-frame sniff in _try_parse_json: JPEG frames (0xff lead
|
|
byte) must be rejected without attempting utf-8 decode (previously raised
|
|
UnicodeDecodeError on every frame)."""
|
|
|
|
from typing import cast
|
|
|
|
from aare.gui.threads.prediction_subscriber import PredictionSubscriber
|
|
|
|
|
|
def _parse(part: bytes):
|
|
# Called unbound: _try_parse_json touches no instance state, so no
|
|
# QThread/zmq construction is needed. cast keeps basedpyright happy
|
|
# about the stand-in self.
|
|
return PredictionSubscriber._try_parse_json(cast(PredictionSubscriber, object()), part)
|
|
|
|
|
|
def test_binary_jpeg_frame_is_not_json():
|
|
assert _parse(b"\xff\xd8\xff\xe0somejpegbytes") is None
|
|
|
|
|
|
def test_json_dict_is_parsed():
|
|
assert _parse(b'{"encoding": "jpeg"}') == {"encoding": "jpeg"}
|
|
|
|
|
|
def test_json_non_dict_is_rejected():
|
|
assert _parse(b"[1, 2]") is None
|
|
assert _parse(b"") is None
|