diff options
Diffstat (limited to 'sources/pyside6/tests/QtGui')
-rw-r--r-- | sources/pyside6/tests/QtGui/CMakeLists.txt | 13 | ||||
-rw-r--r-- | sources/pyside6/tests/QtGui/bug_493.py (renamed from sources/pyside6/tests/QtGui/bug_480.py) | 31 | ||||
-rw-r--r-- | sources/pyside6/tests/QtGui/bug_785.py | 66 | ||||
-rw-r--r-- | sources/pyside6/tests/QtGui/event_filter_test.py | 76 | ||||
-rw-r--r-- | sources/pyside6/tests/QtGui/qbrush_test.py (renamed from sources/pyside6/tests/QtGui/bug_300_test.py) | 26 | ||||
-rw-r--r-- | sources/pyside6/tests/QtGui/qimage_test.py | 312 | ||||
-rw-r--r-- | sources/pyside6/tests/QtGui/qpen_test.py (renamed from sources/pyside6/tests/QtGui/bug_PYSIDE-41.py) | 63 | ||||
-rw-r--r-- | sources/pyside6/tests/QtGui/qpixmap_constructor.py | 286 | ||||
-rw-r--r-- | sources/pyside6/tests/QtGui/qshortcut_test.py | 87 | ||||
-rw-r--r-- | sources/pyside6/tests/QtGui/qstandarditemmodel_test.py | 110 | ||||
-rw-r--r-- | sources/pyside6/tests/QtGui/qstring_qkeysequence_test.py | 69 |
11 files changed, 1078 insertions, 61 deletions
diff --git a/sources/pyside6/tests/QtGui/CMakeLists.txt b/sources/pyside6/tests/QtGui/CMakeLists.txt index dc3056643..d652af4fc 100644 --- a/sources/pyside6/tests/QtGui/CMakeLists.txt +++ b/sources/pyside6/tests/QtGui/CMakeLists.txt @@ -1,8 +1,7 @@ #Keep this in alphabetical sort -PYSIDE_TEST(bug_300_test.py) PYSIDE_TEST(bug_367.py) -PYSIDE_TEST(bug_480.py) +PYSIDE_TEST(bug_493.py) PYSIDE_TEST(bug_606.py) PYSIDE_TEST(bug_617.py) PYSIDE_TEST(bug_652.py) @@ -10,13 +9,15 @@ PYSIDE_TEST(bug_660.py) PYSIDE_TEST(bug_716.py) PYSIDE_TEST(bug_740.py) PYSIDE_TEST(bug_743.py) +PYSIDE_TEST(bug_785.py) PYSIDE_TEST(bug_991.py) PYSIDE_TEST(bug_1091.py) -PYSIDE_TEST(bug_PYSIDE-41.py) PYSIDE_TEST(bug_PYSIDE-344.py) PYSIDE_TEST(deepcopy_test.py) +PYSIDE_TEST(event_filter_test.py) PYSIDE_TEST(float_to_int_implicit_conversion_test.py) PYSIDE_TEST(pyside_reload_test.py) +PYSIDE_TEST(qbrush_test.py) PYSIDE_TEST(qcolor_test.py) PYSIDE_TEST(qcolor_reduce_test.py) PYSIDE_TEST(qcursor_test.py) @@ -26,10 +27,13 @@ PYSIDE_TEST(qfont_test.py) PYSIDE_TEST(qfontmetrics_test.py) PYSIDE_TEST(qguiapplication_test.py) PYSIDE_TEST(qicon_test.py) +PYSIDE_TEST(qimage_test.py) PYSIDE_TEST(qitemselection_test.py) PYSIDE_TEST(qpainter_test.py) +PYSIDE_TEST(qpen_test.py) PYSIDE_TEST(qpdfwriter_test.py) PYSIDE_TEST(qpixelformat_test.py) +PYSIDE_TEST(qpixmap_constructor.py) PYSIDE_TEST(qpixmap_test.py) PYSIDE_TEST(qpixmapcache_test.py) PYSIDE_TEST(qpolygonf_test.py) @@ -37,6 +41,9 @@ PYSIDE_TEST(qkeysequence_test.py) PYSIDE_TEST(qradialgradient_test.py) PYSIDE_TEST(qrasterwindow_test.py) PYSIDE_TEST(qregion_test.py) +PYSIDE_TEST(qshortcut_test.py) +PYSIDE_TEST(qstandarditemmodel_test.py) +PYSIDE_TEST(qstring_qkeysequence_test.py) PYSIDE_TEST(qstylehints_test.py) PYSIDE_TEST(qtextdocument_functions.py) PYSIDE_TEST(qtextdocument_undoredo_test.py) diff --git a/sources/pyside6/tests/QtGui/bug_480.py b/sources/pyside6/tests/QtGui/bug_493.py index cd3fd1d6b..f0eabd551 100644 --- a/sources/pyside6/tests/QtGui/bug_480.py +++ b/sources/pyside6/tests/QtGui/bug_493.py @@ -35,30 +35,23 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from PySide6.QtWidgets import (QApplication, QGridLayout, QLabel, QVBoxLayout, - QWidget) +from PySide6.QtCore import Qt, QEvent +from PySide6.QtGui import QGuiApplication, QKeyEvent, QKeySequence -class BuggyWidget(QWidget): - def setup(self): - self.verticalLayout = QVBoxLayout(self) - self.gridLayout = QGridLayout() - self.lbl = QLabel(self) - self.gridLayout.addWidget(self.lbl, 0, 1, 1, 1) +class TestBug493(unittest.TestCase): - # this cause a segfault during the ownership transfer - self.verticalLayout.addLayout(self.gridLayout) + def testIt(self): + # We need a qapp otherwise Qt will crash when trying to detect the + # current platform + app = QGuiApplication([]) + ev1 = QKeyEvent(QEvent.KeyRelease, Qt.Key_Delete, Qt.NoModifier) + ev2 = QKeyEvent(QEvent.KeyRelease, Qt.Key_Copy, Qt.NoModifier) + ks = QKeySequence.Delete - -class LayoutTransferOwnerShip(unittest.TestCase): - def testBug(self): - app = QApplication([]) - w = BuggyWidget() - w.setup() - w.show() - self.assertTrue(True) + self.assertTrue(ev1.matches(ks)) + self.assertFalse(ev2.matches(ks)) if __name__ == '__main__': unittest.main() - diff --git a/sources/pyside6/tests/QtGui/bug_785.py b/sources/pyside6/tests/QtGui/bug_785.py new file mode 100644 index 000000000..e2193c3b9 --- /dev/null +++ b/sources/pyside6/tests/QtGui/bug_785.py @@ -0,0 +1,66 @@ +############################################################################# +## +## Copyright (C) 2016 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$ +## +############################################################################# + +import os +import sys +import unittest + +from pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from init_paths import init_test_paths +init_test_paths(False) + +from PySide6.QtCore import QItemSelection +from PySide6.QtGui import QStandardItemModel, QStandardItem + + +class Bug324(unittest.TestCase): + def testOperators(self): + model = QStandardItemModel() + for i in range(100): + model.appendRow(QStandardItem(f"Item: {i}")) + + first = model.index(0, 0) + second = model.index(10, 0) + third = model.index(20, 0) + fourth = model.index(30, 0) + + sel = QItemSelection(first, second) + sel2 = QItemSelection() + sel2.select(third, fourth) + + sel3 = sel + sel2 # check operator + + self.assertEqual(len(sel3), 2) + sel4 = sel + sel4 += sel2 # check operator += + self.assertEqual(len(sel4), 2) + self.assertEqual(sel4, sel3) + + +if __name__ == "__main__": + unittest.main() diff --git a/sources/pyside6/tests/QtGui/event_filter_test.py b/sources/pyside6/tests/QtGui/event_filter_test.py new file mode 100644 index 000000000..a64386e12 --- /dev/null +++ b/sources/pyside6/tests/QtGui/event_filter_test.py @@ -0,0 +1,76 @@ +############################################################################# +## +## Copyright (C) 2016 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$ +## +############################################################################# + +import os +import sys +import unittest + +from pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from init_paths import init_test_paths +init_test_paths(False) + +from helper.usesqguiapplication import UsesQGuiApplication +from PySide6.QtCore import QObject, QEvent +from PySide6.QtGui import QWindow + + +class MyFilter(QObject): + def eventFilter(self, obj, event): + if event.type() == QEvent.KeyPress: + pass + return QObject.eventFilter(self, obj, event) + + +class EventFilter(UsesQGuiApplication): + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") + def testRefCount(self): + o = QObject() + filt = MyFilter() + o.installEventFilter(filt) + self.assertEqual(sys.getrefcount(o), 2) + + o.installEventFilter(filt) + self.assertEqual(sys.getrefcount(o), 2) + + o.removeEventFilter(filt) + self.assertEqual(sys.getrefcount(o), 2) + + def testObjectDestructorOrder(self): + w = QWindow() + filt = MyFilter() + filt.app = self.app + w.installEventFilter(filt) + w.show() + w.close() + w = None + self.assertTrue(True) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtGui/bug_300_test.py b/sources/pyside6/tests/QtGui/qbrush_test.py index 9a708f903..2fae5eaf2 100644 --- a/sources/pyside6/tests/QtGui/bug_300_test.py +++ b/sources/pyside6/tests/QtGui/qbrush_test.py @@ -26,6 +26,8 @@ ## ############################################################################# +'''Test cases for QBrush''' + import os import sys import unittest @@ -35,19 +37,23 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from PySide6.QtCore import QModelIndex, QStringListModel +from PySide6.QtCore import Qt +from PySide6.QtGui import QColor, QBrush + +from helper.usesqguiapplication import UsesQGuiApplication + +class Constructor(UsesQGuiApplication): + '''Test case for constructor of QBrush''' -class TestQAbstractItemModelSignals(unittest.TestCase): - def sigCallback(self, index, r, c): - self._called = True + def testQColor(self): + # QBrush(QColor) constructor + color = QColor('black') + obj = QBrush(color) + self.assertEqual(obj.color(), color) - def testSignals(self): - self._called = False - m = QStringListModel() - m.rowsAboutToBeInserted[QModelIndex, int, int].connect(self.sigCallback) - m.insertRows(0, 3) - self.assertTrue(self._called) + obj = QBrush(Qt.blue) + self.assertEqual(obj.color(), Qt.blue) if __name__ == '__main__': diff --git a/sources/pyside6/tests/QtGui/qimage_test.py b/sources/pyside6/tests/QtGui/qimage_test.py new file mode 100644 index 000000000..b2dd7304a --- /dev/null +++ b/sources/pyside6/tests/QtGui/qimage_test.py @@ -0,0 +1,312 @@ +############################################################################# +## +## Copyright (C) 2016 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 QImage''' + +import os +import sys +import unittest + +from pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from init_paths import init_test_paths +init_test_paths(False) + +from PySide6.QtGui import QImage +from helper.usesqguiapplication import UsesQGuiApplication + + +xpm = [ + "27 22 206 2", + " c None", + ". c #FEFEFE", + "+ c #FFFFFF", + "@ c #F9F9F9", + "# c #ECECEC", + "$ c #D5D5D5", + "% c #A0A0A0", + "& c #767676", + "* c #525252", + "= c #484848", + "- c #4E4E4E", + "; c #555555", + "> c #545454", + ", c #5A5A5A", + "' c #4B4B4B", + ") c #4A4A4A", + "! c #4F4F4F", + "~ c #585858", + "{ c #515151", + "] c #4C4C4C", + "^ c #B1B1B1", + "/ c #FCFCFC", + "( c #FDFDFD", + "_ c #C1C1C1", + ": c #848484", + "< c #616161", + "[ c #5E5E5E", + "} c #CECECE", + "| c #E2E2E2", + "1 c #E4E4E4", + "2 c #DFDFDF", + "3 c #D2D2D2", + "4 c #D8D8D8", + "5 c #D4D4D4", + "6 c #E6E6E6", + "7 c #F1F1F1", + "8 c #838383", + "9 c #8E8E8E", + "0 c #8F8F8F", + "a c #CBCBCB", + "b c #CCCCCC", + "c c #E9E9E9", + "d c #F2F2F2", + "e c #EDEDED", + "f c #B5B5B5", + "g c #A6A6A6", + "h c #ABABAB", + "i c #BBBBBB", + "j c #B0B0B0", + "k c #EAEAEA", + "l c #6C6C6C", + "m c #BCBCBC", + "n c #F5F5F5", + "o c #FAFAFA", + "p c #B6B6B6", + "q c #F3F3F3", + "r c #CFCFCF", + "s c #FBFBFB", + "t c #CDCDCD", + "u c #DDDDDD", + "v c #999999", + "w c #F0F0F0", + "x c #2B2B2B", + "y c #C3C3C3", + "z c #A4A4A4", + "A c #D7D7D7", + "B c #E7E7E7", + "C c #6E6E6E", + "D c #9D9D9D", + "E c #BABABA", + "F c #AEAEAE", + "G c #898989", + "H c #646464", + "I c #BDBDBD", + "J c #CACACA", + "K c #2A2A2A", + "L c #212121", + "M c #B7B7B7", + "N c #F4F4F4", + "O c #737373", + "P c #828282", + "Q c #4D4D4D", + "R c #000000", + "S c #151515", + "T c #B2B2B2", + "U c #D6D6D6", + "V c #D3D3D3", + "W c #2F2F2F", + "X c #636363", + "Y c #A1A1A1", + "Z c #BFBFBF", + "` c #E0E0E0", + " . c #6A6A6A", + ".. c #050505", + "+. c #A3A3A3", + "@. c #202020", + "#. c #5F5F5F", + "$. c #B9B9B9", + "%. c #C7C7C7", + "&. c #D0D0D0", + "*. c #3E3E3E", + "=. c #666666", + "-. c #DBDBDB", + ";. c #424242", + ">. c #C2C2C2", + ",. c #1A1A1A", + "'. c #2C2C2C", + "). c #F6F6F6", + "!. c #AAAAAA", + "~. c #DCDCDC", + "{. c #2D2D2D", + "]. c #2E2E2E", + "^. c #A7A7A7", + "/. c #656565", + "(. c #333333", + "_. c #464646", + ":. c #C4C4C4", + "<. c #B8B8B8", + "[. c #292929", + "}. c #979797", + "|. c #EFEFEF", + "1. c #909090", + "2. c #8A8A8A", + "3. c #575757", + "4. c #676767", + "5. c #C5C5C5", + "6. c #7A7A7A", + "7. c #797979", + "8. c #989898", + "9. c #EEEEEE", + "0. c #707070", + "a. c #C8C8C8", + "b. c #111111", + "c. c #AFAFAF", + "d. c #474747", + "e. c #565656", + "f. c #E3E3E3", + "g. c #494949", + "h. c #5B5B5B", + "i. c #222222", + "j. c #353535", + "k. c #D9D9D9", + "l. c #0A0A0A", + "m. c #858585", + "n. c #E5E5E5", + "o. c #0E0E0E", + "p. c #9A9A9A", + "q. c #6F6F6F", + "r. c #868686", + "s. c #060606", + "t. c #1E1E1E", + "u. c #E8E8E8", + "v. c #A5A5A5", + "w. c #0D0D0D", + "x. c #030303", + "y. c #272727", + "z. c #131313", + "A. c #1F1F1F", + "B. c #757575", + "C. c #F7F7F7", + "D. c #414141", + "E. c #080808", + "F. c #6B6B6B", + "G. c #313131", + "H. c #C0C0C0", + "I. c #C9C9C9", + "J. c #0B0B0B", + "K. c #232323", + "L. c #434343", + "M. c #3D3D3D", + "N. c #282828", + "O. c #7C7C7C", + "P. c #252525", + "Q. c #3A3A3A", + "R. c #F8F8F8", + "S. c #1B1B1B", + "T. c #949494", + "U. c #3B3B3B", + "V. c #242424", + "W. c #383838", + "X. c #6D6D6D", + "Y. c #818181", + "Z. c #939393", + "`. c #9E9E9E", + " + c #929292", + ".+ c #7D7D7D", + "++ c #ADADAD", + "@+ c #DADADA", + "#+ c #919191", + "$+ c #E1E1E1", + "%+ c #BEBEBE", + "&+ c #ACACAC", + "*+ c #9C9C9C", + "=+ c #B3B3B3", + "-+ c #808080", + ";+ c #A8A8A8", + ">+ c #393939", + ",+ c #747474", + "'+ c #7F7F7F", + ")+ c #D1D1D1", + "!+ c #606060", + "~+ c #5C5C5C", + "{+ c #686868", + "]+ c #7E7E7E", + "^+ c #787878", + "/+ c #595959", + ". . . + @ # $ % & * = - ; > , ' ) ! ~ { ] ^ / . . + + ", + ". ( + _ : < [ & } | 1 2 $ 3 4 5 3 6 7 + + 8 9 + . + . ", + ". + 0 9 a ( 3 a b c d e c f g h i g j $ k + l m + . + ", + "+ 2 8 n o p | ( q r s . # t + + + u ^ v e w + x + + + ", + "+ y z . @ A k B 7 n + ( s | p 8 C D 2 E 4 + + F G + . ", + "# H I $ J G K L - M N . 2 O P Q R R S T U s s V W j + ", + "X Y Z @ o ` _ g ...+.( 4 @.#.m G $.%.7 &.X *.=.-.;.&.", + "Q >.C ,.'.} e + ).!.k + . + + . ~.{.> ].x f 7 ^./.k (.", + "_.:.4 @ <.[.}.|.1.2.+ + + >.} 4 B + ( @ _ 3.4.5.6.r 7.", + "3.8.9.~ 0.+ a.Q b.+ + c.d.#.=.$ |.b #.e.z ^ ; ^. .f.g.", + "-.h.+ i.S M + # p j.% n 9.5.k.H l.m.V ^.n.o.M + M p.q.", + "7 r.N s.1.R t.<.|.| u.v.~ w.x.E + s y.z.A.B.C.+ 5 D.q ", + ").p.2 E.0.9 F.%.O {._ @.+ + i { [ i.G.H.P I.+ s q.} + ", + ").p.6 J.R b.K.L.M.A.! b.g.K [.R M k + N.I + + >.O.+ . ", + ").8.9.N.P...R R R R E.t.W n.+ Q.R.6 @.| + . + S.+ + . ", + "n }.w T.U.B.<.i.@ Y + + U.+ c u V.= B B 7 u.W.c + . + ", + "N T.# + }.X.Y.,.8.F.8 Z.[.`. +.+}.4 ++@+O.< ~.+ ( . + ", + "d #+1 + _ ~.u.$+b $.y @+| $+%+I.&+k.h W +.9.+ ( . + . ", + "w 0 |.*+. >.<.=+++++p a.p -+;+5.k.>+,+@ + . . + . + + ", + "q '+9.R.^ I.t b %.I.)+4 $+n.I.,+ .|.+ . . . + . + + + ", + ". p !+( + + + + + + E 0. .-+8.f.+ + . . + + . + + + + ", + ". ( A ~+{+]+^+l > /+D f.c q . + . . + + . + + + + + + " +] + + +class QImageTest(UsesQGuiApplication): + '''Test case for calling setPixel with float as argument''' + + def testQImageStringBuffer(self): + '''Test if the QImage signatures receiving string buffers exist.''' + file = Path(__file__).resolve().parent / 'sample.png' + self.assertTrue(file.is_file()) + img0 = QImage(file) + + # btw let's test the bits() method + img1 = QImage(img0.bits(), img0.width(), img0.height(), img0.format()) + self.assertEqual(img0, img1) + img2 = QImage(img0.bits(), img0.width(), img0.height(), img0.bytesPerLine(), img0.format()) + self.assertEqual(img0, img2) + + ## test scanLine method + data1 = img0.scanLine(0) + data2 = img1.scanLine(0) + self.assertEqual(data1, data2) + + def testEmptyBuffer(self): + img = QImage(bytes('', "UTF-8"), 100, 100, QImage.Format_ARGB32) + + def testEmptyStringAsBuffer(self): + img = QImage(bytes('', "UTF-8"), 100, 100, QImage.Format_ARGB32) + + def testXpmConstructor(self): + img = QImage(xpm) + self.assertFalse(img.isNull()) + self.assertEqual(img.width(), 27) + self.assertEqual(img.height(), 22) + + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtGui/bug_PYSIDE-41.py b/sources/pyside6/tests/QtGui/qpen_test.py index d7aea57bf..e8e80d78f 100644 --- a/sources/pyside6/tests/QtGui/bug_PYSIDE-41.py +++ b/sources/pyside6/tests/QtGui/qpen_test.py @@ -26,10 +26,6 @@ ## ############################################################################# -# TODO: -# move this to QtCore -- QStringListModel is part of QtGui and there is no -# simple model class appropriate for this test in QtCore. - import os import sys import unittest @@ -39,40 +35,49 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from PySide6.QtCore import QPersistentModelIndex, QStringListModel - +from helper.usesqguiapplication import UsesQGuiApplication -class TestBugPYSIDE41(unittest.TestCase): +from PySide6.QtCore import Qt, QTimer +from PySide6.QtGui import QPen, QPainter, QRasterWindow - def testIt(self): - # list of single-character strings - strings = list('abcdefghijklmnopqrstuvwxyz') +class Painting(QRasterWindow): + def __init__(self): + super().__init__() + self.penFromEnum = None + self.penFromInteger = None - model = QStringListModel(strings) + def paintEvent(self, event): + painter = QPainter(self) + painter.setPen(Qt.NoPen) + self.penFromEnum = painter.pen() + painter.setPen(int(Qt.NoPen)) + self.penFromInteger = painter.pen() + # PYSIDE-535: PyPy needs an explicit end() or a context manager. + painter.end() + QTimer.singleShot(20, self.close) - # Test hashing of both QModelIndex and QPersistentModelIndex - indexFunctions = [] - indexFunctions.append(model.index) - indexFunctions.append(lambda i: QPersistentModelIndex(model.index(i))) - for indexFunction in indexFunctions: +class QPenTest(UsesQGuiApplication): - # If two objects compare equal, their hashes MUST also be equal. (The - # reverse is not a requirement.) - for i, _ in enumerate(strings): - index1 = indexFunction(i) - index2 = indexFunction(i) - self.assertEqual(index1, index2) - self.assertEqual(hash(index1), hash(index2)) + def testCtorWithCreatedEnums(self): + '''A simple case of QPen creation using created enums.''' + width = 0 + style = Qt.PenStyle(0) + cap = Qt.PenCapStyle(0) + join = Qt.PenJoinStyle(0) + pen = QPen(Qt.blue, width, style, cap, join) - # Adding the full set of indexes to itself is a no-op. - allIndexes1 = set(indexFunction(i) for i, _ in enumerate(strings)) - allIndexes2 = set(indexFunction(i) for i, _ in enumerate(strings)) - allIndexesCombined = allIndexes1 & allIndexes2 - self.assertEqual(allIndexes1, allIndexesCombined) - self.assertEqual(allIndexes2, allIndexesCombined) + def testSetPenWithPenStyleEnum(self): + '''Calls QPainter.setPen with both enum and integer. Bug #511.''' + w = Painting() + w.show() + w.setTitle("qpen_test") + self.app.exec() + self.assertEqual(w.penFromEnum.style(), Qt.NoPen) + self.assertEqual(w.penFromInteger.style(), Qt.SolidLine) if __name__ == '__main__': unittest.main() + diff --git a/sources/pyside6/tests/QtGui/qpixmap_constructor.py b/sources/pyside6/tests/QtGui/qpixmap_constructor.py new file mode 100644 index 000000000..32c649568 --- /dev/null +++ b/sources/pyside6/tests/QtGui/qpixmap_constructor.py @@ -0,0 +1,286 @@ +#!/usr/bin/python + +############################################################################# +## +## Copyright (C) 2016 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$ +## +############################################################################# + +import os +import sys +import unittest + +from pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from init_paths import init_test_paths +init_test_paths(False) + +from PySide6.QtGui import QPixmap + +from helper.usesqguiapplication import UsesQGuiApplication + +xpm = [ + "27 22 206 2", + " c None", + ". c #FEFEFE", + "+ c #FFFFFF", + "@ c #F9F9F9", + "# c #ECECEC", + "$ c #D5D5D5", + "% c #A0A0A0", + "& c #767676", + "* c #525252", + "= c #484848", + "- c #4E4E4E", + "; c #555555", + "> c #545454", + ", c #5A5A5A", + "' c #4B4B4B", + ") c #4A4A4A", + "! c #4F4F4F", + "~ c #585858", + "{ c #515151", + "] c #4C4C4C", + "^ c #B1B1B1", + "/ c #FCFCFC", + "( c #FDFDFD", + "_ c #C1C1C1", + ": c #848484", + "< c #616161", + "[ c #5E5E5E", + "} c #CECECE", + "| c #E2E2E2", + "1 c #E4E4E4", + "2 c #DFDFDF", + "3 c #D2D2D2", + "4 c #D8D8D8", + "5 c #D4D4D4", + "6 c #E6E6E6", + "7 c #F1F1F1", + "8 c #838383", + "9 c #8E8E8E", + "0 c #8F8F8F", + "a c #CBCBCB", + "b c #CCCCCC", + "c c #E9E9E9", + "d c #F2F2F2", + "e c #EDEDED", + "f c #B5B5B5", + "g c #A6A6A6", + "h c #ABABAB", + "i c #BBBBBB", + "j c #B0B0B0", + "k c #EAEAEA", + "l c #6C6C6C", + "m c #BCBCBC", + "n c #F5F5F5", + "o c #FAFAFA", + "p c #B6B6B6", + "q c #F3F3F3", + "r c #CFCFCF", + "s c #FBFBFB", + "t c #CDCDCD", + "u c #DDDDDD", + "v c #999999", + "w c #F0F0F0", + "x c #2B2B2B", + "y c #C3C3C3", + "z c #A4A4A4", + "A c #D7D7D7", + "B c #E7E7E7", + "C c #6E6E6E", + "D c #9D9D9D", + "E c #BABABA", + "F c #AEAEAE", + "G c #898989", + "H c #646464", + "I c #BDBDBD", + "J c #CACACA", + "K c #2A2A2A", + "L c #212121", + "M c #B7B7B7", + "N c #F4F4F4", + "O c #737373", + "P c #828282", + "Q c #4D4D4D", + "R c #000000", + "S c #151515", + "T c #B2B2B2", + "U c #D6D6D6", + "V c #D3D3D3", + "W c #2F2F2F", + "X c #636363", + "Y c #A1A1A1", + "Z c #BFBFBF", + "` c #E0E0E0", + " . c #6A6A6A", + ".. c #050505", + "+. c #A3A3A3", + "@. c #202020", + "#. c #5F5F5F", + "$. c #B9B9B9", + "%. c #C7C7C7", + "&. c #D0D0D0", + "*. c #3E3E3E", + "=. c #666666", + "-. c #DBDBDB", + ";. c #424242", + ">. c #C2C2C2", + ",. c #1A1A1A", + "'. c #2C2C2C", + "). c #F6F6F6", + "!. c #AAAAAA", + "~. c #DCDCDC", + "{. c #2D2D2D", + "]. c #2E2E2E", + "^. c #A7A7A7", + "/. c #656565", + "(. c #333333", + "_. c #464646", + ":. c #C4C4C4", + "<. c #B8B8B8", + "[. c #292929", + "}. c #979797", + "|. c #EFEFEF", + "1. c #909090", + "2. c #8A8A8A", + "3. c #575757", + "4. c #676767", + "5. c #C5C5C5", + "6. c #7A7A7A", + "7. c #797979", + "8. c #989898", + "9. c #EEEEEE", + "0. c #707070", + "a. c #C8C8C8", + "b. c #111111", + "c. c #AFAFAF", + "d. c #474747", + "e. c #565656", + "f. c #E3E3E3", + "g. c #494949", + "h. c #5B5B5B", + "i. c #222222", + "j. c #353535", + "k. c #D9D9D9", + "l. c #0A0A0A", + "m. c #858585", + "n. c #E5E5E5", + "o. c #0E0E0E", + "p. c #9A9A9A", + "q. c #6F6F6F", + "r. c #868686", + "s. c #060606", + "t. c #1E1E1E", + "u. c #E8E8E8", + "v. c #A5A5A5", + "w. c #0D0D0D", + "x. c #030303", + "y. c #272727", + "z. c #131313", + "A. c #1F1F1F", + "B. c #757575", + "C. c #F7F7F7", + "D. c #414141", + "E. c #080808", + "F. c #6B6B6B", + "G. c #313131", + "H. c #C0C0C0", + "I. c #C9C9C9", + "J. c #0B0B0B", + "K. c #232323", + "L. c #434343", + "M. c #3D3D3D", + "N. c #282828", + "O. c #7C7C7C", + "P. c #252525", + "Q. c #3A3A3A", + "R. c #F8F8F8", + "S. c #1B1B1B", + "T. c #949494", + "U. c #3B3B3B", + "V. c #242424", + "W. c #383838", + "X. c #6D6D6D", + "Y. c #818181", + "Z. c #939393", + "`. c #9E9E9E", + " + c #929292", + ".+ c #7D7D7D", + "++ c #ADADAD", + "@+ c #DADADA", + "#+ c #919191", + "$+ c #E1E1E1", + "%+ c #BEBEBE", + "&+ c #ACACAC", + "*+ c #9C9C9C", + "=+ c #B3B3B3", + "-+ c #808080", + ";+ c #A8A8A8", + ">+ c #393939", + ",+ c #747474", + "'+ c #7F7F7F", + ")+ c #D1D1D1", + "!+ c #606060", + "~+ c #5C5C5C", + "{+ c #686868", + "]+ c #7E7E7E", + "^+ c #787878", + "/+ c #595959", + ". . . + @ # $ % & * = - ; > , ' ) ! ~ { ] ^ / . . + + ", + ". ( + _ : < [ & } | 1 2 $ 3 4 5 3 6 7 + + 8 9 + . + . ", + ". + 0 9 a ( 3 a b c d e c f g h i g j $ k + l m + . + ", + "+ 2 8 n o p | ( q r s . # t + + + u ^ v e w + x + + + ", + "+ y z . @ A k B 7 n + ( s | p 8 C D 2 E 4 + + F G + . ", + "# H I $ J G K L - M N . 2 O P Q R R S T U s s V W j + ", + "X Y Z @ o ` _ g ...+.( 4 @.#.m G $.%.7 &.X *.=.-.;.&.", + "Q >.C ,.'.} e + ).!.k + . + + . ~.{.> ].x f 7 ^./.k (.", + "_.:.4 @ <.[.}.|.1.2.+ + + >.} 4 B + ( @ _ 3.4.5.6.r 7.", + "3.8.9.~ 0.+ a.Q b.+ + c.d.#.=.$ |.b #.e.z ^ ; ^. .f.g.", + "-.h.+ i.S M + # p j.% n 9.5.k.H l.m.V ^.n.o.M + M p.q.", + "7 r.N s.1.R t.<.|.| u.v.~ w.x.E + s y.z.A.B.C.+ 5 D.q ", + ").p.2 E.0.9 F.%.O {._ @.+ + i { [ i.G.H.P I.+ s q.} + ", + ").p.6 J.R b.K.L.M.A.! b.g.K [.R M k + N.I + + >.O.+ . ", + ").8.9.N.P...R R R R E.t.W n.+ Q.R.6 @.| + . + S.+ + . ", + "n }.w T.U.B.<.i.@ Y + + U.+ c u V.= B B 7 u.W.c + . + ", + "N T.# + }.X.Y.,.8.F.8 Z.[.`. +.+}.4 ++@+O.< ~.+ ( . + ", + "d #+1 + _ ~.u.$+b $.y @+| $+%+I.&+k.h W +.9.+ ( . + . ", + "w 0 |.*+. >.<.=+++++p a.p -+;+5.k.>+,+@ + . . + . + + ", + "q '+9.R.^ I.t b %.I.)+4 $+n.I.,+ .|.+ . . . + . + + + ", + ". p !+( + + + + + + E 0. .-+8.f.+ + . . + + . + + + + ", + ". ( A ~+{+]+^+l > /+D f.c q . + . . + + . + + + + + + " +] + + +class QStringSequenceTest(UsesQGuiApplication): + def testQPixmapConstructor(self): + pixmap1 = QPixmap(xpm) + self.assertFalse(pixmap1.isNull()) + self.assertEqual(pixmap1.width(), 27) + self.assertEqual(pixmap1.height(), 22) + + +if __name__ == "__main__": + unittest.main() diff --git a/sources/pyside6/tests/QtGui/qshortcut_test.py b/sources/pyside6/tests/QtGui/qshortcut_test.py new file mode 100644 index 000000000..d7e2a9941 --- /dev/null +++ b/sources/pyside6/tests/QtGui/qshortcut_test.py @@ -0,0 +1,87 @@ +# -*- coding: utf-8 -*- + +############################################################################# +## +## Copyright (C) 2016 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 the QShortcut constructor''' + +import os +import sys +import unittest + +from pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from init_paths import init_test_paths +init_test_paths(False) + +from PySide6.QtCore import Qt, QTimer +from PySide6.QtGui import QGuiApplication, QKeySequence, QShortcut, QWindow + + +class Foo(QWindow): + def __init__(self): + super().__init__() + self.ok = False + self.copy = False + + def slot_of_foo(self): + self.ok = True + + def slot_of_copy(self): + self.copy = True + + +class MyShortcut(QShortcut): + def __init__(self, keys, wdg, slot): + QShortcut.__init__(self, keys, wdg, slot) + + def emit_signal(self): + self.activated.emit() + + +class QAppPresence(unittest.TestCase): + + def testQShortcut(self): + self.qapp = QGuiApplication([]) + f = Foo() + + self.sc = MyShortcut(QKeySequence(Qt.Key_Return), f, f.slot_of_foo) + self.scstd = MyShortcut(QKeySequence.Copy, f, f.slot_of_copy) + QTimer.singleShot(0, self.init) + self.qapp.exec() + self.assertEqual(f.ok, True) + self.assertEqual(f.copy, True) + + def init(self): + self.sc.emit_signal() + self.scstd.emit_signal() + self.qapp.quit() + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtGui/qstandarditemmodel_test.py b/sources/pyside6/tests/QtGui/qstandarditemmodel_test.py new file mode 100644 index 000000000..7382d34cf --- /dev/null +++ b/sources/pyside6/tests/QtGui/qstandarditemmodel_test.py @@ -0,0 +1,110 @@ +############################################################################# +## +## Copyright (C) 2021 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$ +## +############################################################################# + +import gc +import os +import sys +import unittest + +from pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from init_paths import init_test_paths +init_test_paths(False) + +from PySide6.QtCore import QObject +from PySide6.QtGui import QStandardItemModel, QStandardItem +from shiboken6 import Shiboken +from helper.usesqguiapplication import UsesQGuiApplication + + +class QStandardItemModelTest(UsesQGuiApplication): + + def setUp(self): + super(QStandardItemModelTest, self).setUp() + self.parent = QObject() + self.model = QStandardItemModel(0, 3, self.parent) + + def tearDown(self): + del self.parent + del self.model + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() + super(QStandardItemModelTest, self).tearDown() + + def testInsertRow(self): + # bug #227 + self.model.insertRow(0) + + def testClear(self): + + model = QStandardItemModel() + root = model.invisibleRootItem() + model.clear() + self.assertFalse(Shiboken.isValid(root)) + + +class QStandardItemModelRef(UsesQGuiApplication): + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") + def testRefCount(self): + model = QStandardItemModel(5, 5) + items = [] + for r in range(5): + row = [] + for c in range(5): + row.append(QStandardItem(f"{r},{c}")) + self.assertEqual(sys.getrefcount(row[c]), 2) + + model.insertRow(r, row) + + for c in range(5): + ref_after = sys.getrefcount(row[c]) + # check if the ref count was incremented after insertRow + self.assertEqual(ref_after, 3) + + items.append(row) + row = None + + for r in range(3): + my_row = model.takeRow(0) + my_row = None + for c in range(5): + # only rest 1 reference + self.assertEqual(sys.getrefcount(items[r][c]), 2) + + my_i = model.item(0, 0) + # ref(my_i) + parent_ref + items list ref + self.assertEqual(sys.getrefcount(my_i), 4) + + model.clear() + # ref(my_i) + self.assertEqual(sys.getrefcount(my_i), 3) + + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtGui/qstring_qkeysequence_test.py b/sources/pyside6/tests/QtGui/qstring_qkeysequence_test.py new file mode 100644 index 000000000..d32498290 --- /dev/null +++ b/sources/pyside6/tests/QtGui/qstring_qkeysequence_test.py @@ -0,0 +1,69 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +############################################################################# +## +## Copyright (C) 2016 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$ +## +############################################################################# + +'''Tests conversions of QString to and from QKeySequence.''' + +import os +import sys +import unittest + +from pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from init_paths import init_test_paths +init_test_paths(False) + +from helper.usesqguiapplication import UsesQGuiApplication + +from PySide6.QtGui import QAction, QKeySequence + + +class QStringQKeySequenceTest(UsesQGuiApplication): + '''Tests conversions of QString to and from QKeySequence.''' + + def testQStringFromQKeySequence(self): + '''Creates a QString from a QKeySequence.''' + keyseq = 'Ctrl+A' + a = QKeySequence(keyseq) + self.assertEqual(a, keyseq) + + def testPythonStringAsQKeySequence(self): + '''Passes a Python string to an argument expecting a QKeySequence.''' + keyseq = 'Ctrl+A' + action = QAction(None) + action.setShortcut(keyseq) + shortcut = action.shortcut() + self.assertTrue(isinstance(shortcut, QKeySequence)) + self.assertEqual(shortcut.toString(), keyseq) + + +if __name__ == '__main__': + unittest.main() + |