Add test to ensure `set_model(None)` cleans up

We want to make sure that the selection model gets deleted when clearing
the model, since we are switching from doing that directly to having it
happen indirectly based off of signals we don't manage.

Hopefully this doesn't end up to be flaky. I think we are depending on
this happening in two different Qt even loop runs (`model.deleteLater()`
in the first one then `selmod.deleteLater()` gets called from the
`model.deleted` signal).

I tried using `qtbot.wait_signals()` with a list but it segfaulted in
some cleanup method. Perhaps is doesn't handle the deleted signal well?

Alternately we could maybe just wait for the selmodel one and check
`sip.isdelted(model)` to check the model is gone too.
This commit is contained in:
toofar 2024-06-03 16:09:10 +12:00
parent fe81422f94
commit 00daefff7e
1 changed files with 12 additions and 0 deletions

View File

@ -146,6 +146,18 @@ def test_completion_item_focus_no_model(which, completionview, model, qtbot):
completionview.completion_item_focus(which)
def test_models_deleted_on_clear(completionview, model, qtbot):
"""Ensure set_model(None) deleted the model and selmodel."""
completionview.set_model(model)
selmod = completionview._selection_model()
completionview.set_model(None)
with qtbot.wait_signal(model.destroyed):
pass
with qtbot.wait_signal(selmod.destroyed):
pass
@pytest.mark.skip("Seems to disagree with reality, see #5897")
def test_completion_item_focus_fetch(completionview, model, qtbot):
"""Test that on_next_prev_item moves the selection properly."""