diff --git a/pyqtgraph/graphicsItems/tests/test_PlotDataItem.py b/pyqtgraph/graphicsItems/tests/test_PlotDataItem.py index dc13bb7a..8851a0a2 100644 --- a/pyqtgraph/graphicsItems/tests/test_PlotDataItem.py +++ b/pyqtgraph/graphicsItems/tests/test_PlotDataItem.py @@ -22,4 +22,39 @@ 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 + +def test_clear(): + y = list(np.random.normal(size=100)) + x = np.linspace(5, 10, 100) + pdi = pg.PlotDataItem(x, y) + pdi.clear() + + assert pdi.xData == None + assert pdi.yData == None