File: test_uc1701x.py

package info (click to toggle)
luma.lcd 2.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,172 kB
  • sloc: python: 2,295; makefile: 204
file content (88 lines) | stat: -rw-r--r-- 2,315 bytes parent folder | download
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2017 Richard Hull and contributors
# See LICENSE.rst for details.

"""
Tests for the :py:class:`luma.lcd.device.uc1701x` device.
"""

from luma.lcd.device import uc1701x
from luma.core.render import canvas

from baseline_data import get_reference_data, primitives
from helpers import serial
from unittest.mock import Mock, call
import pytest


def test_init_128x64():
    """
    UC1701X LCD with a 128 x 64 resolution works correctly.
    """
    uc1701x(serial, gpio=Mock())
    serial.command.assert_has_calls([
        # Initial burst are initialization commands
        call(226),
        call(44),
        call(46),
        call(47),
        call(248, 0),
        call(35),
        call(162),
        call(192),
        call(161),
        call(172),
        call(166),
        call(165),
        call(164),
        # set contrast
        call(129, 44),
        # reset the display
        call(176, 4, 16),
        call(177, 4, 16),
        call(178, 4, 16),
        call(179, 4, 16),
        call(180, 4, 16),
        call(181, 4, 16),
        call(182, 4, 16),
        call(183, 4, 16),
        call(175)])

    # Next 1024 are all data: zero's to clear the RAM
    # (1024 = 128 * 64 / 8)
    serial.data.assert_has_calls([call([0] * 128)] * 8)


def test_display():
    pytest.skip("This test is skipped.")
    """
    UC1701X LCD screen can draw and display an image.
    """
    device = uc1701x(serial, gpio=Mock())
    serial.reset_mock()

    recordings = []

    def data(data):
        recordings.append({'data': data})

    def command(*cmd):
        recordings.append({'command': list(cmd)})

    serial.command = Mock(side_effect=command, unsafe=True)
    serial.data = Mock(side_effect=data, unsafe=True)

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

    serial.data.assert_called()
    serial.command.assert_called()

    # To regenerate test data, uncomment the following (remember not to commit though)
    # ================================================================================
    # from baseline_data import save_reference_data
    # save_reference_data("demo_uc1701x", recordings)

    assert recordings == get_reference_data('demo_uc1701x')