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)
Exemplo n.º 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_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)
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)
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
0
def assert_text(device, term, reference_img, text):
    img_path = get_reference_image(reference_img)

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

        for line in text:
            term.println(line)

        assert_identical_image(reference, device.image)
Exemplo n.º 8
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)
Exemplo n.º 9
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)
Exemplo n.º 10
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)
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)
Exemplo n.º 12
0
def assert_text(device, term, reference_img, text, save=None):
    img_path = get_reference_image(reference_img)

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

        for line in text:
            term.println(line)

        if save is not None:
            device.image.save(save)

        assert_identical_image(reference, device.image, img_path)
Exemplo n.º 13
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)
Exemplo n.º 14
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)
Exemplo n.º 15
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)
Exemplo n.º 16
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)
Exemplo n.º 17
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)
Exemplo n.º 18
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)
Exemplo n.º 19
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)
Exemplo n.º 20
0
def test_viewport_dithering():
    img_path = get_reference_image('hotspot_dither.png')

    with open(img_path, 'rb') as p:
        reference = Image.open(p)
        device = dummy(mode="1")
        virtual = viewport(device, 200, 200, mode='RGBA', dither=True)

        def draw_fn(draw, width, height):
            draw.rectangle((0, 0, width / 2, height / 2), fill="red")
            draw.rectangle((width / 2, 0, width, height / 2), fill="yellow")
            draw.rectangle((0, height / 2, width / 2, height), fill="blue")
            draw.rectangle((width / 2, height / 2, width, height),
                           fill="white")

        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)