aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/tests/QtCore
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside2/tests/QtCore')
-rw-r--r--sources/pyside2/tests/QtCore/CMakeLists.txt5
-rw-r--r--sources/pyside2/tests/QtCore/qfileread_test.py82
-rw-r--r--sources/pyside2/tests/QtCore/qmimedatabase_test.py5
-rw-r--r--sources/pyside2/tests/QtCore/qobject_test.py13
-rw-r--r--sources/pyside2/tests/QtCore/qregularexpression_test.py56
-rw-r--r--sources/pyside2/tests/QtCore/qurl_test.py132
-rw-r--r--sources/pyside2/tests/QtCore/qurlquery_test.py59
-rw-r--r--sources/pyside2/tests/QtCore/quuid_test.py45
-rw-r--r--sources/pyside2/tests/QtCore/qversionnumber_test.py48
9 files changed, 395 insertions, 50 deletions
diff --git a/sources/pyside2/tests/QtCore/CMakeLists.txt b/sources/pyside2/tests/QtCore/CMakeLists.txt
index 9e66ebc0a..3a08cb45b 100644
--- a/sources/pyside2/tests/QtCore/CMakeLists.txt
+++ b/sources/pyside2/tests/QtCore/CMakeLists.txt
@@ -61,6 +61,7 @@ PYSIDE_TEST(qenum_test.py)
PYSIDE_TEST(qevent_test.py)
PYSIDE_TEST(qfileinfo_test.py)
PYSIDE_TEST(qfile_test.py)
+PYSIDE_TEST(qfileread_test.py)
PYSIDE_TEST(qflags_test.py)
PYSIDE_TEST(qinstallmsghandler_test.py)
PYSIDE_TEST(qlinef_test.py)
@@ -85,6 +86,7 @@ PYSIDE_TEST(qprocess_test.py)
PYSIDE_TEST(qproperty_decorator.py)
PYSIDE_TEST(qrect_test.py)
PYSIDE_TEST(qregexp_test.py)
+PYSIDE_TEST(qregularexpression_test.py)
PYSIDE_TEST(qresource_test.py)
PYSIDE_TEST(qsize_test.py)
PYSIDE_TEST(qslot_object_test.py)
@@ -105,6 +107,9 @@ PYSIDE_TEST(qtimer_timeout_test.py)
PYSIDE_TEST(qtimezone_test.py)
PYSIDE_TEST(qtnamespace_test.py)
PYSIDE_TEST(qurl_test.py)
+PYSIDE_TEST(qurlquery_test.py)
+PYSIDE_TEST(quuid_test.py)
+PYSIDE_TEST(qversionnumber_test.py)
PYSIDE_TEST(repr_test.py)
PYSIDE_TEST(setprop_on_ctor_test.py)
PYSIDE_TEST(staticMetaObject_test.py)
diff --git a/sources/pyside2/tests/QtCore/qfileread_test.py b/sources/pyside2/tests/QtCore/qfileread_test.py
new file mode 100644
index 000000000..3912fe7e6
--- /dev/null
+++ b/sources/pyside2/tests/QtCore/qfileread_test.py
@@ -0,0 +1,82 @@
+#############################################################################
+##
+## Copyright (C) 2018 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the test suite of PySide2.
+##
+## $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$
+##
+#############################################################################
+
+import unittest
+
+import os
+
+from PySide2.QtCore import QIODevice, QTemporaryFile
+
+class FileChild1(QTemporaryFile):
+ pass
+
+class FileChild2(QTemporaryFile):
+ def readData(self, maxlen):
+ return super(FileChild2, self).readData(maxlen)
+ def readLineData(self, maxlen):
+ return super(FileChild2, self).readLineData(maxlen)
+
+class readDataTest(unittest.TestCase):
+ '''Test case for readData and readLineData'''
+
+ def setUp(self):
+ '''Acquire resources'''
+ self.filename1 = FileChild1()
+ self.assertTrue(self.filename1.open())
+ self.filename1.write('Test text for testing')
+
+ self.filename2 = FileChild2()
+ self.assertTrue(self.filename2.open())
+ self.filename2.write('Test text for testing')
+
+ def tearDown(self):
+ '''release resources'''
+ pass
+
+ def testBasic(self):
+ '''QTemporaryFile.read'''
+ self.filename1.seek(0)
+ s1 = self.filename1.read(50)
+ self.assertEqual(s1, 'Test text for testing')
+
+
+ def testBug40(self):
+ self.filename2.seek(0)
+ s2 = self.filename2.read(50)
+ self.assertEqual(s2, 'Test text for testing')
+
+ self.filename2.seek(0)
+ s2 = self.filename2.readLine(22)
+ self.assertEqual(s2, 'Test text for testing')
+
+ self.filename1.seek(0)
+ s1 = self.filename1.read(50)
+ self.assertEqual(s1, s2)
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside2/tests/QtCore/qmimedatabase_test.py b/sources/pyside2/tests/QtCore/qmimedatabase_test.py
index 7bd9a4586..4c3ae220d 100644
--- a/sources/pyside2/tests/QtCore/qmimedatabase_test.py
+++ b/sources/pyside2/tests/QtCore/qmimedatabase_test.py
@@ -34,7 +34,7 @@ import unittest
import ctypes
import sys
-from PySide2.QtCore import QMimeDatabase
+from PySide2.QtCore import QMimeDatabase, QLocale
class QMimeDatabaseTest(unittest.TestCase):
def testMimeTypeForName(self):
@@ -43,7 +43,8 @@ class QMimeDatabaseTest(unittest.TestCase):
s0 = db.mimeTypeForName("application/x-zerosize")
self.assertTrue(s0.isValid())
self.assertEqual(s0.name(), "application/x-zerosize")
- self.assertEqual(s0.comment(), "empty document")
+ if "en" in QLocale().name():
+ self.assertEqual(s0.comment(), "empty document")
s0Again = db.mimeTypeForName("application/x-zerosize")
self.assertEqual(s0Again.name(), s0.name())
diff --git a/sources/pyside2/tests/QtCore/qobject_test.py b/sources/pyside2/tests/QtCore/qobject_test.py
index 482ae78be..bafa8a643 100644
--- a/sources/pyside2/tests/QtCore/qobject_test.py
+++ b/sources/pyside2/tests/QtCore/qobject_test.py
@@ -34,7 +34,12 @@
import unittest
import py3kcompat as py3k
-from PySide2.QtCore import QObject
+from PySide2.QtCore import QObject, Signal, Qt
+
+class Obj(QObject):
+ signal = Signal()
+ def empty(self):
+ pass
class ObjectNameCase(unittest.TestCase):
'''Tests related to QObject object name'''
@@ -67,6 +72,12 @@ class ObjectNameCase(unittest.TestCase):
obj.setObjectName(name)
self.assertEqual(obj.objectName(), name)
+ def testUniqueConnection(self):
+ obj = Obj()
+ # On first connect, UniqueConnection returns True, and on the second
+ # it must return False, and not a RuntimeError (PYSIDE-34)
+ self.assertTrue(obj.signal.connect(obj.empty, Qt.UniqueConnection))
+ self.assertFalse(obj.signal.connect(obj.empty, Qt.UniqueConnection))
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside2/tests/QtCore/qregularexpression_test.py b/sources/pyside2/tests/QtCore/qregularexpression_test.py
new file mode 100644
index 000000000..e11b9b61c
--- /dev/null
+++ b/sources/pyside2/tests/QtCore/qregularexpression_test.py
@@ -0,0 +1,56 @@
+#!/usr/bin/python
+
+#############################################################################
+##
+## Copyright (C) 2017 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the test suite of PySide2.
+##
+## $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$
+##
+#############################################################################
+
+'''Unit tests for QRegularExpression'''
+
+import unittest
+from PySide2.QtCore import QRegularExpression, QRegularExpressionMatch, QRegularExpressionMatchIterator
+
+class QRegularExpressionTest(unittest.TestCase):
+
+ def testMatch(self):
+ re = QRegularExpression('^.*(word2).*$')
+ self.assertTrue(re.isValid())
+ match = re.match('word1 word2 word3')
+ self.assertTrue(match.isValid())
+ self.assertEqual(match.captured(1), 'word2')
+
+ def testMatchIterator(self):
+ re = QRegularExpression('(\w+)')
+ self.assertTrue(re.isValid())
+ count = 0
+ it = re.globalMatch('word1 word2 word3');
+ while it.hasNext():
+ it.next()
+ count = count + 1
+ self.assertEqual(count, 3)
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside2/tests/QtCore/qurl_test.py b/sources/pyside2/tests/QtCore/qurl_test.py
index 595e5931f..d5eb37d6e 100644
--- a/sources/pyside2/tests/QtCore/qurl_test.py
+++ b/sources/pyside2/tests/QtCore/qurl_test.py
@@ -33,6 +33,7 @@
import unittest
from PySide2.QtCore import QUrl
+from PySide2.QtCore import QUrlQuery
class QUrlBasicConstructor(unittest.TestCase):
'''Tests the basic constructors'''
@@ -67,59 +68,96 @@ class QUrlBasicConstructor(unittest.TestCase):
self.assertEqual(url.toString(),
'ftp://john:abc123@www.google.com:8080/mail/view')
+class QueryItemsTest(unittest.TestCase):
+ '''Test query item management'''
+
+ def testQueryItems(self):
+ url = QUrl('http://www.google.com/search?q=python&hl=en')
+ valid_data = [(('q'), ('python')), (('hl'), ('en'))]
+
+ self.assertEqual(sorted(QUrlQuery(url.query()).queryItems()), sorted(valid_data))
+
+ def testEncodedQueryItems(self):
+ url = QUrl('http://www.google.com/search?q=python&hl=en')
+ valid_data = [(('q'), ('python')), (('hl'), ('en'))]
+
+ self.assertEqual(sorted(QUrlQuery(url.query()).queryItems()), sorted(valid_data))
+
+ def testSetQueryItems(self):
+ urla = QUrl('http://www.google.com/search?q=python&hl=en')
+ urlb = QUrl('http://www.google.com/search')
+
+ urlb.setQuery(urla.query())
+
+ self.assertEqual(urla, urlb)
+
+ def testAddQueryItem(self):
+ url = QUrlQuery()
+ valid_data = [('hl', 'en'), ('user', 'konqui')]
+
+ url.addQueryItem(*valid_data[0])
+ self.assertEqual(url.queryItems()[0], valid_data[0])
+
+ url.addQueryItem(*valid_data[1])
+ self.assertEqual(sorted(url.queryItems()), sorted(valid_data))
+
+ def testAllQueryItemsValues(self):
+ url = QUrlQuery()
+ key = 'key'
+ valid_data = ['data', 'valid', 'test']
+
+ for i, data in enumerate(valid_data):
+ url.addQueryItem(key, data)
+ self.assertEqual(url.allQueryItemValues(key),
+ list(valid_data[:i+1]))
+
def testPath(self):
url = QUrl("http://qt-project.org/images/ban/pgs_front.jpg")
self.assertEqual(url.path(), "/images/ban/pgs_front.jpg")
# PYSIDE-345: No bindings for QUrlQuery
-# class QueryItemsTest(unittest.TestCase):
-# '''Test query item management'''
-#
-# def testQueryItems(self):
-# #QUrl.queryItems
-# url = QUrl('http://www.google.com/search?q=python&hl=en')
-# valid_data = [(('q'), ('python')), (('hl'), ('en'))]
-#
-# self.assertEqual(sorted(url.queryItems()), sorted(valid_data))
-#
-# def testEncodedQueryItems(self):
-# #QUrl.encodedQueryItems
-# url = QUrl('http://www.google.com/search?q=python&hl=en')
-# valid_data = [(('q'), ('python')), (('hl'), ('en'))]
-#
-# self.assertEqual(sorted(url.encodedQueryItems()), sorted(valid_data))
-#
-# def testSetQueryItems(self):
-# #QUrl.setQueryItems
-# urla = QUrl('http://www.google.com/search?q=python&hl=en')
-# urlb = QUrl('http://www.google.com/search')
-#
-# urlb.setQueryItems(urla.queryItems())
-#
-# self.assertEqual(urla, urlb)
-#
-# def testAddQueryItem(self):
-# #QUrl.addQueryItem
-# url = QUrl()
-# valid_data = [('hl', 'en'), ('user', 'konqui')]
-#
-# url.addQueryItem(*valid_data[0])
-# self.assertEqual(url.queryItems()[0], valid_data[0])
-#
-# url.addQueryItem(*valid_data[1])
-# self.assertEqual(sorted(url.queryItems()), sorted(valid_data))
-#
-# def testAllEncodedQueryItemsValues(self):
-# #QUrl.allEncodedQueryItemValues
-# url = QUrl()
-# key = 'key'
-# valid_data = ['data', 'valid', 'test']
-#
-# for i, data in enumerate(valid_data):
-# url.addQueryItem(key, data)
-# self.assertEqual(url.allEncodedQueryItemValues(key),
-# list(valid_data[:i+1]))
+class QueryItemsTest(unittest.TestCase):
+ '''Test query item management'''
+
+ def testQueryItems(self):
+ url = QUrl('http://www.google.com/search?q=python&hl=en')
+ valid_data = [(('q'), ('python')), (('hl'), ('en'))]
+
+ self.assertEqual(sorted(QUrlQuery(url.query()).queryItems()), sorted(valid_data))
+
+ def testEncodedQueryItems(self):
+ url = QUrl('http://www.google.com/search?q=python&hl=en')
+ valid_data = [(('q'), ('python')), (('hl'), ('en'))]
+
+ self.assertEqual(sorted(QUrlQuery(url.query()).queryItems()), sorted(valid_data))
+
+ def testSetQueryItems(self):
+ urla = QUrl('http://www.google.com/search?q=python&hl=en')
+ urlb = QUrl('http://www.google.com/search')
+
+ urlb.setQuery(urla.query())
+
+ self.assertEqual(urla, urlb)
+
+ def testAddQueryItem(self):
+ url = QUrlQuery()
+ valid_data = [('hl', 'en'), ('user', 'konqui')]
+
+ url.addQueryItem(*valid_data[0])
+ self.assertEqual(url.queryItems()[0], valid_data[0])
+
+ url.addQueryItem(*valid_data[1])
+ self.assertEqual(sorted(url.queryItems()), sorted(valid_data))
+
+ def testAllQueryItemsValues(self):
+ url = QUrlQuery()
+ key = 'key'
+ valid_data = ['data', 'valid', 'test']
+ for i, data in enumerate(valid_data):
+ url.addQueryItem(key, data)
+ self.assertEqual(url.allQueryItemValues(key),
+ list(valid_data[:i+1]))
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside2/tests/QtCore/qurlquery_test.py b/sources/pyside2/tests/QtCore/qurlquery_test.py
new file mode 100644
index 000000000..e42856e6d
--- /dev/null
+++ b/sources/pyside2/tests/QtCore/qurlquery_test.py
@@ -0,0 +1,59 @@
+#!/usr/bin/python
+
+#############################################################################
+##
+## Copyright (C) 2017 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the test suite of PySide2.
+##
+## $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$
+##
+#############################################################################
+
+'''Unit tests for QUrlQuery'''
+
+import unittest
+import ctypes
+import sys
+
+from PySide2.QtCore import QUrlQuery
+
+class QUrlQueryTest(unittest.TestCase):
+ def testConstructing(self):
+ empty = QUrlQuery()
+ self.assertTrue(empty.isEmpty())
+ self.assertEqual(empty.queryPairDelimiter(), QUrlQuery.defaultQueryPairDelimiter())
+ self.assertEqual(empty.queryValueDelimiter(), QUrlQuery.defaultQueryValueDelimiter())
+
+ empty.clear();
+ self.assertTrue(empty.isEmpty())
+
+ def testAddRemove(self):
+ query = QUrlQuery()
+
+ query.addQueryItem("a", "b");
+ self.assertTrue(not query.isEmpty())
+ self.assertTrue(query.hasQueryItem("a"))
+ self.assertEqual(query.queryItemValue("a"), "b")
+ self.assertEqual(query.allQueryItemValues("a"), ["b"])
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside2/tests/QtCore/quuid_test.py b/sources/pyside2/tests/QtCore/quuid_test.py
new file mode 100644
index 000000000..64183884a
--- /dev/null
+++ b/sources/pyside2/tests/QtCore/quuid_test.py
@@ -0,0 +1,45 @@
+#!/usr/bin/python
+
+#############################################################################
+##
+## Copyright (C) 2017 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the test suite of PySide2.
+##
+## $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$
+##
+#############################################################################
+
+'''Unit tests for QUuid'''
+
+import unittest
+
+from PySide2.QtCore import QUuid
+
+class QUuidTest(unittest.TestCase):
+ def testFromString(self):
+ uuidString = '{fc69b59e-cc34-4436-a43c-ee95d128b8c5}'
+ uuid = QUuid(uuidString)
+ self.assertTrue(not uuid.isNull())
+ self.assertEqual(uuid.toString(), uuidString)
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside2/tests/QtCore/qversionnumber_test.py b/sources/pyside2/tests/QtCore/qversionnumber_test.py
new file mode 100644
index 000000000..929772fa6
--- /dev/null
+++ b/sources/pyside2/tests/QtCore/qversionnumber_test.py
@@ -0,0 +1,48 @@
+#!/usr/bin/python
+
+#############################################################################
+##
+## Copyright (C) 2017 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the test suite of PySide2.
+##
+## $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$
+##
+#############################################################################
+
+'''Unit tests for QVersionNumber'''
+
+import unittest
+
+from PySide2.QtCore import QVersionNumber
+
+class QVersionNumberTest(unittest.TestCase):
+ def testFromString(self):
+ versionString = '5.9.2'
+ version = QVersionNumber.fromString(versionString)
+ self.assertTrue(not version.isNull())
+ self.assertEqual(version.majorVersion(), 5)
+ self.assertEqual(version.minorVersion(), 9)
+ self.assertEqual(version.microVersion(), 2)
+ self.assertEqual(version.toString(), versionString)
+
+if __name__ == '__main__':
+ unittest.main()