aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/tests/QtSensors/sensors.py
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-06-10 21:18:36 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-06-11 06:44:55 +0200
commit4e458e6bc7bf5588498e3cff4ecca25ab403be48 (patch)
treed172419e621fea5043c1ec76ef5932c6c08ef3dc /sources/pyside6/tests/QtSensors/sensors.py
parentd7b13507140a5073503ce73097c2a7b51b5bfe44 (diff)
QtSensors test: Handle failed readings
Failures have been observed on Windows: qt.sensors.winrt: Unable to initialize orientation sensor factory. "CoInitialize has not been called." for i in range(0, reading.valueCount()): AttributeError: 'NoneType' object has no attribute Traceback (most recent call last): Change-Id: I67d2645b722666631c640bea865f2966b3deb130 Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside6/tests/QtSensors/sensors.py')
-rw-r--r--sources/pyside6/tests/QtSensors/sensors.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/sources/pyside6/tests/QtSensors/sensors.py b/sources/pyside6/tests/QtSensors/sensors.py
index 67928b6ec..e0595dba7 100644
--- a/sources/pyside6/tests/QtSensors/sensors.py
+++ b/sources/pyside6/tests/QtSensors/sensors.py
@@ -47,18 +47,25 @@ class QSensorTest(unittest.TestCase):
for sensorType in QSensor.sensorTypes():
identifiers = QSensor.sensorsForType(sensorType)
values = []
- usedIdentifier = None
+ error = ''
for identifier in identifiers:
sensor = QSensor(sensorType, None)
sensor.setIdentifier(identifier)
if sensor.connectToBackend():
usedIdentifier = identifier
reading = sensor.reading()
- for i in range(0, reading.valueCount()):
- values.append(reading.value(i))
- break
- if usedIdentifier:
+ if reading:
+ for i in range(0, reading.valueCount()):
+ values.append(reading.value(i))
+ break
+ else:
+ error = "Unable to obtain reading"
+ else:
+ error = "Unable to connect to backend"
+ if values:
print('Sensor ', sensorType, usedIdentifier, values)
+ else:
+ print(f"{sensorType}: {error}", file=sys.stderr)
if __name__ == '__main__':