def test_opacities(): """Test setting opacities.""" 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.opacity == 0.7 assert len(layer.opacities) == shape[0] assert layer.opacities == [0.7] * shape[0] # With no data selected chaning opacity has no effect layer.opacity = 1 assert layer.opacity == 1 assert layer.opacities == [0.7] * shape[0] # Select data and change opacity of selection layer.selected_data = [0, 1] assert layer.opacity == 0.7 layer.opacity = 0.5 assert layer.opacities == [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.opacity = 0.3 layer.add(new_shape) assert layer.opacities == [0.5] * 2 + [0.7] * (shape[0] - 2) + [0.3] # Instantiate with custom opacity layer = Shapes(data, opacity=0.2) assert layer.opacity == 0.2 # Instantiate with custom opacity list opacity_list = [0.1, 0.4] * 5 layer = Shapes(data, opacity=opacity_list) assert layer.opacity == 0.7 assert layer.opacities == opacity_list # Add new shape and test its opacity layer.opacity = 0.6 layer.add(new_shape) assert len(layer.opacities) == shape[0] + 1 assert layer.opacities == opacity_list + [0.6] # Check removing data adjusts opacities correctly layer.selected_data = [0, 2] layer.remove_selected() assert len(layer.data) == shape[0] - 1 assert len(layer.opacities) == shape[0] - 1 assert layer.opacities == [opacity_list[1]] + opacity_list[3:] + [0.6]
def test_opacity(): """Test setting layer opacity.""" np.random.seed(0) data = 20 * np.random.random((10, 4, 2)) layer = Shapes(data) assert layer.opacity == 0.7 layer.opacity = 0.5 assert layer.opacity == 0.5 layer = Shapes(data, opacity=0.6) assert layer.opacity == 0.6 layer.opacity = 0.3 assert layer.opacity == 0.3
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.opacity == 0.7 # Select data and change opacity of selection layer.selected_data = {0, 1} assert layer.opacity == 0.7 layer.opacity = 0.5 assert layer.opacity == 0.5 # Add new shape and test its width new_shape = np.random.random((1, 4, 2)) layer.selected_data = set() layer.add(new_shape) assert layer.opacity == 0.5 # Instantiate with custom opacity layer2 = Shapes(data, opacity=0.2) assert layer2.opacity == 0.2 # Check removing data shouldn't change opacity layer2.selected_data = {0, 2} layer2.remove_selected() assert len(layer2.data) == shape[0] - 2 assert layer2.opacity == 0.2