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:
Dave Jones
2016-10-23 21:27:38 +01:00
parent 945bea4e54
commit e5336c38ce
2 changed files with 8 additions and 24 deletions

View File

@@ -84,6 +84,10 @@ class PiGPIOFactory(PiFactory):
('software', 'shared'): PiGPIOSoftwareSPIShared,
}
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._port = port
self._spis = []

View File

@@ -12,7 +12,6 @@ except NameError:
import io
import os
import subprocess
from time import sleep
import pytest
@@ -37,20 +36,7 @@ except ImportError:
# your testing rig requires different pins because the defaults interfere with
# attached hardware).
TEST_PIN = int(os.getenv('GPIOZERO_TEST_PIN', '22'))
INPUT_PIN = int(os.getenv('GPIOZERO_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
INPUT_PIN = int(os.getenv('GPIOZERO_TEST_INPUT_PIN', '27'))
@pytest.fixture(
@@ -58,24 +44,18 @@ del is_a_pi
params=pkg_resources.get_distribution('gpiozero').get_entry_map('gpiozero_pin_factories').keys())
def pin_factory(request):
# 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':
try:
subprocess.check_call(['sudo', 'systemctl', 'start', 'pigpiod'])
except subprocess.CalledProcessError:
pytest.skip("skipped factory pigpio: failed to start pigpiod")
if os.getenv('PIGPIO_ADDR', 'localhost') != 'localhost':
pytest.skip("skipped factory pigpio: remote host in PIGPIO_ADDR")
try:
factory = pkg_resources.load_entry_point('gpiozero', 'gpiozero_pin_factories', request.param)()
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)))
else:
Device._set_pin_factory(factory)
def fin():
Device._set_pin_factory(MockFactory())
if request.param == 'pigpio':
subprocess.check_call(['sudo', 'systemctl', 'stop', 'pigpiod'])
request.addfinalizer(fin)
return factory