def test_remove_selected(): """Test removing selected layers.""" layers = LayerList() layer_a = Image(np.random.random((10, 10))) layer_b = Image(np.random.random((15, 15))) layer_c = Image(np.random.random((15, 15))) layers.append(layer_a) layers.append(layer_b) layers.append(layer_c) # remove last added layer as only one selected layers.selection.clear() layers.selection.add(layer_c) layers.remove_selected() assert list(layers) == [layer_a, layer_b] # select and remove all layersay layers.select_all() layers.remove_selected() assert len(layers) == 0
def test_removing_layers(qtbot): """ Test removing layers. """ layers = LayerList() view = QtLayerList(layers) qtbot.addWidget(view) layer_a = Image(np.random.random((10, 10))) layer_b = Image(np.random.random((15, 15))) layer_c = Image(np.random.random((15, 15))) layer_d = Image(np.random.random((15, 15))) layers.append(layer_a) layers.append(layer_b) layers.append(layer_c) layers.append(layer_d) # Check layout and layers list match after removing a layer layers.remove(layer_b) assert view.vbox_layout.count() == 2 * (len(layers) + 1) assert check_layout_layers(view.vbox_layout, layers) assert check_layout_dividers(view.vbox_layout, len(layers)) # Check layout and layers list match after removing a layer layers.remove(layer_d) assert view.vbox_layout.count() == 2 * (len(layers) + 1) assert check_layout_layers(view.vbox_layout, layers) assert check_layout_dividers(view.vbox_layout, len(layers)) layers.append(layer_b) layers.append(layer_d) # Select first and third layers for layer, s in zip(layers, [True, True, False, False]): layer.selected = s layers.remove_selected() assert view.vbox_layout.count() == 2 * (len(layers) + 1) assert check_layout_layers(view.vbox_layout, layers) assert check_layout_dividers(view.vbox_layout, len(layers))
def test_remove_selected(): """ Test removing selected layers """ layers = LayerList() layer_a = Image(np.random.random((10, 10))) layer_b = Image(np.random.random((15, 15))) layer_c = Image(np.random.random((15, 15))) layer_d = Image(np.random.random((15, 15))) layers.append(layer_a) layers.append(layer_b) layers.append(layer_c) # remove last added layer as only one selected layers.remove_selected() assert list(layers) == [layer_a, layer_b] # check that the next to last layer is now selected assert [lay.selected for lay in layers] == [False, True] layers.remove_selected() assert list(layers) == [layer_a] assert [lay.selected for lay in layers] == [True] # select and remove first layer only layers.append(layer_b) layers.append(layer_c) assert list(layers) == [layer_a, layer_b, layer_c] layer_a.selected = True layer_b.selected = False layer_c.selected = False layers.remove_selected() assert list(layers) == [layer_b, layer_c] assert [lay.selected for lay in layers] == [True, False] # select and remove first and last layer of four layers.append(layer_a) layers.append(layer_d) assert list(layers) == [layer_b, layer_c, layer_a, layer_d] layer_a.selected = False layer_b.selected = True layer_c.selected = False layer_d.selected = True layers.remove_selected() assert list(layers) == [layer_c, layer_a] assert [lay.selected for lay in layers] == [True, False] # select and remove middle two layers of four layers.append(layer_b) layers.append(layer_d) layer_a.selected = True layer_b.selected = True layer_c.selected = False layer_d.selected = False layers.remove_selected() assert list(layers) == [layer_c, layer_d] assert [lay.selected for lay in layers] == [True, False] # select and remove all layersay for lay in layers: lay.selected = True layers.remove_selected() assert len(layers) == 0
def test_remove_selected(): """ Test removing selected layers """ layers = LayerList() layer_a = Image(np.random.random((10, 10))) layer_b = Image(np.random.random((15, 15))) layer_c = Image(np.random.random((15, 15))) layer_d = Image(np.random.random((15, 15))) layers.append(layer_a) layers.append(layer_b) layers.append(layer_c) # remove last added layer as only one selected layers.remove_selected() assert list(layers) == [layer_a, layer_b] # remove no layers as none selected layers.remove_selected() assert list(layers) == [layer_a, layer_b] # select and remove first layer only layers.append(layer_c) layer_c.selected = False layer_a.selected = True layers.remove_selected() assert list(layers) == [layer_b, layer_c] # select and remove first and last layer of four layers.append(layer_a) layers.append(layer_d) layer_b.selected = True layers.remove_selected() assert list(layers) == [layer_c, layer_a] # select and remove middle two layers of four layers.append(layer_b) layers.append(layer_d) layer_a.selected = True layer_b.selected = True layer_d.selected = False layers.remove_selected() assert list(layers) == [layer_c, layer_d] # select and remove all layers for l in layers: l.selected = True layers.remove_selected() assert len(layers) == 0