Skip to content
Snippets Groups Projects
Commit 62ba2144 authored by Oscar Gustafsson's avatar Oscar Gustafsson :bicyclist:
Browse files

Test Simulation GUI

parent f87edabd
No related branches found
No related tags found
1 merge request!276Test Simulation GUI
Pipeline #93827 failed
...@@ -100,8 +100,14 @@ class PlotWindow(QDialog): ...@@ -100,8 +100,14 @@ class PlotWindow(QDialog):
self._plot_axes = self._plot_fig.add_subplot(111) self._plot_axes = self._plot_fig.add_subplot(111)
self._plot_axes.xaxis.set_major_locator(MaxNLocator(integer=True)) self._plot_axes.xaxis.set_major_locator(MaxNLocator(integer=True))
# Use | when dropping support for Python 3.8
ordered_for_plotting = {}
ordered_for_plotting.update(sim_res_others)
ordered_for_plotting.update(sim_res_delays)
ordered_for_plotting.update(sim_res_ins)
ordered_for_plotting.update(sim_res_outs)
self._lines = {} self._lines = {}
for key in sim_res_others | sim_res_delays | sim_res_ins | sim_res_outs: for key, result in ordered_for_plotting.items():
line = self._plot_axes.plot(sim_result[key], label=key) line = self._plot_axes.plot(sim_result[key], label=key)
self._lines[key] = line[0] self._lines[key] = line[0]
...@@ -114,12 +120,12 @@ class PlotWindow(QDialog): ...@@ -114,12 +120,12 @@ class PlotWindow(QDialog):
# Add two buttons for selecting all/none: # Add two buttons for selecting all/none:
hlayout = QHBoxLayout() hlayout = QHBoxLayout()
button_all = QPushButton("&All") self._button_all = QPushButton("&All")
button_all.clicked.connect(self._button_all_click) self._button_all.clicked.connect(self._button_all_click)
hlayout.addWidget(button_all) hlayout.addWidget(self._button_all)
button_none = QPushButton("&None") self._button_none = QPushButton("&None")
button_none.clicked.connect(self._button_none_click) self._button_none.clicked.connect(self._button_none_click)
hlayout.addWidget(button_none) hlayout.addWidget(self._button_none)
listlayout.addLayout(hlayout) listlayout.addLayout(hlayout)
# Add the entire list # Add the entire list
...@@ -127,7 +133,13 @@ class PlotWindow(QDialog): ...@@ -127,7 +133,13 @@ class PlotWindow(QDialog):
self.checklist.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) self.checklist.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
self.checklist.itemChanged.connect(self._item_change) self.checklist.itemChanged.connect(self._item_change)
listitems = {} listitems = {}
for key in sim_res_ins | sim_res_outs | sim_res_delays | sim_res_others: # Use | when dropping support for Python 3.8
ordered_for_checklist = {}
ordered_for_checklist.update(sim_res_ins)
ordered_for_checklist.update(sim_res_outs)
ordered_for_checklist.update(sim_res_delays)
ordered_for_checklist.update(sim_res_others)
for key in ordered_for_checklist:
listitem = QListWidgetItem(key) listitem = QListWidgetItem(key)
listitems[key] = listitem listitems[key] = listitem
self.checklist.addItem(listitem) self.checklist.addItem(listitem)
......
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
assert len(widget._plot_axes.lines) == 1
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment