File: test_character.py

package info (click to toggle)
luma.core 2.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,044 kB
  • sloc: python: 6,185; makefile: 204
file content (37 lines) | stat: -rw-r--r-- 1,204 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2020 Richard Hull and contributors
# See LICENSE.rst for details.

from pathlib import Path

from PIL import Image, ImageFont
from luma.core.device import dummy
from luma.core.virtual import character

from helpers import get_reference_file, get_reference_image, assert_identical_image
import pytest

def test_init():
    pytest.skip()
    path = get_reference_file(Path('font').joinpath('hd44780a02.pil'))
    fnt = ImageFont.load(path)
    device = dummy(width=80, height=16, mode="1")
    character(device, font=fnt)
    assert device.image == Image.new("1", (80, 16))


def test_setter_getter():
    pytest.skip()
    fnt_path = get_reference_file(Path('font').joinpath('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)