From 7b9ba8634c0a02cb4c82313d9bef3197640c3187 Mon Sep 17 00:00:00 2001 From: Billy Su Date: Thu, 5 Apr 2018 11:13:09 +0800 Subject: [PATCH] Add test_setData() for PlotDataItem class --- .../graphicsItems/tests/test_PlotDataItem.py | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/pyqtgraph/graphicsItems/tests/test_PlotDataItem.py b/pyqtgraph/graphicsItems/tests/test_PlotDataItem.py index dc13bb7a..9a13c0b6 100644 --- a/pyqtgraph/graphicsItems/tests/test_PlotDataItem.py +++ b/pyqtgraph/graphicsItems/tests/test_PlotDataItem.py @@ -22,4 +22,30 @@ def test_fft(): pd.setLogMode(True, False) x, y = pd.getData() assert abs(x[np.argmax(y)] - np.log10(f)) < 0.01 - \ No newline at end of file + +def test_setData(): + pdi = pg.PlotDataItem() + + #test empty data + pdi.setData([]) + + #test y data + y = list(np.random.normal(size=100)) + pdi.setData(y) + assert len(pdi.xData) == 100 + assert len(pdi.yData) == 100 + + #test x, y data + y += list(np.random.normal(size=50)) + x = np.linspace(5, 10, 150) + + pdi.setData(x, y) + assert len(pdi.xData) == 150 + assert len(pdi.yData) == 150 + + #test dict of x, y list + y += list(np.random.normal(size=50)) + x = list(np.linspace(5, 10, 200)) + pdi.setData({'x': x, 'y': y}) + assert len(pdi.xData) == 200 + assert len(pdi.yData) == 200