コード例 #1
0
def test_opacity():
    """Test setting opacity."""
    shape = (10, 4, 2)
    np.random.seed(0)
    data = 20 * np.random.random(shape)
    layer = Shapes(data)
    # Check default opacity value of 0.7
    assert layer.current_opacity == 0.7
    assert len(layer.opacity) == shape[0]
    assert layer.opacity == [0.7] * shape[0]

    # With no data selected changing opacity has no effect
    layer.current_opacity = 1
    assert layer.current_opacity == 1
    assert layer.opacity == [0.7] * shape[0]

    # Select data and change opacity of selection
    layer.selected_data = [0, 1]
    assert layer.current_opacity == 0.7
    layer.current_opacity = 0.5
    assert layer.opacity == [0.5] * 2 + [0.7] * (shape[0] - 2)

    # Add new shape and test its width
    new_shape = np.random.random((1, 4, 2))
    layer.selected_data = []
    layer.current_opacity = 0.3
    layer.add(new_shape)
    assert layer.opacity == [0.5] * 2 + [0.7] * (shape[0] - 2) + [0.3]

    # Instantiate with custom opacity
    layer = Shapes(data, opacity=0.2)
    assert layer.current_opacity == 0.2

    # Instantiate with custom opacity list
    opacity_list = [0.1, 0.4] * 5
    layer = Shapes(data, opacity=opacity_list)
    assert layer.current_opacity == 0.7
    assert layer.opacity == opacity_list

    # Add new shape and test its opacity
    layer.current_opacity = 0.6
    layer.add(new_shape)
    assert len(layer.opacity) == shape[0] + 1
    assert layer.opacity == opacity_list + [0.6]

    # Check removing data adjusts opacity correctly
    layer.selected_data = [0, 2]
    layer.remove_selected()
    assert len(layer.data) == shape[0] - 1
    assert len(layer.opacity) == shape[0] - 1
    assert layer.opacity == [opacity_list[1]] + opacity_list[3:] + [0.6]
コード例 #2
0
def test_current_opacity():
    """Test setting current layer opacity."""
    np.random.seed(0)
    data = 20 * np.random.random((10, 4, 2))
    layer = Shapes(data)
    assert layer.current_opacity == 0.7

    layer.current_opacity = 0.5
    assert layer.current_opacity == 0.5

    layer = Shapes(data, opacity=0.6)
    assert layer.current_opacity == 0.6

    layer.current_opacity = 0.3
    assert layer.current_opacity == 0.3