1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
# SPDX-FileCopyrightText: All Contributors to the PyTango project
# SPDX-License-Identifier: LGPL-3.0-or-later
"""
Basic unit test for a PowerSupply device with events. Requires pytest.
"""
import time
from tango import EventType
from tango.test_utils import DeviceTestContext
from pytest import approx
from ps0b import PowerSupply
def test_calibrate():
"""Test device calibration and voltage reading."""
with DeviceTestContext(PowerSupply, process=True) as proxy:
proxy.calibrate()
assert proxy.voltage == approx(1.5, abs=0.1)
def test_events():
"""Test change events occur."""
results = []
def callback(evt):
if not evt.err:
results.append(evt)
with DeviceTestContext(PowerSupply, process=True) as proxy:
eid = proxy.subscribe_event(
"voltage", EventType.CHANGE_EVENT, callback, wait=True
)
# wait for events to happen
time.sleep(4) # not ideal in tests!
assert len(results) > 1
proxy.unsubscribe_event(eid)
|