Skip to content

Commit

Permalink
CI: Fix tests for st7735 rename.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Nov 3, 2023
1 parent 147ccfc commit 47fc5e1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 64 deletions.
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
import pytest


@pytest.fixture(scope='function', autouse=False)
def st7735():
import st7735
yield st7735
del sys.modules['st7735']


@pytest.fixture(scope='function', autouse=False)
def GPIO():
"""Mock RPi.GPIO module."""
Expand Down
15 changes: 4 additions & 11 deletions tests/test_dimensions.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
from tools import force_reimport


def test_128_64_0(GPIO, spidev, numpy):
force_reimport('ST7735')
import ST7735
display = ST7735.ST7735(port=0, cs=0, dc=24, width=128, height=64, rotation=0)
def test_128_64_0(GPIO, spidev, numpy, st7735):
display = st7735.ST7735(port=0, cs=0, dc=24, width=128, height=64, rotation=0)
assert display.width == 128
assert display.height == 64


def test_128_64_90(GPIO, spidev, numpy):
force_reimport('ST7735')
import ST7735
display = ST7735.ST7735(port=0, cs=0, dc=24, width=128, height=64, rotation=90)
def test_128_64_90(GPIO, spidev, numpy, st7735):
display = st7735.ST7735(port=0, cs=0, dc=24, width=128, height=64, rotation=90)
assert display.width == 64
assert display.height == 128
19 changes: 6 additions & 13 deletions tests/test_features.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
import mock
from tools import force_reimport


def test_display(GPIO, spidev, numpy):
force_reimport('ST7735')
import ST7735
display = ST7735.ST7735(port=0, cs=0, dc=24)
def test_display(GPIO, spidev, numpy, st7735):
display = st7735.ST7735(port=0, cs=0, dc=24)
numpy.dstack().flatten().tolist.return_value = [0xff, 0x00, 0xff, 0x00]
display.display(mock.MagicMock())

spidev.SpiDev().xfer3.assert_called_with([0xff, 0x00, 0xff, 0x00])


def test_color565(GPIO, spidev, numpy):
force_reimport('ST7735')
import ST7735
assert ST7735.color565(255, 255, 255) == 0xFFFF
def test_color565(GPIO, spidev, numpy, st7735):
assert st7735.color565(255, 255, 255) == 0xFFFF


def test_image_to_data(GPIO, spidev, numpy):
force_reimport('ST7735')
def test_image_to_data(GPIO, spidev, numpy, st7735):
numpy.dstack().flatten().tolist.return_value = []
import ST7735
assert ST7735.image_to_data(mock.MagicMock()) == []
assert st7735.image_to_data(mock.MagicMock()) == []
25 changes: 8 additions & 17 deletions tests/test_setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import mock
from tools import force_reimport


def test_setup(GPIO, spidev, numpy):
force_reimport('ST7735')
import ST7735
display = ST7735.ST7735(port=0, cs=0, dc=24)
def test_setup(GPIO, spidev, numpy, st7735):
display = st7735.ST7735(port=0, cs=0, dc=24)
del display

GPIO.output.assert_has_calls([
Expand All @@ -14,17 +11,13 @@ def test_setup(GPIO, spidev, numpy):
], any_order=True)


def test_setup_no_invert(GPIO, spidev, numpy):
force_reimport('ST7735')
import ST7735
display = ST7735.ST7735(port=0, cs=0, dc=24, invert=False)
def test_setup_no_invert(GPIO, spidev, numpy, st7735):
display = st7735.ST7735(port=0, cs=0, dc=24, invert=False)
del display


def test_setup_with_backlight(GPIO, spidev, numpy):
force_reimport('ST7735')
import ST7735
display = ST7735.ST7735(port=0, cs=0, dc=24, backlight=4)
def test_setup_with_backlight(GPIO, spidev, numpy, st7735):
display = st7735.ST7735(port=0, cs=0, dc=24, backlight=4)
GPIO.setup.assert_called_with(4, GPIO.OUT)

display.set_backlight(GPIO.HIGH)
Expand All @@ -39,9 +32,7 @@ def test_setup_with_backlight(GPIO, spidev, numpy):
], any_order=True)


def test_setup_with_reset(GPIO, spidev, numpy):
force_reimport('ST7735')
import ST7735
display = ST7735.ST7735(port=0, cs=0, dc=24, rst=4)
def test_setup_with_reset(GPIO, spidev, numpy, st7735):
display = st7735.ST7735(port=0, cs=0, dc=24, rst=4)
GPIO.setup.assert_called_with(4, GPIO.OUT)
del display
23 changes: 0 additions & 23 deletions tests/tools.py

This file was deleted.

0 comments on commit 47fc5e1

Please sign in to comment.