Beispiel #1
0
def test_color_mul():
    verify_color(Color('magenta') * Color('blue'), Color('blue'))
    verify_color(Color('magenta') * Color('white'), Color('magenta'))
    verify_color(Color('magenta') * Red(0.5), Color(0.5, 0, 1))
    verify_color(Color('magenta') * Green(0.5), Color('magenta'))
    verify_color(Color('magenta') * Blue(0.5), Color(1, 0, 0.5))
    verify_color(Color('magenta') * Hue(0), Color('red'))
    verify_color(Color('magenta') * Lightness(0.5), Color(0.5, 0.0, 0.5))
    verify_color(Color('magenta') * Saturation(0), Color(0.5, 0.5, 0.5))
    verify_color(Color('magenta') * Luma(1), Color('magenta'))
    verify_color(Red(0.5) * Color('magenta'), Color(0.5, 0, 1))
    # pylint: disable=expression-not-assigned
    with pytest.raises(TypeError):
        Color('magenta') * 1
    with pytest.raises(TypeError):
        1 * Color('magenta')
Beispiel #2
0
def test_color_add():
    verify_color(Color('red') + Color('blue'), Color('magenta'))
    verify_color(Color('red') + Color('white'), Color('white'))
    verify_color(Color('red') + Red(1), Color('red'))
    verify_color(Color('red') + Green(1), Color('yellow'))
    verify_color(Color('red') + Blue(1), Color('magenta'))
    verify_color(Color('red') + Hue(0), Color('red'))
    verify_color(Color('red') + Lightness(0.5), Color('white'))
    verify_color(Color('red') + Saturation(1), Color('red'))
    verify_color(Color('red') + Luma(1), Color('white'))
    verify_color(Green(1) + Color('red'), Color('yellow'))
    # pylint: disable=expression-not-assigned
    with pytest.raises(TypeError):
        Color('red') + 1
    with pytest.raises(TypeError):
        1 + Color('red')
Beispiel #3
0
def test_color_sub():
    verify_color(Color('magenta') - Color('blue'), Color('red'))
    verify_color(Color('magenta') - Color('white'), Color('black'))
    verify_color(Color('magenta') - Red(1), Color('blue'))
    verify_color(Color('magenta') - Green(1), Color('magenta'))
    verify_color(Color('magenta') - Blue(1), Color('red'))
    verify_color(Color('magenta') - Hue(0), Color('magenta'))
    verify_color(Color('magenta') - Lightness(0.5), Color('black'))
    verify_color(Color('magenta') - Saturation(1), Color(0.5, 0.5, 0.5))
    verify_color(Color('magenta') - Luma(1), Color('black'))
    verify_color(Red(1) - Color('magenta'), Color(0, 0, 0))
    verify_color(Green(1) - Color('magenta'), Color(0, 1, 0))
    verify_color(Blue(1) - Color('magenta'), Color(0, 0, 0))
    # pylint: disable=expression-not-assigned
    with pytest.raises(TypeError):
        Color('magenta') - 1
    with pytest.raises(TypeError):
        1 - Color('magenta')
Beispiel #4
0
def test_color_attr():
    assert Color('red').hue == Hue(0)
    assert Color('red').lightness == Lightness(0.5)
    assert Color('red').saturation == Saturation(1)
    assert Color('red').luma == Luma(0.299)