Newer
Older
import pytest
from qtpy import QtCore
try:
from b_asic.gui_utils.plot_window import PlotWindow
except ImportError:
pytestmark = pytest.mark.skip("Qt not setup")
def test_start(qtbot):
widget = PlotWindow({})
qtbot.addWidget(widget)
def test_start_with_data(qtbot):
sim_res = {
'0': [0.5, 0.5, 0, 0],
'add1': [0.5, 0.5, 0, 0],
'cmul1': [0, 0.5, 0, 0],
'cmul2': [0.5, 0, 0, 0],
'in1': [1, 0, 0, 0],
't1': [0, 1, 0, 0],
}
widget = PlotWindow(sim_res)
qtbot.addWidget(widget)
assert widget._checklist.count() == 6
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def test_start_with_complex_data(qtbot):
sim_res = {
'0': [0.5, 0.5, 0, 0],
'1': [0.5, 0.5 + 0.4j, 1, 0],
'add1': [0.5, 0.5, 0, 0],
'cmul1': [0, 0.5, 0, 0],
'cmul2': [0.5, 0, 0, 0],
'in1': [1, 0, 0, 0],
't1': [0, 1, 0, 0],
}
widget = PlotWindow(sim_res)
qtbot.addWidget(widget)
assert widget._checklist.count() == 10
assert len(widget._plot_axes.lines) == 3
def test_start_with_multi_data(qtbot):
sim_res1 = {
'0': [1.5, 1.6, 1.5, 1],
'1': [1.0, 2.0, 1.5, 1.1],
'add1': [1.5, 1.5, 1, 1],
'cmul1': [1, 1.5, 1, 1],
'in1': [2, 1, 1, 1],
't3': [1, 1, 1, 2],
}
sim_res2 = {
'1': [
0.0,
1.0 + 0.3j,
0.5,
0.1j,
], # Each complex generates four signals, whereof two are shown (for outs).
'add1': [0.5, 0.5, 0, 0],
'cmul1': [0, 0.5, 0, 0],
'cmul2': [0.5, 0, 0, 0],
'in1': [1, 0, 0, 0],
'in2': [0.1, 2, 0, 0],
}
sim_res3 = {
'1': [1, 2, 3, 4],
't4': [2, 3, 3, 2],
}
widget = PlotWindow(['simReal', sim_res1, 'simCpx', sim_res2], "Test vector")
qtbot.addWidget(widget)
assert widget._checklist.count() == 15
assert len(widget._plot_axes.lines) == 4
widget.add_result('foo', sim_res3)
assert widget._checklist.count() == 17
assert len(widget._plot_axes.lines) == 5
def test_click_buttons(qtbot):
sim_res = {
'0': [0.5, 0.5, 0, 0],
'add1': [0.5, 0.5, 0, 0],
'cmul1': [0, 0.5, 0, 0],
'cmul2': [0.5, 0, 0, 0],
'in1': [1, 0, 0, 0],
't1': [0, 1, 0, 0],
}
widget = PlotWindow(sim_res)
qtbot.addWidget(widget)
assert widget._checklist.count() == 6
assert len(widget._plot_axes.lines) == 1
qtbot.mouseClick(widget._button_all, QtCore.Qt.MouseButton.LeftButton)
assert len(widget._plot_axes.lines) == 6
qtbot.mouseClick(widget._button_none, QtCore.Qt.MouseButton.LeftButton)
assert len(widget._plot_axes.lines) == 0