diff options
Diffstat (limited to 'sources/pyside2/tests/QtCore')
-rw-r--r-- | sources/pyside2/tests/QtCore/CMakeLists.txt | 2 | ||||
-rw-r--r-- | sources/pyside2/tests/QtCore/bug_826.py | 4 | ||||
-rw-r--r-- | sources/pyside2/tests/QtCore/qabstractitemmodel_test.py | 4 | ||||
-rw-r--r-- | sources/pyside2/tests/QtCore/qcbor_test.py | 74 | ||||
-rw-r--r-- | sources/pyside2/tests/QtCore/qenum_test.py | 18 | ||||
-rw-r--r-- | sources/pyside2/tests/QtCore/qjsondocument_test.py | 56 | ||||
-rw-r--r-- | sources/pyside2/tests/QtCore/qmetaobject_test.py | 6 | ||||
-rw-r--r-- | sources/pyside2/tests/QtCore/qmodelindex_internalpointer_test.py | 23 | ||||
-rw-r--r-- | sources/pyside2/tests/QtCore/qrandomgenerator_test.py | 2 |
9 files changed, 172 insertions, 17 deletions
diff --git a/sources/pyside2/tests/QtCore/CMakeLists.txt b/sources/pyside2/tests/QtCore/CMakeLists.txt index 649e796cc..08e63d043 100644 --- a/sources/pyside2/tests/QtCore/CMakeLists.txt +++ b/sources/pyside2/tests/QtCore/CMakeLists.txt @@ -52,6 +52,7 @@ PYSIDE_TEST(qbytearray_concatenation_operator_test.py) PYSIDE_TEST(qbytearray_operator_iadd_test.py) PYSIDE_TEST(qbytearray_operator_test.py) PYSIDE_TEST(qbytearray_test.py) +PYSIDE_TEST(qcbor_test.py) PYSIDE_TEST(qcollator_test.py) PYSIDE_TEST(qcommandlineparser_test.py) PYSIDE_TEST(qcoreapplication_instance_test.py) @@ -67,6 +68,7 @@ PYSIDE_TEST(qfile_test.py) PYSIDE_TEST(qfileread_test.py) PYSIDE_TEST(qflags_test.py) PYSIDE_TEST(qinstallmsghandler_test.py) +PYSIDE_TEST(qjsondocument_test.py) PYSIDE_TEST(qlinef_test.py) PYSIDE_TEST(qlocale_test.py) PYSIDE_TEST(qlockfile_test.py) 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/qabstractitemmodel_test.py b/sources/pyside2/tests/QtCore/qabstractitemmodel_test.py index 70b610c34..fd8d01c99 100644 --- a/sources/pyside2/tests/QtCore/qabstractitemmodel_test.py +++ b/sources/pyside2/tests/QtCore/qabstractitemmodel_test.py @@ -34,14 +34,12 @@ from PySide2.QtCore import * class MyModel (QAbstractListModel): pass -class Foo: - pass class TestQModelIndexInternalPointer(unittest.TestCase): def testInternalPointer(self): m = MyModel() - foo = Foo() + foo = QObject() idx = m.createIndex(0,0, foo) check = m.checkIndex(idx, QAbstractItemModel.CheckIndexOption.IndexIsValid | QAbstractItemModel.CheckIndexOption.DoNotUseParent diff --git a/sources/pyside2/tests/QtCore/qcbor_test.py b/sources/pyside2/tests/QtCore/qcbor_test.py new file mode 100644 index 000000000..2ac46673a --- /dev/null +++ b/sources/pyside2/tests/QtCore/qcbor_test.py @@ -0,0 +1,74 @@ +#!/usr/bin/python + +############################################################################# +## +## Copyright (C) 2018 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of Qt for Python. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +'''Test cases for QCbor''' + +import unittest + +from PySide2.QtCore import (QByteArray, QCborStreamReader, QCborStreamWriter, + QCborValue) + +class TestCbor(unittest.TestCase): + def testReader(self): + ba = QByteArray() + writer = QCborStreamWriter(ba) + writer.append(42) + del writer + self.assertTrue(not ba.isEmpty()) + reader = QCborStreamReader(ba) + self.assertTrue(reader.hasNext()) + value = reader.toInteger() + self.assertEqual(value, 42) + + def testReader(self): + ba = QByteArray() + writer = QCborStreamWriter(ba) + writer.append("hello") + del writer + self.assertTrue(not ba.isEmpty()) + reader = QCborStreamReader(ba) + self.assertTrue(reader.hasNext()) + if (reader.isByteArray()): # Python 2 + value = reader.readByteArray() + self.assertTrue(value) + self.assertEqual(value.data, "hello") + else: + self.assertTrue(reader.isString()) + value = reader.readString() + self.assertTrue(value) + self.assertEqual(value.data, "hello") + + def testValue(self): + value = QCborValue('hello') + self.assertTrue(value.isString()) + self.assertEqual(value.toString(), 'hello') + +if __name__ == '__main__': + unittest.main() 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/QtCore/qjsondocument_test.py b/sources/pyside2/tests/QtCore/qjsondocument_test.py new file mode 100644 index 000000000..0cd4dc5b2 --- /dev/null +++ b/sources/pyside2/tests/QtCore/qjsondocument_test.py @@ -0,0 +1,56 @@ +#!/usr/bin/python + +############################################################################# +## +## Copyright (C) 2018 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of Qt for Python. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +'''Test cases for QJsonDocument/nullptr_t''' + +import unittest +from PySide2.QtCore import QJsonDocument +import py3kcompat as py3k + +class QJsonDocumentTest(unittest.TestCase): + + def testToVariant(self): + a = QJsonDocument.fromJson(b'{"test": null}') + self.assertIsInstance(a, QJsonDocument) + if py3k.IS_PY3K: + self.assertEqual(str(a.toVariant()), "{'test': None}") + else: + self.assertEqual(str(a.toVariant()), "{u'test': None}") + + b = QJsonDocument.fromJson(b'{"test": [null]}') + self.assertIsInstance(b, QJsonDocument) + if py3k.IS_PY3K: + self.assertEqual(str(b.toVariant()), "{'test': [None]}") + else: + self.assertEqual(str(b.toVariant()), "{u'test': [None]}") + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtCore/qmetaobject_test.py b/sources/pyside2/tests/QtCore/qmetaobject_test.py index 12b5312a6..73ab81c7c 100644 --- a/sources/pyside2/tests/QtCore/qmetaobject_test.py +++ b/sources/pyside2/tests/QtCore/qmetaobject_test.py @@ -78,6 +78,12 @@ class qmetaobject_test(unittest.TestCase): #self.assertTrue(slot_index != signal_index) + # PYSIDE-784, plain Qt objects should not have intermediary + # metaObjects. + def test_PlainQObject(self): + timer = QTimer() + self.assertEqual(timer.metaObject().superClass().className(), + "QObject") if __name__ == '__main__': unittest.main() diff --git a/sources/pyside2/tests/QtCore/qmodelindex_internalpointer_test.py b/sources/pyside2/tests/QtCore/qmodelindex_internalpointer_test.py index 875d2075c..a67bb380a 100644 --- a/sources/pyside2/tests/QtCore/qmodelindex_internalpointer_test.py +++ b/sources/pyside2/tests/QtCore/qmodelindex_internalpointer_test.py @@ -33,6 +33,7 @@ import sys import unittest from PySide2.QtCore import * +from PySide2.support import VoidPtr class MyModel (QAbstractListModel): pass @@ -50,22 +51,22 @@ class TestQModelIndexInternalPointer(unittest.TestCase): def testInternalPointer(self): #Test QAbstractListModel.createIndex and - #QModelIndex.internalPointer with regular - #Python objects - idx = self.model.createIndex(0, 0, "Hello") - self.assertEqual("Hello", idx.internalPointer()) - a = [1, 2, 3] - idx = self.model.createIndex(0, 0, a) - self.assertEqual(a, idx.internalPointer()) + #QModelIndex.internalPointer + obj = QObject() + obj_ptr = VoidPtr(obj) + idx = self.model.createIndex(0, 0, obj) + i = idx.internalPointer() + self.assertEqual(int(obj_ptr), int(i)) def testReferenceCounting(self): #Test reference counting when retrieving data with #QModelIndex.internalPointer - a = [1, 2, 3] - a_refcnt = sys.getrefcount(a) - idx = self.model.createIndex(0, 0, a) + o = QObject() + o_refcnt = sys.getrefcount(o) + idx = self.model.createIndex(0, 0, o) ptr = idx.internalPointer() - self.assertEqual(sys.getrefcount(a), a_refcnt + 1) + self.assertEqual(sys.getrefcount(o), o_refcnt) + def testIndexForDefaultDataArg(self): #Test QAbstractListModel.createIndex with a default diff --git a/sources/pyside2/tests/QtCore/qrandomgenerator_test.py b/sources/pyside2/tests/QtCore/qrandomgenerator_test.py index 7d80510a7..2b732ad5e 100644 --- a/sources/pyside2/tests/QtCore/qrandomgenerator_test.py +++ b/sources/pyside2/tests/QtCore/qrandomgenerator_test.py @@ -3,7 +3,7 @@ ## Copyright (C) 2017 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## -## This file is part of the test suite of PySide2. +## This file is part of the test suite of Qt for Python. ## ## $QT_BEGIN_LICENSE:GPL-EXCEPT$ ## Commercial License Usage |