Make tests work reliably on the Pi

While the tests work well on a PC or Travis, the Pi (where I ought to be
running them!) has some issues with the timing tests. Need to relax the
tolerance of the "assert_states_and_times" method to 0.05 seconds
otherwise it periodically fails even on something reasonably quick like
a Pi 2 (less failures on a Pi 3 but still occasionally).

Also reduced default fps to 25; if the default timing occasionally fails
on a Pi 2 it's evidently too fast for a Pi 1 and shouldn't be the
default; 25 also doesn't look any different to me on a pulsing LED.

There's also a bunch of miscellaneous fixes in here; last minute typos
and chart re-gens for the 1.2 release.
This commit is contained in:
Dave Jones
2016-04-08 11:10:59 +01:00
parent 44422bd6c9
commit c2a9392ea5
28 changed files with 846 additions and 842 deletions

View File

@@ -121,19 +121,3 @@ from .other_devices import (
PingServer,
TimeOfDay,
)
from .source_tools import (
averaged,
clamped,
conjunction,
cos_values,
disjunction,
inverted,
negated,
post_delayed,
pre_delayed,
quantized,
queued,
random_values,
scaled,
sin_values,
)

View File

@@ -258,7 +258,7 @@ class LEDBoard(LEDCollection):
on_time, off_time, fade_in_time, fade_out_time, n, background
)
def _blink_device(self, on_time, off_time, fade_in_time, fade_out_time, n, fps=50):
def _blink_device(self, on_time, off_time, fade_in_time, fade_out_time, n, fps=25):
sequence = []
if fade_in_time > 0:
sequence += [

View File

@@ -107,7 +107,13 @@ class GPIOMeta(type):
try:
old_close()
finally:
del cls._INSTANCES[key]
try:
del cls._INSTANCES[key]
except KeyError:
# If the _refs go negative (too many closes)
# just ignore the resulting KeyError here -
# it's already gone
pass
self.close = close
cls._INSTANCES[key] = weakref.proxy(self)
else:

View File

@@ -374,7 +374,7 @@ class HoldMixin(EventsMixin):
@hold_time.setter
def hold_time(self, value):
if value < 0:
raise BadWaitTime('source_delay must be 0 or greater')
raise BadWaitTime('hold_time must be 0 or greater')
self._hold_time = float(value)
@property
@@ -403,8 +403,8 @@ class HoldMixin(EventsMixin):
The length of time (in seconds) that the device has been held for.
This is counted from the first execution of the :attr:`when_held` event
rather than when the device activated, in contrast to
:attr:`active_time`. If the device is not currently held, this is
``None``.
:attr:`~EventsMixin.active_time`. If the device is not currently held,
this is ``None``.
"""
if self._held_from is not None:
return time() - self._held_from

View File

@@ -19,8 +19,8 @@ class OutputDevice(SourceMixin, GPIODevice):
Represents a generic GPIO output device.
This class extends :class:`GPIODevice` to add facilities common to GPIO
output devices: an :meth:`on` method to switch the device on, and a
corresponding :meth:`off` method.
output devices: an :meth:`on` method to switch the device on, a
corresponding :meth:`off` method, and a :meth:`toggle` method.
:param int pin:
The GPIO pin (in BCM numbering) that the device is connected to. If
@@ -123,10 +123,9 @@ class DigitalOutputDevice(OutputDevice):
"""
Represents a generic output device with typical on/off behaviour.
This class extends :class:`OutputDevice` with a :meth:`toggle` method to
switch the device between its on and off states, and a :meth:`blink` method
which uses an optional background thread to handle toggling the device
state without further interaction.
This class extends :class:`OutputDevice` with a :meth:`blink` method which
uses an optional background thread to handle toggling the device state
without further interaction.
"""
def __init__(self, pin=None, active_high=True, initial_value=False):
self._blink_thread = None
@@ -458,7 +457,7 @@ class PWMOutputDevice(OutputDevice):
self._blink_thread = None
def _blink_device(
self, on_time, off_time, fade_in_time, fade_out_time, n, fps=50):
self, on_time, off_time, fade_in_time, fade_out_time, n, fps=25):
sequence = []
if fade_in_time > 0:
sequence += [
@@ -686,7 +685,7 @@ class RGBLED(SourceMixin, Device):
def _blink_device(
self, on_time, off_time, fade_in_time, fade_out_time, on_color,
off_color, n, fps=50):
off_color, n, fps=25):
# Define some simple lambdas to perform linear interpolation between
# off_color and on_color
lerp = lambda t, fade_in: tuple(

View File

@@ -159,7 +159,7 @@ class MockPin(Pin):
# that's about all we can reasonably expect in a non-realtime
# environment on a Pi 1)
for actual, expected in zip(self.states, expected_states):
assert isclose(actual.timestamp, expected[0], rel_tol=0.01, abs_tol=0.01)
assert isclose(actual.timestamp, expected[0], rel_tol=0.05, abs_tol=0.05)
assert isclose(actual.state, expected[1])