mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-10-29 17:50:37 +00:00
Merge pull request #446 from lurch/traffic_lights_tweak
Add extra TrafficLight tests, and remove the redundant setattr function
This commit is contained in:
@@ -710,13 +710,6 @@ class TrafficLights(LEDBoard):
|
||||
name = 'amber'
|
||||
return super(TrafficLights, self).__getattr__(name)
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
if name == 'amber' and self._display_yellow:
|
||||
name = 'yellow'
|
||||
elif name == 'yellow' and not self._display_yellow:
|
||||
name = 'amber'
|
||||
return super(TrafficLights, self).__setattr__(name, value)
|
||||
|
||||
|
||||
class PiTraffic(TrafficLights):
|
||||
"""
|
||||
|
||||
@@ -555,6 +555,10 @@ def test_traffic_lights():
|
||||
assert red_pin.state
|
||||
assert not amber_pin.state
|
||||
assert not green_pin.state
|
||||
board.amber.on()
|
||||
assert amber_pin.state
|
||||
board.yellow.off()
|
||||
assert not amber_pin.state
|
||||
with TrafficLights(red=red_pin, yellow=amber_pin, green=green_pin) as board:
|
||||
board.yellow.on()
|
||||
assert not board.red.value
|
||||
@@ -564,6 +568,8 @@ def test_traffic_lights():
|
||||
assert not red_pin.state
|
||||
assert amber_pin.state
|
||||
assert not green_pin.state
|
||||
board.amber.off()
|
||||
assert not amber_pin.state
|
||||
|
||||
def test_traffic_lights_bad_init():
|
||||
with pytest.raises(ValueError):
|
||||
|
||||
Reference in New Issue
Block a user