aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/tests
diff options
context:
space:
mode:
authorCristian Maureira-Fredes <cristian.maureira-fredes@qt.io>2018-11-13 16:36:04 +0100
committerCristian Maureira-Fredes <cristian.maureira-fredes@qt.io>2018-11-20 15:40:22 +0000
commit9ab15abdb293941b41f8ec36889546e8eec38b75 (patch)
tree98b9f252018a6e1892f1a83446dae38c7594b34e /sources/pyside2/tests
parent830fb5792ae7825c4cc5ab45330f39ea7567d73b (diff)
Improve enum type operations implementation
The current implementation of the enum operations, wrongly assumes that the first element is always an enum. This patch add some logic to determinate the types we are dealing with, to allow operations like: 2 + QtCore.Qt.Key.Key_1 which were not accepted before. Float numbers are not accepted for enum operations and a test case was included. Some tests were adapted since they were wrongly implemented. Fixes: PYSIDE-830 Change-Id: I407dca2b7c39fc684dbdac19ad45d259403ebadd Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'sources/pyside2/tests')
-rw-r--r--sources/pyside2/tests/QtCore/bug_826.py4
-rw-r--r--sources/pyside2/tests/QtCore/qenum_test.py18
-rw-r--r--sources/pyside2/tests/QtWidgets/bug_493.py8
3 files changed, 23 insertions, 7 deletions
diff --git a/sources/pyside2/tests/QtCore/bug_826.py b/sources/pyside2/tests/QtCore/bug_826.py
index 5e3a12146..b5701fc5a 100644
--- a/sources/pyside2/tests/QtCore/bug_826.py
+++ b/sources/pyside2/tests/QtCore/bug_826.py
@@ -46,8 +46,8 @@ class TestEvent(QEvent):
class TestEnums(unittest.TestCase):
def testUserTypesValues(self):
- self.assertTrue(QEvent.User <= int(TestEvent.TestEventType) <= QEvent.MaxUser)
- self.assertTrue(QEvent.User <= int(TEST_EVENT_TYPE) <= QEvent.MaxUser)
+ self.assertTrue(QEvent.User <= TestEvent.TestEventType <= QEvent.MaxUser)
+ self.assertTrue(QEvent.User <= TEST_EVENT_TYPE <= QEvent.MaxUser)
def testUserTypesRepr(self):
self.assertEqual(eval(repr(TestEvent.TestEventType)), TestEvent.TestEventType)
diff --git a/sources/pyside2/tests/QtCore/qenum_test.py b/sources/pyside2/tests/QtCore/qenum_test.py
index eccbfac23..ada625f24 100644
--- a/sources/pyside2/tests/QtCore/qenum_test.py
+++ b/sources/pyside2/tests/QtCore/qenum_test.py
@@ -49,6 +49,24 @@ class TestEnum(unittest.TestCase):
def testToIntInFunction(self):
self.assertEqual(str(int(QIODevice.WriteOnly)), "2")
+ def testOperations(self):
+ k = Qt.Key.Key_1
+
+ # Integers
+ self.assertEqual(k + 2, 2 + k)
+ self.assertEqual(k - 2, -(2 - k))
+ self.assertEqual(k * 2, 2 * k)
+
+ # Floats
+ with self.assertRaises(TypeError):
+ a = k+2.0
+
+ with self.assertRaises(TypeError):
+ a = k-2.0
+
+ with self.assertRaises(TypeError):
+ a = k*2.0
+
class TestQFlags(unittest.TestCase):
def testToItn(self):
om = QIODevice.NotOpen
diff --git a/sources/pyside2/tests/QtWidgets/bug_493.py b/sources/pyside2/tests/QtWidgets/bug_493.py
index 100959fbb..19cbb0023 100644
--- a/sources/pyside2/tests/QtWidgets/bug_493.py
+++ b/sources/pyside2/tests/QtWidgets/bug_493.py
@@ -32,7 +32,7 @@ from PySide2.QtWidgets import QApplication
import unittest
-class TestBug569(unittest.TestCase):
+class TestBug493(unittest.TestCase):
def testIt(self):
# We need a qapp otherwise Qt will crash when trying to detect the
@@ -42,10 +42,8 @@ class TestBug569(unittest.TestCase):
ev2 = QKeyEvent(QEvent.KeyRelease, Qt.Key_Copy, Qt.NoModifier)
ks = QKeySequence.Delete
- self.assertEqual(ev1, ks)
- self.assertEqual(ks, ev1)
- self.assertNotEqual(ev2, ks)
- self.assertNotEqual(ks, ev2)
+ self.assertTrue(ev1.matches(ks))
+ self.assertFalse(ev2.matches(ks))
if __name__ == '__main__':
unittest.main()