kopia lustrzana https://github.com/corrscope/corrscope
Ensure CustomLine.xdata is always ndarray
rodzic
8fb107fec1
commit
40ccba0f72
|
@ -215,7 +215,16 @@ UpdateOneLine = Callable[[np.ndarray], Any]
|
|||
@attr.dataclass
|
||||
class CustomLine:
|
||||
stride: int
|
||||
xdata: np.ndarray
|
||||
_xdata: np.ndarray = attr.ib(converter=np.array)
|
||||
|
||||
@property
|
||||
def xdata(self) -> np.ndarray:
|
||||
return self._xdata
|
||||
|
||||
@xdata.setter
|
||||
def xdata(self, value):
|
||||
self._xdata = np.array(value)
|
||||
|
||||
set_xdata: UpdateOneLine
|
||||
set_ydata: UpdateOneLine
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ from corrscope.renderer import (
|
|||
calc_center,
|
||||
AbstractMatplotlibRenderer,
|
||||
RendererFrontend,
|
||||
CustomLine,
|
||||
)
|
||||
from corrscope.util import perr
|
||||
from corrscope.wave import Flatten
|
||||
|
@ -508,3 +509,19 @@ def test_frontend_overrides_backend(mocker: "pytest_mock.MockFixture"):
|
|||
|
||||
assert frontend_get_frame.call_count == 1
|
||||
assert backend_get_frame.call_count == 1
|
||||
|
||||
|
||||
def test_custom_line():
|
||||
def verify(line: CustomLine, xdata: list):
|
||||
line_xdata = line.xdata
|
||||
assert isinstance(line_xdata, np.ndarray)
|
||||
assert line_xdata.tolist() == xdata
|
||||
|
||||
stride = 1
|
||||
noop = lambda x: None
|
||||
|
||||
line = CustomLine(stride, [3], noop, noop)
|
||||
verify(line, [3])
|
||||
|
||||
line.xdata = [4, 4]
|
||||
verify(line, [4, 4])
|
||||
|
|
Ładowanie…
Reference in New Issue