Skip to content

Commit

Permalink
tests: update images for Pillow 10.1 (#274)
Browse files Browse the repository at this point in the history
* tests: update images for Pillow 10.1

* add test font

* disable save statement

* tox: add py3.13

* ci: test against py3.13
  • Loading branch information
thijstriemstra committed Jan 21, 2024
1 parent caeaae5 commit 5b271cb
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-minor-version: [7, 8, 9, 10, 11, 12-dev]
python-minor-version: [7, 8, 9, 10, 11, 12, 13-dev]
name: Python 3.${{ matrix.python-minor-version }}
steps:
- uses: actions/checkout@v3
Expand Down
8 changes: 5 additions & 3 deletions tests/baseline_data.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2017-18 Richard Hull and contributors
# Copyright (c) 2017-2024 Richard Hull and contributors
# See LICENSE.rst for details.

from helpers import test_font


def primitives(device, draw):
padding = 2
Expand All @@ -20,5 +22,5 @@ def primitives(device, draw):
draw.line((x, bottom, x + shape_width, top), fill="yellow")
draw.line((x, top, x + shape_width, bottom), fill="yellow")
x += shape_width + padding
draw.text((x, top), 'Hello', fill="cyan")
draw.text((x, top + 20), 'World!', fill="purple")
draw.text((x, top), 'Hello', font=test_font, fill="cyan")
draw.text((x, top + 20), 'World!', font=test_font, fill="purple")
5 changes: 5 additions & 0 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def get_reference_pillow_font(fname):
return ImageFont.load(path)


# font used in (most) tests
test_font = get_reference_pillow_font('courB08.pil')


def get_spidev():
try:
import spidev
Expand All @@ -72,6 +76,7 @@ def assert_identical_image(reference, target, img_path):
:type img_path: str
"""
bbox = ImageChops.difference(reference, target).getbbox()
#target.save(img_path)
assert bbox is None, f'{img_path} is not identical to generated image'


Expand Down
Binary file added tests/reference/font/courB08.pbm
Binary file not shown.
Binary file added tests/reference/font/courB08.pil
Binary file not shown.
Binary file modified tests/reference/images/golden_ratio.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions tests/test_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from luma.core.device import dummy
from luma.core.render import canvas

from helpers import get_reference_image, assert_identical_image
from helpers import get_reference_image, assert_identical_image, test_font


def test_canvas_background():
Expand All @@ -28,8 +28,8 @@ def test_canvas_background():
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')
draw.text((36, 22), 'Background', fill='white', font=test_font)
draw.text((52, 32), 'Test', fill='white', font=test_font)

assert_identical_image(reference, device.image, img_path)

Expand Down
20 changes: 10 additions & 10 deletions tests/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from luma.core.virtual import terminal

from helpers import (get_reference_image, assert_identical_image,
get_reference_font)
get_reference_font, test_font)


def assert_text(device, term, reference_img, text, save=None):
Expand All @@ -34,7 +34,7 @@ def assert_text(device, term, reference_img, text, save=None):
def test_default_text():
reference = 'quick_brown_fox.png'
device = dummy()
term = terminal(device)
term = terminal(device, font=test_font)

assert_text(device, term, reference, [
"The quick brown fox jumps over the lazy dog"
Expand All @@ -44,7 +44,7 @@ def test_default_text():
def test_wrapped_text():
reference = 'quick_brown_fox_word_wrap.png'
device = dummy()
term = terminal(device, word_wrap=True, animate=False)
term = terminal(device, font=test_font, word_wrap=True, animate=False)

assert_text(device, term, reference, [
"The quick brown fox jumps over the lazy dog"
Expand All @@ -54,7 +54,7 @@ def test_wrapped_text():
def test_tab_alignment():
reference = 'tab_align.png'
device = dummy()
term = terminal(device, animate=False)
term = terminal(device, font=test_font, animate=False)

assert_text(device, term, reference, [
"1\t32\t999",
Expand All @@ -65,7 +65,7 @@ def test_tab_alignment():
def test_control_chars():
reference = 'control_chars.png'
device = dummy()
term = terminal(device, animate=False)
term = terminal(device, font=test_font, animate=False)

assert_text(device, term, reference, [
'foo\rbar\bspam\teggs\n\nham and cheese on rye'
Expand All @@ -75,7 +75,7 @@ def test_control_chars():
def test_scrolling():
reference = 'scroll_text.png'
device = dummy()
term = terminal(device, animate=False)
term = terminal(device, font=test_font, animate=False)

assert_text(device, term, reference, [
"it oozed over the blackness, and heard Harris's sleepy voice asking "
Expand All @@ -89,7 +89,7 @@ def test_scrolling():
def test_alt_colors():
reference = 'alt_colors.png'
device = dummy()
term = terminal(device, color="blue", bgcolor="grey", animate=False)
term = terminal(device, font=test_font, color="blue", bgcolor="grey", animate=False)

assert_text(device, term, reference, [
"blue on grey"
Expand All @@ -99,7 +99,7 @@ def test_alt_colors():
def test_ansi_colors():
reference = 'ansi_colors.png'
device = dummy()
term = terminal(device, animate=False)
term = terminal(device, font=test_font, animate=False)

assert_text(device, term, reference, [
"hello \033[31mworld\033[0m ansi colors here!",
Expand All @@ -111,7 +111,7 @@ def test_ansi_colors():
def test_ansi_colors_wrapped():
reference = 'ansi_colors_wrapped.png'
device = dummy()
term = terminal(device, word_wrap=True, animate=False)
term = terminal(device, font=test_font, word_wrap=True, animate=False)

assert_text(device, term, reference, [
"hello \033[31mworld\033[0m ansi colors\t\033[32mwrap\033[0m\t?",
Expand All @@ -123,7 +123,7 @@ def test_ansi_colors_wrapped():
def test_ansi_colors_scroll():
reference = 'ansi_colors_scroll.png'
device = dummy()
term = terminal(device, word_wrap=True, animate=False)
term = terminal(device, font=test_font, word_wrap=True, animate=False)

assert_text(device, term, reference, [
"hello \033[31mworld\033[0m ansi colors\t\033[32mwrap\033[0m\t?",
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Copyright (c) 2017-2023 Richard Hull and contributors
# Copyright (c) 2017-2024 Richard Hull and contributors
# See LICENSE.rst for details.

[tox]
envlist = py{37,38,39,310,311,312},qa,doc
envlist = py{37,38,39,310,311,312,313},qa,doc
skip_missing_interpreters = True

[testenv]
Expand Down

0 comments on commit 5b271cb

Please sign in to comment.