def test_settext_nocolor():
    neoseg = neosegment(width=6, device=dummy(width=6, height=7))
    neoseg.text = "888888"
    ref = dummy(width=6, height=7)
    with canvas(ref) as draw:
        draw.rectangle(ref.bounding_box, fill="white")
    assert_identical_image(ref.image, neoseg.device.image)
Beispiel #2
0
def test_settext_nocolor():
    neoseg = neosegment(width=6, device=dummy(width=6, height=7))
    neoseg.text = "888888"
    ref = dummy(width=6, height=7)
    with canvas(ref) as draw:
        draw.rectangle(ref.bounding_box, fill="white")
    assert_identical_image(ref.image, neoseg.device.image)
def test_settext_replacechars():
    neoseg = neosegment(width=6, device=dummy(width=6, height=7))
    neoseg.text = "888888"
    neoseg.text[2:4] = "  "
    ref = dummy(width=6, height=7)
    with canvas(ref) as draw:
        draw.rectangle(ref.bounding_box, fill="white")
        draw.rectangle([2, 0, 3, 6], fill="black")
    assert_identical_image(ref.image, neoseg.device.image)
Beispiel #4
0
def test_settext_replacechars():
    neoseg = neosegment(width=6, device=dummy(width=6, height=7))
    neoseg.text = "888888"
    neoseg.text[2:4] = "  "
    ref = dummy(width=6, height=7)
    with canvas(ref) as draw:
        draw.rectangle(ref.bounding_box, fill="white")
        draw.rectangle([2, 0, 3, 6], fill="black")
    assert_identical_image(ref.image, neoseg.device.image)
Beispiel #5
0
def test_unknown_char():
    neoseg = neosegment(width=6, device=dummy(width=6, height=7))
    neoseg.text = "888888"
    neoseg.text[2:4] = "&\x7f"
    neoseg.color[2:4] = ["orange", "orange"]
    ref = dummy(width=6, height=7)
    with canvas(ref) as draw:
        draw.rectangle(ref.bounding_box, fill="white")
        draw.rectangle([2, 0, 3, 6], fill="black")
        draw.rectangle([2, 1, 3, 1], fill="orange")
    assert_identical_image(ref.image, neoseg.device.image)
Beispiel #6
0
def test_persist():
    dev = dummy()
    assert dev.persist is False
    with patch.object(dev, 'hide') as mock:
        dev.cleanup()
    mock.assert_called_once_with()
    dev = dummy()
    dev.persist = True
    with patch.object(dev, 'hide') as mock:
        dev.cleanup()
    mock.assert_not_called()
def test_unknown_char():
    neoseg = neosegment(width=6, device=dummy(width=6, height=7))
    neoseg.text = "888888"
    neoseg.text[2:4] = "&\x7f"
    neoseg.color[2:4] = ["orange", "orange"]
    ref = dummy(width=6, height=7)
    with canvas(ref) as draw:
        draw.rectangle(ref.bounding_box, fill="white")
        draw.rectangle([2, 0, 3, 6], fill="black")
        draw.rectangle([2, 1, 3, 1], fill="orange")
    assert_identical_image(ref.image, neoseg.device.image)
Beispiel #8
0
def test_seven_segment():
    with open(get_reference_image("seven_segment.png"), "rb") as fp:
        ref = Image.open(fp)
        chars = [
            # Alphabet with omissions
            0x00, 0x01, 0x08, 0x02, 0x7e, 0x30, 0x6d, 0x79, 0x33, 0x5b, 0x5f,
            0x70, 0x7f, 0x7b, 0x7d, 0x1f, 0x0d, 0x3d, 0x6f, 0x47, 0x7b, 0x17,
            0x10, 0x18, 0x06, 0x15, 0x1d, 0x67, 0x73, 0x05, 0x5b, 0x0f, 0x1c,
            0x1c, 0x3b, 0x6d, 0x77, 0x7f, 0x4e, 0x7e, 0x4f, 0x47, 0x5e, 0x37,
            0x30, 0x38, 0x0e, 0x76, 0x7e, 0x67, 0x73, 0x46, 0x5b, 0x0f, 0x3e,
            0x3e, 0x3b, 0x6d, 0x80, 0x80
        ]
        device = dummy(width=len(chars), height=8)
        with canvas(device) as draw:
            for x in range(len(chars)):
                val = chars[x]
                for y in range(8):
                    mask = 1 << y
                    if val & mask != 0:
                        draw.point((device.width - x, y), fill="white")
        surface = to_pygame_surface(device.image)
        tf = transformer(pygame, device.width, device.height, 16)
        im = to_pillow_img(tf.seven_segment(surface))
        bbox = ImageChops.difference(ref, im).getbbox()
        assert bbox is None
Beispiel #9
0
def test_wrapped_text():
    reference = 'quick_brown_fox_word_wrap.png'
    device = dummy()
    term = terminal(device, word_wrap=True, animate=False)

    assert_text(device, term, reference,
                ["The quick brown fox jumps over the lazy dog"])
Beispiel #10
0
def test_default_text():
    reference = 'quick_brown_fox.png'
    device = dummy()
    term = terminal(device)

    assert_text(device, term, reference,
                ["The quick brown fox jumps over the lazy dog"])
Beispiel #11
0
def test_control_chars():
    reference = 'control_chars.png'
    device = dummy()
    term = terminal(device, animate=False)

    assert_text(device, term, reference,
                ['foo\rbar\bspam\teggs\n\nham and cheese on rye'])
Beispiel #12
0
def test_overflow():
    device = dummy(width=24, height=8, mode="1")
    seg = sevensegment(device)
    with pytest.raises(OverflowError) as ex:
        seg.text = "This is too big to fit in 3x8 seven-segment displays"
    assert str(
        ex.value
    ) == "Device's capabilities insufficent for value 'This is too big to fit in 3x8 seven-segment displays'"
Beispiel #13
0
def test_capture_noops():
    device = dummy()
    # All these should have no effect
    device.hide()
    device.show()
    device.cleanup()
    device.contrast(123)
    device.command(1, 2, 4, 4)
    device.data([1, 2, 4, 4])
def test_segment_mapper():
    img_path = get_reference_image('neosegment.png')

    with open(img_path, 'rb') as img:
        reference = Image.open(img)
        neoseg = neosegment(width=6, device=dummy(width=6, height=7))
        neoseg.color = ["red", "green", "blue", "yellow", "cyan", "magenta"]
        neoseg.text = "012345"
        assert_identical_image(reference, neoseg.device.image)
Beispiel #15
0
def test_segment_mapper():
    img_path = get_reference_image('neosegment.png')

    with open(img_path, 'rb') as img:
        reference = Image.open(img)
        neoseg = neosegment(width=6, device=dummy(width=6, height=7))
        neoseg.color = ["red", "green", "blue", "yellow", "cyan", "magenta"]
        neoseg.text = "012345"
        assert_identical_image(reference, neoseg.device.image)
Beispiel #16
0
def test_ansi_colors_wrapped():
    reference = 'ansi_colors_wrapped.png'
    device = dummy()
    term = terminal(device, word_wrap=True, animate=False)

    assert_text(device, term, reference, [
        "hello \033[31mworld\033[0m ansi colors\t\033[32mwrap\033[0m\t?",
        "this is \033[7mreversed\033[7m!",
        "\033[43;30mYellow\033[0m \033[45;37mMagenta"
    ])
Beispiel #17
0
def test_ansi_colors():
    reference = 'ansi_colors.png'
    device = dummy()
    term = terminal(device, animate=False)

    assert_text(device, term, reference, [
        "hello \033[31mworld\033[0m ansi colors here!",
        "this is \033[7mreversed\033[7m!",
        "\033[44;37mBlue\033[0m \033[46;30mCyan"
    ])
    def init_display(self):
        if Config.get("debug.dummy", False):
            self.device = dummy(width=256, height=64, rotate=0, mode="1")
        else:
            serial = spi(bus_speed_hz=Config.get("debug.bus_speed", 16000000))
            self.device = ssd1322(serial, mode="1", rotate=0)

        self.viewport = viewport(self.device,
                                 width=self.device.width,
                                 height=self.device.height)
Beispiel #19
0
def test_setter_getter():
    img_path = get_reference_image('golden_ratio.png')

    with open(img_path, 'rb') as img:
        reference = Image.open(img)
        device = dummy(width=24, height=8)
        seg = sevensegment(device, segment_mapper=dot_muncher)
        seg.text = "1.61803398875"
        assert str(seg.text) == "1.61803398875"

        assert_identical_image(reference, device.image)
Beispiel #20
0
def test_ansi_colors_scroll():
    reference = 'ansi_colors_scroll.png'
    device = dummy()
    term = terminal(device, word_wrap=True, animate=False)

    assert_text(device, term, reference, [
        "hello \033[31mworld\033[0m ansi colors\t\033[32mwrap\033[0m\t?",
        "this is \033[7mreversed\033[7m!",
        "\033[43;30mYellow\033[0m \033[44;37mBlue abcdefg hijklmn",
        "\033[41;30mRed\033[0m \033[42;37mGreen"
    ])
Beispiel #21
0
def test_font(fontname):
    font = getattr(luma.core.legacy.font, fontname)
    w, h = textsize(charset, proportional(font))
    device = dummy(width=w, height=h, mode="1")
    with canvas(device) as draw:
        text(draw, (0, 0), charset, "white", font=proportional(font))

    img_path = get_reference_image(f'{fontname}.png')
    with open(img_path, 'rb') as fp:
        reference = Image.open(fp)
        assert_identical_image(reference, device.image, img_path)
Beispiel #22
0
def test_refresh():
    ic = ImageComposition(dummy())
    ic_img_before = list(ic().getdata())
    img = Image.new("RGB", (25, 25))
    draw = ImageDraw.Draw(img)
    draw.rectangle((10, 10, 20, 20), outline="white")
    del draw
    ci = ComposableImage(img)
    ic.add_image(ci)
    ic.refresh()
    assert ic_img_before != list(ic().getdata())
Beispiel #23
0
def test_setter_getter():
    img_path = get_reference_image('golden_ratio.png')

    with open(img_path, 'rb') as img:
        reference = Image.open(img)
        device = dummy(width=24, height=8)
        seg = sevensegment(device)
        seg.text = "1.61803398875"
        assert str(seg.text) == "1.61803398875"

        bbox = ImageChops.difference(reference, device.image).getbbox()
        assert bbox is None
Beispiel #24
0
def test_scrolling():
    reference = 'scroll_text.png'
    device = dummy()
    term = terminal(device, animate=False)

    assert_text(device, term, reference, [
        "it oozed over the blackness, and heard Harris's sleepy voice asking "
        "where we drew near it, so they spread their handkerchiefs on the back "
        "of Harris and Harris's friend as to avoid running down which, we managed "
        "to get out of here while this billing and cooing is on. We'll go down "
        "to eat vegetables. He said they were demons."
    ])
Beispiel #25
0
def test_accented_charset():
    reference = 'accented_charset.png'
    unicode_font = get_reference_font('DejaVuSans.ttf')
    device = dummy()
    term = terminal(device,
                    font=unicode_font,
                    word_wrap=False,
                    animate=False,
                    color="blue",
                    bgcolor="white")

    assert_text(device, term, reference,
                [u"\033[31mFußgängerunterführungen\033[0m Текст на русском"])
Beispiel #26
0
def test_led_matrix():
    with open(get_reference_image("led_matrix.png"), "rb") as fp:
        ref = Image.open(fp)
        device = dummy(width=40, height=24)
        with canvas(device) as draw:
            draw.rectangle(device.bounding_box, outline="white")
            draw.text((5, 2), "Hello", fill="white")
            draw.text((5, 10), "World", fill="white")
        surface = to_pygame_surface(device.image)
        tf = transformer(pygame, device.width, device.height, 16)
        im = to_pillow_img(tf.led_matrix(surface))
        bbox = ImageChops.difference(ref, im).getbbox()
        assert bbox is None
Beispiel #27
0
def test_setter_getter():
    fnt_path = get_reference_file(os.path.join('font', 'hd44780a02.pil'))
    img_path = get_reference_image('character_golden_ratio.png')

    with open(img_path, 'rb') as img:
        fnt = ImageFont.load(fnt_path)
        reference = Image.open(img)
        device = dummy(width=80, height=16, mode="1")
        c = character(device, font=fnt)
        c.text = "1.61803398875\n1.61803398875"
        assert str(c.text) == "1.61803398875\n1.61803398875"

        assert_identical_image(reference, device.image, img_path)
Beispiel #28
0
def test_portrait():
    img_path = get_reference_image('portrait.png')

    with open(img_path, 'rb') as p:
        reference = Image.open(p)

        device = dummy(rotate=1)

        # Use the same drawing primitives as the demo
        with canvas(device) as draw:
            baseline_data.primitives(device, draw)

        assert_identical_image(reference, device.image)
Beispiel #29
0
def test_dither():
    img_path = get_reference_image('dither.png')

    with open(img_path, 'rb') as p:
        reference = Image.open(p)
        device = dummy(mode="1")

        with canvas(device, dither=True) as draw:
            draw.rectangle((0, 0, 64, 32), fill="red")
            draw.rectangle((64, 0, 128, 32), fill="yellow")
            draw.rectangle((0, 32, 64, 64), fill="blue")
            draw.rectangle((64, 32, 128, 64), fill="white")

        assert_identical_image(reference, device.image)
Beispiel #30
0
def test_image_count():
    ic = ImageComposition(dummy())
    img1 = ComposableImage(Image.new("RGB", (1, 1)))
    img2 = ComposableImage(Image.new("RGB", (1, 1)))
    img3 = ComposableImage(Image.new("RGB", (1, 1)))
    ic.add_image(img1)
    ic.add_image(img2)
    ic.add_image(img3)
    assert len(ic.composed_images) == 3
    ic.remove_image(img3)
    assert len(ic.composed_images) == 2
    ic.remove_image(img2)
    assert len(ic.composed_images) == 1
    ic.remove_image(img1)
    assert len(ic.composed_images) == 0
Beispiel #31
0
def test_viewport_set_position():
    img_path = get_reference_image('set_position.png')

    with open(img_path, 'rb') as p:
        reference = Image.open(p)
        device = dummy()
        virtual = viewport(device, 200, 200)

        # Use the same drawing primitives as the demo
        with canvas(virtual) as draw:
            baseline_data.primitives(virtual, draw)

        virtual.set_position((20, 30))

        assert_identical_image(reference, device.image, img_path)
Beispiel #32
0
def test_canvas_background():
    with open(get_reference_image('dither.png'), 'rb') as p1:
        with open(get_reference_image('background.png'), 'rb') as p2:
            bgnd = Image.open(p1)
            reference = Image.open(p2)
            device = dummy()

            with canvas(device, background=bgnd) as draw:
                draw.rectangle((20, 15, device.width - 20, device.height - 15),
                               fill="black",
                               outline="white")
                draw.text((36, 22), "Background", fill="white")
                draw.text((52, 32), "Test", fill="white")

            assert_identical_image(reference, device.image)
Beispiel #33
0
def test_canvas_background():
    img_path = get_reference_image('background.png')
    with open(get_reference_image('dither.png'), 'rb') as p1:
        with open(img_path, 'rb') as p2:
            bgnd = Image.open(p1)
            reference = Image.open(p2)
            device = dummy()

            with canvas(device, background=bgnd) as draw:
                draw.rectangle((20, 15, device.width - 20, device.height - 15),
                               fill='black',
                               outline='white')
                draw.text((36, 22), 'Background', fill='white')
                draw.text((52, 32), 'Test', fill='white')

            assert_identical_image(reference, device.image, img_path)
Beispiel #34
0
def test_viewport_hotspot():
    img_path = get_reference_image('hotspot.png')

    with open(img_path, 'rb') as p:
        reference = Image.open(p)
        device = dummy()
        virtual = viewport(device, 200, 200)

        def draw_fn(draw, width, height):
            baseline_data.primitives(device, draw)

        widget = hotspot(device.width, device.height, draw_fn)

        virtual.add_hotspot(widget, (19, 56))
        virtual.set_position((28, 30))
        virtual.remove_hotspot(widget, (19, 56))

        assert_identical_image(reference, device.image, img_path)
Beispiel #35
0
def test_invalid_dimensions():
    with pytest.raises(luma.core.error.DeviceDisplayModeError) as ex:
        neosegment(width=3, device=dummy(width=6, height=7))
    assert "Unsupported display mode: width=3" in str(ex.value)
Beispiel #36
0
def test_overflow():
    with pytest.raises(OverflowError) as ex:
        neoseg = neosegment(width=6, device=dummy(width=6, height=7))
        neoseg.text = "TooBig!"
    assert "Device's capabilities insufficient for value 'TooBig!'" in str(ex.value)