[go: up one dir, main page]

File: test_terminal.py

package info (click to toggle)
luma.core 2.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,040 kB
  • sloc: python: 6,186; makefile: 204
file content (157 lines) | stat: -rw-r--r-- 4,232 bytes parent folder | download | duplicates (2)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2017-18 Richard Hull and contributors
# See LICENSE.rst for details.

"""
Tests for the :py:class:`luma.core.virtual.terminal` class.
"""

from PIL import Image

from luma.core.device import dummy
from luma.core.virtual import terminal

from helpers import (get_reference_image, assert_identical_image,
    get_reference_font)

import pytest

def assert_text(device, term, reference_img, text, save=None):
    pytest.skip()
    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)


def test_default_text():
    pytest.skip()
    reference = 'quick_brown_fox.png'
    device = dummy()
    term = terminal(device)

    assert_text(device, term, reference, [
        "The quick brown fox jumps over the lazy dog"
    ])


def test_wrapped_text():
    pytest.skip()
    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"
    ])


def test_tab_alignment():
    pytest.skip()
    reference = 'tab_align.png'
    device = dummy()
    term = terminal(device, animate=False)

    assert_text(device, term, reference, [
        "1\t32\t999",
        "999\t1\t32"
    ])


def test_control_chars():
    pytest.skip()
    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'
    ])


def test_scrolling():
    pytest.skip()
    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."
    ])


def test_alt_colors():
    pytest.skip()
    reference = 'alt_colors.png'
    device = dummy()
    term = terminal(device, color="blue", bgcolor="grey", animate=False)

    assert_text(device, term, reference, [
        "blue on grey"
    ])


def test_ansi_colors():
    pytest.skip()
    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 test_ansi_colors_wrapped():
    pytest.skip()
    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"
    ])


def test_ansi_colors_scroll():
    pytest.skip()
    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"
    ])


def test_accented_charset():
    pytest.skip()
    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 Текст на русском"
    ])