mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-10-29 17:50:37 +00:00
Run all tests on all platforms
Also renamed GPIOZERO_INPUT_PIN to GPIOZERO_TEST_INPUT_PIN, and fixed up the pigpio factory so it actually raises an exception if the connection fails and we don't try and control the daemon anymore.
This commit is contained in:
@@ -84,6 +84,10 @@ class PiGPIOFactory(PiFactory):
|
|||||||
('software', 'shared'): PiGPIOSoftwareSPIShared,
|
('software', 'shared'): PiGPIOSoftwareSPIShared,
|
||||||
}
|
}
|
||||||
self._connection = pigpio.pi(host, port)
|
self._connection = pigpio.pi(host, port)
|
||||||
|
# Annoyingly, pigpio doesn't raise an exception when it fails to make a
|
||||||
|
# connection; it returns a valid (but disconnected) pi object
|
||||||
|
if self.connection is None:
|
||||||
|
raise IOError('failed to connect to %s:%s' % (host, port))
|
||||||
self._host = host
|
self._host = host
|
||||||
self._port = port
|
self._port = port
|
||||||
self._spis = []
|
self._spis = []
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ except NameError:
|
|||||||
|
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
import subprocess
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -37,20 +36,7 @@ except ImportError:
|
|||||||
# your testing rig requires different pins because the defaults interfere with
|
# your testing rig requires different pins because the defaults interfere with
|
||||||
# attached hardware).
|
# attached hardware).
|
||||||
TEST_PIN = int(os.getenv('GPIOZERO_TEST_PIN', '22'))
|
TEST_PIN = int(os.getenv('GPIOZERO_TEST_PIN', '22'))
|
||||||
INPUT_PIN = int(os.getenv('GPIOZERO_INPUT_PIN', '27'))
|
INPUT_PIN = int(os.getenv('GPIOZERO_TEST_INPUT_PIN', '27'))
|
||||||
|
|
||||||
|
|
||||||
# Skip the entire module if we're not on a Pi
|
|
||||||
def is_a_pi():
|
|
||||||
with io.open('/proc/cpuinfo', 'r') as cpuinfo:
|
|
||||||
for line in cpuinfo:
|
|
||||||
if line.startswith('Hardware'):
|
|
||||||
hardware, colon, soc = line.strip().split(None, 2)
|
|
||||||
return soc in ('BCM2708', 'BCM2709', 'BCM2835', 'BCM2836')
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
pytestmark = pytest.mark.skipif(not is_a_pi(), reason='tests cannot run on non-Pi platforms')
|
|
||||||
del is_a_pi
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(
|
@pytest.fixture(
|
||||||
@@ -58,24 +44,18 @@ del is_a_pi
|
|||||||
params=pkg_resources.get_distribution('gpiozero').get_entry_map('gpiozero_pin_factories').keys())
|
params=pkg_resources.get_distribution('gpiozero').get_entry_map('gpiozero_pin_factories').keys())
|
||||||
def pin_factory(request):
|
def pin_factory(request):
|
||||||
# Constructs each pin factory in turn with some extra logic to ensure
|
# Constructs each pin factory in turn with some extra logic to ensure
|
||||||
# the pigpiod daemon gets started and stopped around the pigpio factory
|
# we skip tests if pigpio is set for remote operation
|
||||||
if request.param == 'pigpio':
|
if request.param == 'pigpio':
|
||||||
try:
|
if os.getenv('PIGPIO_ADDR', 'localhost') != 'localhost':
|
||||||
subprocess.check_call(['sudo', 'systemctl', 'start', 'pigpiod'])
|
pytest.skip("skipped factory pigpio: remote host in PIGPIO_ADDR")
|
||||||
except subprocess.CalledProcessError:
|
|
||||||
pytest.skip("skipped factory pigpio: failed to start pigpiod")
|
|
||||||
try:
|
try:
|
||||||
factory = pkg_resources.load_entry_point('gpiozero', 'gpiozero_pin_factories', request.param)()
|
factory = pkg_resources.load_entry_point('gpiozero', 'gpiozero_pin_factories', request.param)()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if request.param == 'pigpio':
|
|
||||||
subprocess.check_call(['sudo', 'systemctl', 'stop', 'pigpiod'])
|
|
||||||
pytest.skip("skipped factory %s: %s" % (request.param, str(e)))
|
pytest.skip("skipped factory %s: %s" % (request.param, str(e)))
|
||||||
else:
|
else:
|
||||||
Device._set_pin_factory(factory)
|
Device._set_pin_factory(factory)
|
||||||
def fin():
|
def fin():
|
||||||
Device._set_pin_factory(MockFactory())
|
Device._set_pin_factory(MockFactory())
|
||||||
if request.param == 'pigpio':
|
|
||||||
subprocess.check_call(['sudo', 'systemctl', 'stop', 'pigpiod'])
|
|
||||||
request.addfinalizer(fin)
|
request.addfinalizer(fin)
|
||||||
return factory
|
return factory
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user