fix(image): guard layer access during/after teardown

This commit is contained in:
2026-07-14 12:53:04 +02:00
committed by Jan Wyzula
parent c1ea65f7f9
commit 9c6fa74f65
2 changed files with 34 additions and 2 deletions
+23 -1
View File
@@ -1456,4 +1456,26 @@ def test_adjust_image_buffer_coerces_list_and_scalar(qtbot, mocked_client):
buf = view.adjust_image_buffer(image, [1, 2, 3]) # python list
assert buf.shape == (1, 3)
buf = view.adjust_image_buffer(image, np.array(42.0)) # 0-d scalar
assert buf.shape[0] == 2
assert buf.shape[0] == 2
##############################################
# Teardown safety
##############################################
def test_layer_accessors_safe_after_teardown(qtbot, mocked_client):
"""Once layer_manager is gone (post-cleanup), signal-driven accessors must
not raise. They used to subscript None or resurrect the 'main' layer."""
view = create_widget(qtbot, Image, client=mocked_client)
view.enable_full_colorbar = True
view.layer_manager = None # simulate post-cleanup state
# None of these should raise:
assert view.autorange is False
assert view.autorange_mode == "mean"
view.toggle_autorange(True, "mean")
view._set_autorange(True)
view.autorange_mode = "max"
view._sync_autorange_switch()
view._sync_colorbar_levels()