Beispiel #1
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
def test_deprecated_selection():
    """Test deprecated layer selection emits warnings."""
    layers = LayerList()
    layer = Image(np.random.random((10, 15)))
    events = []

    with pytest.warns(FutureWarning):
        layer.events.select.connect(lambda e: events.append(e))
        layer.events.deselect.connect(lambda e: events.append(e))

    layers.append(layer)
    assert events[-1].type == 'select'

    with pytest.warns(FutureWarning):
        assert layer.selected is True

    with pytest.warns(FutureWarning):
        layer.selected = False

    assert events[-1].type == 'deselect'
    assert layer not in layers.selection
Beispiel #3
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]

    # 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