Skip to content
Snippets Groups Projects
test_simulation_gui.py 2.68 KiB
Newer Older
  • Learn to ignore specific revisions
  • Oscar Gustafsson's avatar
    Oscar Gustafsson committed
    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
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
        assert len(widget._plot_axes.lines) == 1
    
    
    
    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
    
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
    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
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
        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