From 9ab15abdb293941b41f8ec36889546e8eec38b75 Mon Sep 17 00:00:00 2001 From: Cristian Maureira-Fredes Date: Tue, 13 Nov 2018 16:36:04 +0100 Subject: 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 Reviewed-by: Alexandru Croitor --- sources/pyside2/tests/QtCore/bug_826.py | 4 ++-- sources/pyside2/tests/QtCore/qenum_test.py | 18 ++++++++++++++++++ sources/pyside2/tests/QtWidgets/bug_493.py | 8 +++----- 3 files changed, 23 insertions(+), 7 deletions(-) (limited to 'sources/pyside2') 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() -- cgit v1.2.3