Skip to content

Commit

Permalink
added black formatting and lint to tests/test_display.py
Browse files Browse the repository at this point in the history
  • Loading branch information
qlrd committed Jan 4, 2024
1 parent 4ff4eb2 commit 311998d
Showing 1 changed file with 122 additions and 0 deletions.
122 changes: 122 additions & 0 deletions tests/test_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@
DEFAULT_BG_COLOR = 0x0000 # Black


# pylint: disable=unused-argument
def test_init(mocker, m5stickv):
"""
Test initialization of :class:`krux.display.Display`
in a mocked :mod:`krux.display.lcd`
"""
mocker.patch("krux.display.lcd", new=mocker.MagicMock())
import krux
from krux.display import Display
Expand All @@ -87,6 +92,10 @@ def test_init(mocker, m5stickv):
d.initialize_lcd()

assert isinstance(d, Display)

# :func:`assert_called` is a mocked method
# added by mocker. It needs a pylint disable call
# pylint: disable=no-member
d.initialize_lcd.assert_called()

krux.display.lcd.init.assert_called_once()
Expand All @@ -97,7 +106,12 @@ def test_init(mocker, m5stickv):
)


# pylint: disable=unused-argument
def test_width(mocker, m5stickv):
"""
Test :func:`krux.display.Display.width`
in a mocked :module:`krux.display.lcd`
"""
mocker.patch("krux.display.lcd", new=mocker.MagicMock())
import krux
from krux.display import Display
Expand All @@ -116,7 +130,12 @@ def test_width(mocker, m5stickv):
krux.display.lcd.height.assert_called()


# pylint: disable=unused-argument
def test_height(mocker, m5stickv):
"""
Test :func:`krux.display.Display.height`
in a mocked :module:`krux.display.lcd`
"""
mocker.patch("krux.display.lcd", new=mocker.MagicMock())
import krux
from krux.display import Display
Expand All @@ -134,7 +153,12 @@ def test_height(mocker, m5stickv):
krux.display.lcd.width.assert_called()


# pylint: disable=unused-argument
def test_qr_data_width(mocker, m5stickv):
"""
Test :func:`krux.display.Display.qr_data_width`
in a mocked :module:`krux.display.lcd`
"""
from krux.display import Display

d = Display()
Expand All @@ -150,10 +174,18 @@ def test_qr_data_width(mocker, m5stickv):
mocker.spy(d, "width")
assert d.qr_data_width() == width // 6

# :func:`assert_called` is a mocked method
# added by mocker. It needs a pylint disable call
# pylint: disable=no-member
d.width.assert_called()


# pylint: disable=unused-argument
def test_to_landscape(mocker, m5stickv):
"""
Test :func:`krux.display.Display.to_landscape`
in a mocked :module:`krux.display.lcd`
"""
mocker.patch("krux.display.lcd", new=mocker.MagicMock())
import krux
from krux.display import Display
Expand All @@ -165,7 +197,12 @@ def test_to_landscape(mocker, m5stickv):
krux.display.lcd.rotation.assert_called()


# pylint: disable=unused-argument
def test_to_portrait(mocker, m5stickv):
"""
Test :func:`krux.display.Display.to_portrait`
in a mocked :module:`krux.display.lcd`
"""
mocker.patch("krux.display.lcd", new=mocker.MagicMock())
import krux
from krux.display import Display
Expand All @@ -177,7 +214,12 @@ def test_to_portrait(mocker, m5stickv):
krux.display.lcd.rotation.assert_called()


# pylint: disable=unused-argument
def test_to_lines(mocker, m5stickv):
"""
Test many cases of calling :func:`krux.display.Display.to_lines`
in a mocked :module:`krux.display.lcd`:
"""
from krux.display import Display

cases = [
Expand All @@ -198,6 +240,7 @@ def test_to_lines(mocker, m5stickv):
),
(
135,
# pylint: disable=line-too-long
"tpubDCDuqu5HtBX2aD7wxvnHcj1DgFN1UVgzLkA1Ms4Va4P7TpJ3jDknkPLwWT2SqrKXNNAtJBCPcbJ8Tcpm6nLxgFapCZyhKgqwcEGv1BVpD7s",
[
"tpubDCDuqu5HtBX2",
Expand All @@ -211,6 +254,7 @@ def test_to_lines(mocker, m5stickv):
),
(
135,
# pylint: disable=line-too-long
"xpub: tpubDCDuqu5HtBX2aD7wxvnHcj1DgFN1UVgzLkA1Ms4Va4P7TpJ3jDknkPLwWT2SqrKXNNAtJBCPcbJ8Tcpm6nLxgFapCZyhKgqwcEGv1BVpD7s",
[
"xpub:",
Expand All @@ -226,6 +270,7 @@ def test_to_lines(mocker, m5stickv):
(135, "Log Level\nNONE", ["Log Level", "NONE"]),
(
135,
# pylint: disable=line-too-long
"New firmware detected.\n\nSHA256:\n1621f9c0e9ccb7995a29327066566adfd134e19109d7ce8e52aad7bd7dcce121\n\n\n\nInstall?",
[
"New firmware",
Expand Down Expand Up @@ -258,6 +303,7 @@ def test_to_lines(mocker, m5stickv):
),
(
240,
# pylint: disable=line-too-long
"tpubDCDuqu5HtBX2aD7wxvnHcj1DgFN1UVgzLkA1Ms4Va4P7TpJ3jDknkPLwWT2SqrKXNNAtJBCPcbJ8Tcpm6nLxgFapCZyhKgqwcEGv1BVpD7s",
[
"tpubDCDuqu5HtBX2aD7wxvnHcj1",
Expand All @@ -269,6 +315,7 @@ def test_to_lines(mocker, m5stickv):
),
(
240,
# pylint: disable=line-too-long
"xpub: tpubDCDuqu5HtBX2aD7wxvnHcj1DgFN1UVgzLkA1Ms4Va4P7TpJ3jDknkPLwWT2SqrKXNNAtJBCPcbJ8Tcpm6nLxgFapCZyhKgqwcEGv1BVpD7s",
[
"xpub:",
Expand All @@ -282,6 +329,7 @@ def test_to_lines(mocker, m5stickv):
(240, "Log Level\nNONE", ["Log Level", "NONE"]),
(
240,
# pylint: disable=line-too-long
"New firmware detected.\n\nSHA256:\n1621f9c0e9ccb7995a29327066566adfd134e19109d7ce8e52aad7bd7dcce121\n\n\n\nInstall?",
[
"New firmware detected.",
Expand All @@ -307,7 +355,13 @@ def test_to_lines(mocker, m5stickv):
assert lines == case[2]


# pylint: disable=unused-argument
def test_outline(mocker, m5stickv):
"""
Test :func:`krux.display.Display.to_outline` call
in a mocked :module:`krux.display.lcd` resulting
in :const:`krux.display.lcd.WHITE` in some positions
"""
mocker.patch("krux.display.lcd", new=mocker.MagicMock())
import krux
from krux.display import Display
Expand All @@ -317,6 +371,9 @@ def test_outline(mocker, m5stickv):

d.outline(0, 0, 100, 100, krux.display.lcd.WHITE)

# :func:`assert_has_calls` is a mocked method
# added by mocker. It needs a pylint disable call
# pylint: disable=no-member
d.fill_rectangle.assert_has_calls(
[
mocker.call(0, 0, 101, 1, krux.display.lcd.WHITE),
Expand All @@ -327,7 +384,13 @@ def test_outline(mocker, m5stickv):
)


# pylint: disable=unused-argument
def test_fill_rectangle(mocker, m5stickv):
"""
Test :func:`krux.display.Display.fill_rectangle`
in a mocked :module:`krux.display.lcd` resulting
in :const:`krux.display.lcd.WHITE` in "normal" display
"""
mocker.patch("krux.display.lcd", new=mocker.MagicMock())
import krux
from krux.display import Display
Expand All @@ -341,7 +404,13 @@ def test_fill_rectangle(mocker, m5stickv):
)


# pylint: disable=unused-argument
def test_fill_rectangle_on_inverted_display(mocker, amigo_tft):
"""
Test :func:`krux.display.Display.fill_rectangle`
in a mocked :module:`krux.display.lcd` resulting
in :const:`krux.display.lcd.WHITE` in inverted display
"""
mocker.patch("krux.display.lcd", new=mocker.MagicMock())
import krux
from krux.display import Display
Expand All @@ -356,7 +425,14 @@ def test_fill_rectangle_on_inverted_display(mocker, amigo_tft):
)


# pylint: disable=unused-argument
def test_draw_string(mocker, m5stickv):
"""
Test :func:`krux.display.Display.draw_string`
in a mocked :module:`krux.display.lcd` resulting
in a :const:`krux.display.lcd.WHITE` text within
a :const:`krux.display.lcd.BLACK` background
"""
mocker.patch("krux.display.lcd", new=mocker.MagicMock())
import krux
from krux.display import Display
Expand All @@ -370,7 +446,15 @@ def test_draw_string(mocker, m5stickv):
)


# pylint: disable=unused-argument
def test_draw_string_on_inverted_display(mocker, amigo_tft):
"""
Test :func:`krux.display.Display.draw_string`
in a mocked :module:`krux.display.lcd` resulting
in a :const:`krux.display.lcd.WHITE` text within
a :const:`krux.display.lcd.BLACK` background in a
inverted display
"""
mocker.patch("krux.display.lcd", new=mocker.MagicMock())
import krux
from krux.display import Display
Expand All @@ -385,7 +469,14 @@ def test_draw_string_on_inverted_display(mocker, amigo_tft):
)


# pylint: disable=unused-argument
def test_draw_hcentered_text(mocker, m5stickv):
"""
Test :func:`krux.display.Display.draw_hcentered_text` in
a mocked :module:`krux.display.lcd` resulting in a horizontal
centered :const:`krux.display.lcd.WHITE` text within a
:const:`krux.display.lcd.BLACK` background
"""
mocker.patch("krux.display.lcd", new=mocker.MagicMock())
import krux
from krux.display import Display
Expand All @@ -398,12 +489,22 @@ def test_draw_hcentered_text(mocker, m5stickv):
"Hello world", 50, krux.display.lcd.WHITE, krux.display.lcd.BLACK
)

# :func:`assert_called_with` is a mocked method
# added by mocker. It needs a pylint disable call
# pylint: disable=no-member
d.draw_string.assert_called_with(
23, 50, "Hello world", krux.display.lcd.WHITE, krux.display.lcd.BLACK
)


# pylint: disable=unused-argument
def test_draw_centered_text(mocker, m5stickv):
"""
Test :func:`krux.display.Display.draw_centered_text` in
a mocked :module:`krux.display.lcd` resulting in a
centered :const:`krux.display.lcd.WHITE` text within a
:const:`krux.display.lcd.BLACK` background
"""
mocker.patch("krux.display.lcd", new=mocker.MagicMock())
import krux
from krux.display import Display
Expand All @@ -415,12 +516,21 @@ def test_draw_centered_text(mocker, m5stickv):

d.draw_centered_text("Hello world", krux.display.lcd.WHITE, 0)

# :func:`assert_called_with` is a mocked method
# added by mocker. It needs a pylint disable call
# pylint: disable=no-member
d.draw_hcentered_text.assert_called_with(
"Hello world", 113, krux.display.lcd.WHITE, 0
)


# pylint: disable=unused-argument
def test_flash_text(mocker, m5stickv):
"""
Test :func:`krux.display.Display.flash_text` in
a mocked :module:`krux.display.lcd` resulting in a
:const:`krux.display.lcd.WHITE` text
"""
mocker.patch("krux.display.lcd", new=mocker.MagicMock())
mocker.patch("krux.display.time", new=mocker.MagicMock())
import krux
Expand All @@ -434,12 +544,24 @@ def test_flash_text(mocker, m5stickv):

d.flash_text("Hello world", krux.display.lcd.WHITE, 0, 1000)

# :attr:`call_count` is a mocked attribute
# added by mocker. It needs a pylint disable call
# pylint: disable=no-member
assert d.clear.call_count == 2

# :func:`assert_called_once` is a mocked method
# added by mocker. It needs a pylint disable call
# pylint: disable=no-member
d.draw_centered_text.assert_called_once()
krux.display.time.sleep_ms.assert_called_with(1000)


# pylint: disable=unused-argument
def test_draw_qr_code(mocker, m5stickv):
"""
Test :func:`krux.display.Display.draw_qr_code` in
a mocked :module:`krux.display.lcd`
"""
mocker.patch("krux.display.lcd", new=mocker.MagicMock())
import krux
from krux.display import Display, QR_DARK_COLOR, QR_LIGHT_COLOR
Expand Down

0 comments on commit 311998d

Please sign in to comment.