Пример #1
0
def test_face_color():
    """Test setting face color."""
    shape = (10, 4, 2)
    np.random.seed(0)
    data = 20 * np.random.random(shape)
    layer = Shapes(data)
    assert layer.current_face_color == 'white'
    assert len(layer.face_color) == shape[0]
    assert layer.face_color == ['white'] * shape[0]

    # With no data selected changing face color has no effect
    layer.current_face_color = 'blue'
    assert layer.current_face_color == 'blue'
    assert layer.face_color == ['white'] * shape[0]

    # Select data and change face color of selection
    layer.selected_data = [0, 1]
    assert layer.current_face_color == 'white'
    layer.current_face_color = 'green'
    assert layer.face_color == ['green'] * 2 + ['white'] * (shape[0] - 2)

    # Add new shape and test its color
    new_shape = np.random.random((1, 4, 2))
    layer.selected_data = []
    layer.current_face_color = 'blue'
    layer.add(new_shape)
    assert len(layer.face_color) == shape[0] + 1
    assert layer.face_color == ['green'] * 2 + ['white'] * (shape[0] - 2) + [
        'blue'
    ]

    # Instantiate with custom face color
    layer = Shapes(data, face_color='red')
    assert layer.current_face_color == 'red'

    # Instantiate with custom face color list
    col_list = ['red', 'green'] * 5
    layer = Shapes(data, face_color=col_list)
    assert layer.current_face_color == 'white'
    assert layer.face_color == col_list

    # Add new point and test its color
    layer.current_face_color = 'blue'
    layer.add(new_shape)
    assert len(layer.face_color) == shape[0] + 1
    assert layer.face_color == col_list + ['blue']

    # Check removing data adjusts colors correctly
    layer.selected_data = [0, 2]
    layer.remove_selected()
    assert len(layer.data) == shape[0] - 1
    assert len(layer.face_color) == shape[0] - 1
    assert layer.face_color == [col_list[1]] + col_list[3:] + ['blue']
Пример #2
0
def test_shape_controls_face_color(qtbot):
    """Check updating of face color updates QtShapesControls."""
    layer = Shapes(_SHAPES)
    qtctrl = QtShapesControls(layer)
    qtbot.addWidget(qtctrl)
    target_color = transform_color(layer.current_face_color)[0]
    np.testing.assert_almost_equal(qtctrl.faceColorEdit.color, target_color)

    # Update current face color
    layer.current_face_color = 'red'
    target_color = transform_color(layer.current_face_color)[0]
    np.testing.assert_almost_equal(qtctrl.faceColorEdit.color, target_color)