Beispiel #1
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 #2
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 #3
0
def test_rgbled_rgb_property_pwm():
    with RGBLED(1, 2, 3) as led:
        assert led.value == (0, 0, 0)
        led.red = Red(0)
        assert led.value == (0, 0, 0)
        led.red = Red(0.5)
        assert led.value == (0.5, 0, 0)
        led.green = Green(0.5)
        assert led.value == (0.5, 0.5, 0)
        led.blue = Blue(0.5)
        assert led.value == (0.5, 0.5, 0.5)
Beispiel #4
0
def test_rgbled_rgb_property_nopwm():
    with RGBLED(1, 2, 3, pwm=False) as led:
        assert led.value == (0, 0, 0)
        led.red = Red(0)
        assert led.value == (0, 0, 0)
        led.red = Red(1)
        assert led.value == (1, 0, 0)
        led.green = Green(1)
        assert led.value == (1, 1, 0)
        led.blue = Blue(1)
        assert led.value == (1, 1, 1)
Beispiel #5
0
def barometer(offset, reading):
    p = (max(950, min(1050, reading.pressure)) - 950) / 100 * 64
    screen = array([
        Color('green') if i < int(p) else
        Color('green') * Green(p - int(p)) if i < p else
        Color('black')
        for i in range(64)
    ])
    screen = np.flipud(screen)
    text = image_to_rgb(draw_text(int(round(reading.pressure)),
                                  'small.pil', foreground=Color('gray'),
                                  padding=(0, 0, 8, 3)))
    screen[:text.shape[0], :] += text[:, offset:offset + 8]
    return screen.clip(0, 1)
Beispiel #6
0
def test_rgbled_bad_rgb_property_pwm():
    with RGBLED(1, 2, 3) as led:
        with pytest.raises(ValueError):
            led.red = 1.5
        with pytest.raises(ValueError):
            led.green = 2
        with pytest.raises(ValueError):
            led.blue = -1
        with pytest.raises(ValueError):
            led.red = Red(1.5)
        with pytest.raises(ValueError):
            led.green = Green(2)
        with pytest.raises(ValueError):
            led.blue = Blue(-1)
Beispiel #7
0
def test_rgbled_bad_rgb_property_nopwm():
    with RGBLED(1, 2, 3, pwm=False) as led:
        with pytest.raises(ValueError):
            led.red = 0.1
        with pytest.raises(ValueError):
            led.green = 0.5
        with pytest.raises(ValueError):
            led.blue = 0.9
        with pytest.raises(ValueError):
            led.red = Red(0.1)
        with pytest.raises(ValueError):
            led.green = Green(0.5)
        with pytest.raises(ValueError):
            led.blue = Blue(0.9)
Beispiel #8
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')