Skip to content

Commit

Permalink
CI: Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Jun 3, 2024
1 parent 8452998 commit a2dc729
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
6 changes: 5 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ def gpiod():

@pytest.fixture(scope='function', autouse=False)
def gpiodevice():
sys.modules['gpiodevice'] = mock.Mock()
gpiodevice = mock.Mock()
gpiodevice.get_pins_for_platform.return_value = [(mock.Mock(), 0), (mock.Mock(), 0)]
gpiodevice.get_pin.return_value = (mock.Mock(), 0)

sys.modules['gpiodevice'] = gpiodevice
yield sys.modules['gpiodevice']
del sys.modules['gpiodevice']

Expand Down
21 changes: 9 additions & 12 deletions tests/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@
import pytest


def test_setup(gpiod):
def test_setup(gpiod, gpiodevice):
"""Test init succeeds and GPIO pins are set up."""
import blinkt
with pytest.raises((RuntimeError, SystemExit)):
blinkt.show()
blinkt.show()


def test_set_pins(gpiod):
def test_set_pins(gpiod, gpiodevice):
import blinkt

with pytest.raises((RuntimeError, SystemExit)):
blinkt.set_pins("PIN1", "PIN2")
blinkt.set_pins("PIN1", "PIN2")


def test_set_pixel(gpiod):
def test_set_pixel(gpiod, gpiodevice):
import blinkt
blinkt.set_brightness(1.0)

Expand All @@ -30,7 +27,7 @@ def test_set_pixel(gpiod):
assert blinkt.get_pixel(2)[0:3] == (0, 0, 255)


def test_set_all_and_clear(gpiod):
def test_set_all_and_clear(gpiod, gpiodevice):
import blinkt
blinkt.set_brightness(1.0)

Expand All @@ -45,7 +42,7 @@ def test_set_all_and_clear(gpiod):
assert blinkt.get_pixel(0)[0:3] == (0, 0, 0)


def test_brightness(gpiod):
def test_brightness(gpiod, gpiodevice):
import blinkt
blinkt.set_brightness(1.0)

Expand All @@ -58,7 +55,7 @@ def test_brightness(gpiod):
blinkt.set_brightness(-1)


def test_show(gpiod, gpiod_request):
def test_show(gpiod, gpiodevice, gpiod_request):
import blinkt

blinkt.clk_lines = gpiod_request
Expand All @@ -73,4 +70,4 @@ def test_show(gpiod, gpiod_request):
mock.call(0, blinkt.Value.INACTIVE), # Dat line low
mock.call(1, blinkt.Value.ACTIVE), # Clock pin high
mock.call(1, blinkt.Value.INACTIVE) # Clock pin low
))
))

0 comments on commit a2dc729

Please sign in to comment.