mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-10-29 17:50:37 +00:00
Use with in a few more tests
This commit is contained in:
@@ -49,28 +49,28 @@ def test_device_init_twice_different_pin():
|
|||||||
|
|
||||||
def test_device_close():
|
def test_device_close():
|
||||||
device = GPIODevice(2)
|
device = GPIODevice(2)
|
||||||
|
# Don't use "with" here; we're testing close explicitly
|
||||||
device.close()
|
device.close()
|
||||||
assert device.closed
|
assert device.closed
|
||||||
assert device.pin is None
|
assert device.pin is None
|
||||||
|
|
||||||
def test_device_reopen_same_pin():
|
def test_device_reopen_same_pin():
|
||||||
pin = Device._pin_factory.pin(2)
|
pin = Device._pin_factory.pin(2)
|
||||||
device = GPIODevice(pin)
|
with GPIODevice(pin) as device:
|
||||||
device.close()
|
pass
|
||||||
device2 = GPIODevice(pin)
|
with GPIODevice(pin) as device2:
|
||||||
assert not device2.closed
|
assert not device2.closed
|
||||||
assert device2.pin is pin
|
assert device2.pin is pin
|
||||||
assert device.closed
|
assert device.closed
|
||||||
assert device.pin is None
|
assert device.pin is None
|
||||||
device2.close()
|
|
||||||
|
|
||||||
def test_device_repr():
|
def test_device_repr():
|
||||||
with GPIODevice(2) as device:
|
with GPIODevice(2) as device:
|
||||||
assert repr(device) == '<gpiozero.GPIODevice object on pin %s, is_active=False>' % device.pin
|
assert repr(device) == '<gpiozero.GPIODevice object on pin %s, is_active=False>' % device.pin
|
||||||
|
|
||||||
def test_device_repr_after_close():
|
def test_device_repr_after_close():
|
||||||
device = GPIODevice(2)
|
with GPIODevice(2) as device:
|
||||||
device.close()
|
pass
|
||||||
assert repr(device) == '<gpiozero.GPIODevice object closed>'
|
assert repr(device) == '<gpiozero.GPIODevice object closed>'
|
||||||
|
|
||||||
def test_device_unknown_attr():
|
def test_device_unknown_attr():
|
||||||
|
|||||||
Reference in New Issue
Block a user