|
| 1 | +"""Test of Quick View functionalities |
| 2 | +
|
| 3 | +Created a new test file because putting "test_no_events_issue_37" and |
| 4 | +"test_update_polygon_filter_issue_26" in one file raised an error |
| 5 | +"RuntimeError: wrapped C/C++ object of type MatrixElement has been |
| 6 | +deleted" (similar to issue #38). |
| 7 | +""" |
| 8 | +import pathlib |
| 9 | + |
| 10 | +from PyQt5 import QtCore |
| 11 | + |
| 12 | +import numpy as np |
| 13 | +from shapeout2.gui.main import ShapeOut2 |
| 14 | +from shapeout2 import session |
| 15 | +import pytest |
| 16 | + |
| 17 | + |
| 18 | +@pytest.fixture(autouse=True) |
| 19 | +def run_around_tests(): |
| 20 | + # Code that will run before your test, for example: |
| 21 | + session.clear_session() |
| 22 | + # A test function will be run at this point |
| 23 | + yield |
| 24 | + # Code that will run after your test, for example: |
| 25 | + session.clear_session() |
| 26 | + |
| 27 | + |
| 28 | +def test_no_events_issue_37(qtbot): |
| 29 | + """https://github.com/ZELLMECHANIK-DRESDEN/ShapeOut2/issues/37 |
| 30 | +
|
| 31 | + "ValueError: zero-size array to reduction operation minimum |
| 32 | + which has no identity" when all events are filtered out. |
| 33 | + """ |
| 34 | + mw = ShapeOut2() |
| 35 | + qtbot.addWidget(mw) |
| 36 | + |
| 37 | + # add a dataslot |
| 38 | + path = pathlib.Path(__file__).parent / "data" / "calibration_beads_47.rtdc" |
| 39 | + mw.add_dataslot(paths=[path, path]) |
| 40 | + |
| 41 | + assert len(mw.pipeline.slot_ids) == 2, "we added those" |
| 42 | + assert len(mw.pipeline.filter_ids) == 1, "automatically added" |
| 43 | + |
| 44 | + # activate a dataslot |
| 45 | + slot_id = mw.pipeline.slot_ids[0] |
| 46 | + filt_id = mw.pipeline.filter_ids[0] |
| 47 | + em = mw.block_matrix.get_widget(slot_id, filt_id) |
| 48 | + qtbot.mouseClick(em, QtCore.Qt.LeftButton) # activate |
| 49 | + # did that work? |
| 50 | + assert mw.pipeline.is_element_active(slot_id, filt_id) |
| 51 | + |
| 52 | + # filter away all events |
| 53 | + fe = mw.block_matrix.get_widget(filt_plot_id=filt_id) |
| 54 | + qtbot.mouseClick(fe.toolButton_modify, QtCore.Qt.LeftButton) |
| 55 | + fv = mw.widget_ana_view.widget_filter |
| 56 | + qtbot.mouseClick(fv.toolButton_moreless, QtCore.Qt.LeftButton) |
| 57 | + rc = fv._box_range_controls["area_um"] |
| 58 | + qtbot.mouseClick(rc.checkBox, QtCore.Qt.LeftButton) |
| 59 | + # did that work? |
| 60 | + assert rc.checkBox.isChecked() |
| 61 | + qtbot.mouseClick(fv.toolButton_moreless, QtCore.Qt.LeftButton) |
| 62 | + # set range |
| 63 | + rc.doubleSpinBox_min.setValue(0) |
| 64 | + rc.doubleSpinBox_max.setValue(1) |
| 65 | + qtbot.mouseClick(fv.pushButton_apply, QtCore.Qt.LeftButton) |
| 66 | + # did that work? |
| 67 | + ds = mw.pipeline.get_dataset(slot_index=0, filt_index=0, |
| 68 | + apply_filter=True) |
| 69 | + assert np.sum(ds.filter.all) == 0 |
| 70 | + |
| 71 | + # open QuickView |
| 72 | + slot_id = mw.pipeline.slot_ids[0] |
| 73 | + filt_id = mw.pipeline.filter_ids[0] |
| 74 | + em = mw.block_matrix.get_widget(slot_id, filt_id) |
| 75 | + |
| 76 | + # this raised the error |
| 77 | + qtbot.mouseClick(em, QtCore.Qt.LeftButton, QtCore.Qt.ShiftModifier) |
| 78 | + mw.close() |
0 commit comments