diff --git a/tests/conftest.py b/tests/conftest.py index db460f7..353ab9d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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'] diff --git a/tests/test_setup.py b/tests/test_setup.py index 0ffd7f5..40ceeb1 100644 --- a/tests/test_setup.py +++ b/tests/test_setup.py @@ -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) @@ -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) @@ -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) @@ -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 @@ -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 - )) \ No newline at end of file + ))