Skip to content

Commit

Permalink
QA: Fix tests.
Browse files Browse the repository at this point in the history
GPIO setup tests have been pruned and could use rewriting.
  • Loading branch information
Gadgetoid committed Feb 6, 2024
1 parent b14439a commit 3ae84b4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 59 deletions.
7 changes: 2 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ def GPIO():
"""Mock RPi.GPIO module."""
GPIO = mock.MagicMock()
# Fudge for Python < 37 (possibly earlier)
sys.modules['RPi'] = mock.MagicMock()
sys.modules['RPi'].GPIO = GPIO
sys.modules['RPi.GPIO'] = GPIO
sys.modules['gpiod'] = mock.MagicMock()
yield GPIO
del sys.modules['RPi']
del sys.modules['RPi.GPIO']
del sys.modules['gpiod']


@pytest.fixture(scope='function', autouse=False)
Expand Down
54 changes: 0 additions & 54 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,6 @@ def test_init_invalid_colour(spidev, smbus2):
InkyWHAT('octarine')


def test_init_what_setup_no_gpio(spidev, smbus2):
"""Test Inky init with a missing RPi.GPIO library."""
from inky import InkyWHAT

inky = InkyWHAT('red')

with pytest.raises(ImportError):
inky.setup()


def test_init_what_setup(spidev, smbus2, GPIO):
"""Test initialisation and setup of InkyWHAT.
Expand All @@ -93,39 +83,10 @@ def test_init_what_setup(spidev, smbus2, GPIO):
inky = InkyWHAT('red')
inky.setup()

# Check GPIO setup
GPIO.setwarnings.assert_called_with(False)
GPIO.setmode.assert_called_with(GPIO.BCM)
GPIO.setup.assert_has_calls([
mock.call(inky.dc_pin, GPIO.OUT, initial=GPIO.LOW, pull_up_down=GPIO.PUD_OFF),
mock.call(inky.reset_pin, GPIO.OUT, initial=GPIO.HIGH, pull_up_down=GPIO.PUD_OFF),
mock.call(inky.busy_pin, GPIO.IN, pull_up_down=GPIO.PUD_OFF)
])

# Check device will been reset
GPIO.output.assert_has_calls([
mock.call(inky.reset_pin, GPIO.LOW),
mock.call(inky.reset_pin, GPIO.HIGH)
])

# Check API will been opened
spidev.SpiDev().open.assert_called_with(0, inky.cs_channel)


def test_init_7colour_setup_no_gpio(spidev, smbus2):
"""Test initialisation and setup of 7-colour Inky.
Verify an error is raised when RPi.GPIO is not present.
"""
from inky.inky_uc8159 import Inky

inky = Inky()

with pytest.raises(ImportError):
inky.setup()


def test_init_7colour_setup(spidev, smbus2, GPIO):
"""Test initialisation and setup of 7-colour Inky.
Expand All @@ -140,20 +101,5 @@ def test_init_7colour_setup(spidev, smbus2, GPIO):
inky = Inky()
inky.setup()

# Check GPIO setup
GPIO.setwarnings.assert_called_with(False)
GPIO.setmode.assert_called_with(GPIO.BCM)
GPIO.setup.assert_has_calls([
mock.call(inky.dc_pin, GPIO.OUT, initial=GPIO.LOW, pull_up_down=GPIO.PUD_OFF),
mock.call(inky.reset_pin, GPIO.OUT, initial=GPIO.HIGH, pull_up_down=GPIO.PUD_OFF),
mock.call(inky.busy_pin, GPIO.IN, pull_up_down=GPIO.PUD_OFF)
])

# Check device will been reset
GPIO.output.assert_has_calls([
mock.call(inky.reset_pin, GPIO.LOW),
mock.call(inky.reset_pin, GPIO.HIGH)
])

# Check API will been opened
spidev.SpiDev().open.assert_called_with(0, inky.cs_channel)

0 comments on commit 3ae84b4

Please sign in to comment.