File: test_st7567.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 (74 lines) | stat: -rw-r--r-- 1,928 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2013-17 Richard Hull and contributors
# See LICENSE.rst for details.

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

import pytest

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

from baseline_data import get_reference_data, primitives
from helpers import serial, setup_function, assert_invalid_dimensions  # noqa: F401
from unittest.mock import Mock, call


def test_init_128x64():
    st7567(serial, gpio=Mock())
    serial.command.assert_has_calls([
        call(0xA3),
        call(0xA1),
        call(0xC0),
        call(0xA6),
        call(0x40),
        call(0x2F),
        call(0x22),
        call(0xAF),
        call(0x81, 57)
    ])

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


def test_contrast():
    device = st7567(serial, gpio=Mock())
    serial.reset_mock()
    with pytest.raises(AssertionError):
        device.contrast(300)


def test_display():
    pytest.skip("This test is skipped.")
    device = st7567(serial, gpio=Mock())
    serial.reset_mock()

    recordings = []

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

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

    serial.command.side_effect = command
    serial.data.side_effect = data

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

    assert serial.data.called
    assert serial.command.called

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

    assert recordings == get_reference_data('demo_st7567')