aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/tests
diff options
context:
space:
mode:
authorAndreas Buhr <andreas@andreasbuhr.de>2020-05-24 18:18:58 +0200
committerAndreas Buhr <andreas@andreasbuhr.de>2020-05-26 08:40:44 +0200
commitb9a814cc89283a86cbf4c38ea1d00ac5ba283ade (patch)
treef3c86d81fb202482c999f738dad0b2838525f5ea /sources/pyside2/tests
parent49c4d1f31014605c9355b1f6901e28e5762301d1 (diff)
QtSerialPort improved unit tests
Support for QtSerialPort was added to PySide2 recently. However, only very few unit tests were added at that time. This change replicates a part of the C++ unit tests of QtSerialPort in PySide/Python. Change-Id: I7e7a1ee7a521b952a6c0860cd8cceacb3b0b7e57 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside2/tests')
-rw-r--r--sources/pyside2/tests/QtSerialPort/serial.py49
1 files changed, 43 insertions, 6 deletions
diff --git a/sources/pyside2/tests/QtSerialPort/serial.py b/sources/pyside2/tests/QtSerialPort/serial.py
index c30d9eb03..7c0839d8e 100644
--- a/sources/pyside2/tests/QtSerialPort/serial.py
+++ b/sources/pyside2/tests/QtSerialPort/serial.py
@@ -39,20 +39,57 @@ from init_paths import init_test_paths
init_test_paths(False)
from PySide2.QtSerialPort import QSerialPort, QSerialPortInfo
+from PySide2.QtCore import QIODevice
+class QSerialPortTest(unittest.TestCase):
+ def testDefaultConstructedPort(self):
+ serialPort = QSerialPort()
-def callPortInfoMemberFunctions(portinfo):
- portinfo.description()
- portinfo.hasProductIdentifier()
- portinfo.hasVendorIdentifier()
- portinfo.isNull()
+ self.assertEqual(serialPort.error(), QSerialPort.NoError)
+ self.assertTrue(not serialPort.errorString() == "")
+
+ # properties
+ defaultBaudRate = QSerialPort.Baud9600
+ self.assertEqual(serialPort.baudRate(), defaultBaudRate)
+ self.assertEqual(serialPort.baudRate(QSerialPort.Input), defaultBaudRate)
+ self.assertEqual(serialPort.baudRate(QSerialPort.Output), defaultBaudRate)
+ self.assertEqual(serialPort.dataBits(), QSerialPort.Data8)
+ self.assertEqual(serialPort.parity(), QSerialPort.NoParity)
+ self.assertEqual(serialPort.stopBits(), QSerialPort.OneStop)
+ self.assertEqual(serialPort.flowControl(), QSerialPort.NoFlowControl)
+
+ self.assertEqual(serialPort.pinoutSignals(), QSerialPort.NoSignal)
+ self.assertEqual(serialPort.isRequestToSend(), False)
+ self.assertEqual(serialPort.isDataTerminalReady(), False)
+
+ # QIODevice
+ self.assertEqual(serialPort.openMode(), QIODevice.NotOpen)
+ self.assertTrue(not serialPort.isOpen())
+ self.assertTrue(not serialPort.isReadable())
+ self.assertTrue(not serialPort.isWritable())
+ self.assertTrue(serialPort.isSequential())
+ self.assertEqual(serialPort.canReadLine(), False)
+ self.assertEqual(serialPort.pos(), 0)
+ self.assertEqual(serialPort.size(), 0)
+ self.assertTrue(serialPort.atEnd())
+ self.assertEqual(serialPort.bytesAvailable(), 0)
+ self.assertEqual(serialPort.bytesToWrite(), 0)
+
+ def testOpenExisting(self):
+ allportinfos = QSerialPortInfo.availablePorts()
+ for portinfo in allportinfos:
+ serialPort = QSerialPort(portinfo)
+ self.assertEqual(serialPort.portName(), portinfo.portName())
class QSerialPortInfoTest(unittest.TestCase):
def test_available_ports(self):
allportinfos = QSerialPortInfo.availablePorts()
for portinfo in allportinfos:
- callPortInfoMemberFunctions(portinfo)
+ portinfo.description()
+ portinfo.hasProductIdentifier()
+ portinfo.hasVendorIdentifier()
+ portinfo.isNull()
if __name__ == '__main__':
unittest.main()