From 8bb579a0d969e3bd652e2cb54abc4fb647378c23 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson <oscar.gustafsson@gmail.com> Date: Thu, 6 Apr 2023 10:51:55 +0200 Subject: [PATCH] Test Simulation GUI --- b_asic/gui_utils/plot_window.py | 16 ++++++++++++++-- test/test_simulation_gui.py | 26 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 test/test_simulation_gui.py diff --git a/b_asic/gui_utils/plot_window.py b/b_asic/gui_utils/plot_window.py index 77babe1f..8ca17389 100644 --- a/b_asic/gui_utils/plot_window.py +++ b/b_asic/gui_utils/plot_window.py @@ -100,8 +100,14 @@ class PlotWindow(QDialog): self._plot_axes = self._plot_fig.add_subplot(111) 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 = {} - 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) self._lines[key] = line[0] @@ -127,7 +133,13 @@ class PlotWindow(QDialog): self.checklist.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) self.checklist.itemChanged.connect(self._item_change) 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) listitems[key] = listitem self.checklist.addItem(listitem) diff --git a/test/test_simulation_gui.py b/test/test_simulation_gui.py new file mode 100644 index 00000000..9df221b1 --- /dev/null +++ b/test/test_simulation_gui.py @@ -0,0 +1,26 @@ +import pytest + +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 -- GitLab