Commit 1c86fb6b authored by Valentin Valls's avatar Valentin Valls
Browse files

Create tests for time curve plot

parent e9804b73
......@@ -235,3 +235,37 @@ def test_curve_stack(flint_session):
p.clear_data()
vrange = p.get_data_range()
assert vrange == [None, None]
def test_time_curve_plot(flint_session):
"""Coverage of the main time curve plot API"""
f = plot.get_flint()
p = f.get_plot(plot_class="timecurveplot", name="timecurveplot")
p.select_time_curve("diode1")
p.select_time_curve("diode2")
# set_data update the curves
p.set_data(time=[0, 1, 2], diode1=[0, 1, 1], diode2=[1, 5, 1])
vrange = p.get_data_range()
assert vrange[0] == [0, 2]
assert vrange[1] == [0, 5]
# append data update the data on the right side
p.append_data(time=[3], diode1=[2], diode2=[6])
vrange = p.get_data_range()
assert vrange[0] == [0, 3]
assert vrange[1] == [0, 6]
# when a fixed duration is used, the data disappear on one side
p.select_x_duration(second=5)
p.append_data(time=[10], diode1=[2], diode2=[6])
vrange = p.get_data_range()
assert vrange[0][0] > 1
assert vrange[0][1] == 10
# clean data clean up the plot
p.clear_data()
vrange = p.get_data_range()
assert vrange == [None, None]
"""Testing time curve plot."""
import pytest
from silx.gui import qt
from bliss.flint.custom_plots import time_curve_plot
@pytest.fixture(scope="function")
def time_curve_plot_widget(local_flint):
w = time_curve_plot.TimeCurvePlot()
w.setAttribute(qt.Qt.WA_DeleteOnClose)
w.setVisible(True)
yield w
w.close()
def test_time_curve_plot__creation(time_curve_plot_widget):
"""The widget can be implemented"""
pass
def test_time_curve_plot__set_data(time_curve_plot_widget):
"""The setData of the widget can be used
We expect curves to be displayed
"""
w = time_curve_plot_widget
w.selectCurve("value1")
w.selectCurve("value2")
w.setData(
time=[0, 1, 2, 3, 4, 5], value1=[0, 1, 2, 3, 4, 5], value2=[0, 1, 2, 3, 4, 5]
)
plot = w.getPlotWidget()
assert len(plot.getAllCurves()) == 2
def test_time_curve_plot__clear(time_curve_plot_widget):
"""Feed a plot and call `clear`
We expect no curves to be displayed
"""
w = time_curve_plot_widget
w.selectCurve("value1")
w.selectCurve("value2")
w.setData(
time=[0, 1, 2, 3, 4, 5], value1=[0, 1, 2, 3, 4, 5], value2=[0, 1, 2, 3, 4, 5]
)
w.clear()
plot = w.getPlotWidget()
assert len(plot.getAllCurves()) == 0
def test_time_curve_plot__append_data(time_curve_plot_widget):
"""Create a plot and feed data with `appendData`
We expect the plot to contains curves witch grow up.
"""
w = time_curve_plot_widget
w.selectCurve("value1")
w.selectCurve("value2")
w.appendData(time=[0, 1, 2], value1=[0, 1, 2], value2=[0, 1, 2])
plot = w.getPlotWidget()
curve = plot.getAllCurves()[0]
assert len(curve.getXData()) == 3
w.appendData(time=[3, 4, 5], value1=[0, 1, 2], value2=[0, 1, 2])
curve = plot.getAllCurves()[0]
assert len(curve.getXData()) == 6
def test_time_curve_plot__drop_data(time_curve_plot_widget):
"""Create a plot with limited life time data duration and feed it with data
We expect the plot to contain curves witch grow up on one side, and disappear
on the other side.
"""
w = time_curve_plot_widget
w.setXDuration(5)
w.selectCurve("value1")
w.selectCurve("value2")
w.appendData(time=[0, 1, 2], value1=[0, 1, 2], value2=[0, 1, 2])
w.appendData(time=[3, 4, 5], value1=[0, 1, 2], value2=[0, 1, 2])
w.appendData(time=[6, 7, 8], value1=[0, 1, 2], value2=[0, 1, 2])
plot = w.getPlotWidget()
curve = plot.getAllCurves()[0]
assert len(curve.getXData()) <= 5 + 2
assert curve.getXData()[0] > 0
assert curve.getXData()[-1] == 8
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment