mirror of
https://github.com/pimoroni/st7735-python.git
synced 2025-01-05 22:40:25 +03:00
CI: Fix tests for st7735 rename.
This commit is contained in:
@@ -8,6 +8,13 @@ import mock
|
||||
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."""
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()) == []
|
||||
|
||||
@@ -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([
|
||||
@@ -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)
|
||||
@@ -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
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
import sys
|
||||
|
||||
|
||||
def force_reimport(module):
|
||||
"""Force the module under test to be re-imported.
|
||||
|
||||
Because pytest runs all tests within the same scope (this makes me cry)
|
||||
we have to do some manual housekeeping to avoid tests polluting each other.
|
||||
|
||||
Since conftest.py already does some sys.modules mangling I see no reason not to
|
||||
do the same thing here.
|
||||
"""
|
||||
if "." in module:
|
||||
steps = module.split(".")
|
||||
else:
|
||||
steps = [module]
|
||||
|
||||
for i in range(len(steps)):
|
||||
module = ".".join(steps[0:i + 1])
|
||||
try:
|
||||
del sys.modules[module]
|
||||
except KeyError:
|
||||
pass
|
||||
Reference in New Issue
Block a user