aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/tests/pysidetest/new_inherited_functions_test.py
blob: b09a7fb42aeb23ce76759543792306ad21700ef4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#############################################################################
##
## 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$
##
#############################################################################

from __future__ import print_function

import sys
import os
import unittest

import PySide2.QtCore

# This test tests the existence and callability of the newly existing functions,
# after the inheritance was made complete in the course of PYSIDE-331.

def warn_essential(modname):
    print(80 * "*")
    print("*** Warning: '{}' is an essential module! Are you sure to skip it?"
          .format(modname))
    print(80 * "*")

new_functions = """
    PySide2.QtCore.QAbstractItemModel().parent()
    PySide2.QtCore.QAbstractListModel().parent()
    PySide2.QtCore.QAbstractTableModel().parent()
    PySide2.QtCore.QFile().resize(qint64)
    m = PySide2.QtCore.QMutex(); m.tryLock(); m.unlock() # prevent a message "QMutex: destroying locked mutex"
    PySide2.QtCore.QSortFilterProxyModel().parent()
    PySide2.QtCore.QTemporaryFile(tfarg).open(openMode)
"""
try:
    modname = "PySide2.QtGui"
    exec("import " + modname)
    new_functions += """
        PySide2.QtGui.QBitmap().transformed(qMatrix,transformationMode)
        PySide2.QtGui.QStandardItemModel().insertColumn(int,qModelIndex)
        PySide2.QtGui.QStandardItemModel().parent()
        # PySide2.QtGui.QTextList(qTextDocument).setFormat(qTextFormat) # Segmentation fault: 11
        # PySide2.QtGui.QTextTable(qTextDocument).setFormat(qTextFormat) # Segmentation fault: 11
    """
except ImportError:
    warn_essential(modname)
try:
    modname = "PySide2.QtWidgets"
    exec("import " + modname)
    new_functions += """
        PySide2.QtWidgets.QAbstractItemView().update()
        PySide2.QtWidgets.QApplication.palette()
        PySide2.QtWidgets.QApplication.setFont(qFont)
        PySide2.QtWidgets.QApplication.setPalette(qPalette)
        PySide2.QtWidgets.QBoxLayout(direction).addWidget(qWidget)
        PySide2.QtWidgets.QColorDialog().open()
        PySide2.QtWidgets.QDirModel().index(int,int,qModelIndex)
        PySide2.QtWidgets.QDirModel().parent()
        PySide2.QtWidgets.QFileDialog().open()
        PySide2.QtWidgets.QFileSystemModel().index(int,int,qModelIndex)
        PySide2.QtWidgets.QFileSystemModel().parent()
        PySide2.QtWidgets.QFontDialog().open()
        PySide2.QtWidgets.QGestureEvent([]).accept()
        PySide2.QtWidgets.QGestureEvent([]).ignore()
        PySide2.QtWidgets.QGestureEvent([]).isAccepted()
        PySide2.QtWidgets.QGestureEvent([]).setAccepted(bool)
        # PySide2.QtWidgets.QGraphicsView().render(qPaintDevice,qPoint,qRegion,renderFlags) # QPaintDevice: NotImplementedError
        PySide2.QtWidgets.QGridLayout().addWidget(qWidget)
        PySide2.QtWidgets.QHeaderView(orientation).initStyleOption(qStyleOptionFrame)
        PySide2.QtWidgets.QInputDialog().open()
        PySide2.QtWidgets.QLineEdit().addAction(qAction)
        PySide2.QtWidgets.QListWidget().closePersistentEditor(qModelIndex)
        PySide2.QtWidgets.QListWidget().openPersistentEditor(qModelIndex)
        PySide2.QtWidgets.QMessageBox().open()
        PySide2.QtWidgets.QPlainTextEdit.find(quintptr)
        PySide2.QtWidgets.QProgressDialog().open()
        PySide2.QtWidgets.QStackedLayout().widget()
        # PySide2.QtWidgets.QStylePainter().begin(qPaintDevice) # QPaintDevice: NotImplementedError
        PySide2.QtWidgets.QTableWidget().closePersistentEditor(qModelIndex)
        PySide2.QtWidgets.QTableWidget().openPersistentEditor(qModelIndex)
        PySide2.QtWidgets.QTextEdit.find(quintptr)
        PySide2.QtWidgets.QTreeWidget().closePersistentEditor(qModelIndex)
        PySide2.QtWidgets.QTreeWidget().openPersistentEditor(qModelIndex)
    """
except ImportError:
    warn_essential(modname)
try:
    modname = "PySide2.QtPrintSupport"
    exec("import " + modname)
    new_functions += """
        # PySide2.QtPrintSupport.QPageSetupDialog().open() # Segmentation fault: 11
        # PySide2.QtPrintSupport.QPrintDialog().open() # opens the dialog, but works
        PySide2.QtPrintSupport.QPrintDialog().printer()
        PySide2.QtPrintSupport.QPrintPreviewDialog().open() # note: this prints something, but really shouldn't ;-)
    """
except ImportError:
    warn_essential(modname)
try:
    import PySide2.QtHelp
    new_functions += """
        PySide2.QtHelp.QHelpContentModel().parent()
        # PySide2.QtHelp.QHelpIndexModel().createIndex(int,int,quintptr) # returned NULL without setting an error
        # PySide2.QtHelp.QHelpIndexModel().createIndex(int,int,object()) # returned NULL without setting an error
    """
except ImportError:
    pass
try:
    import PySide2.QtQuick
    new_functions += """
        PySide2.QtQuick.QQuickPaintedItem().update()
    """
except ImportError:
    pass


class MainTest(unittest.TestCase):

    def testNewInheriedFunctionsExist(self):
        """
        Run all new method signarures
        """
        for app in "QtWidgets.QApplication", "QtGui.QGuiApplication", "QtCore.QCoreApplication":
            try:
                exec("qApp = PySide2.{0}([]) or PySide2.{0}.instance()".format(app))
                break
            except AttributeError:
                continue
        bool = True
        int = 42
        qint64 = 42
        tfarg = os.path.join(PySide2.QtCore.QDir.tempPath(), "XXXXXX.tmp")
        orientation = PySide2.QtCore.Qt.Orientation()
        openMode = PySide2.QtCore.QIODevice.OpenMode(PySide2.QtCore.QIODevice.ReadOnly)
        qModelIndex = PySide2.QtCore.QModelIndex()
        transformationMode = PySide2.QtCore.Qt.TransformationMode()
        qObject = PySide2.QtCore.QObject()
        qPoint = PySide2.QtCore.QPoint()
        try:
            PySide2.QtGui
            #qPaintDevice = PySide2.QtGui.QPaintDevice()  # NotImplementedError
            qMatrix = PySide2.QtGui.QMatrix()
            qTextDocument = PySide2.QtGui.QTextDocument()
            qTextFormat = PySide2.QtGui.QTextFormat()
            quintptr = long(42) if sys.version_info[0] < 3 else 42
            qFont = PySide2.QtGui.QFont()
            qPalette = PySide2.QtGui.QPalette()
        except AttributeError:
            pass
        try:
            PySide2.QtWidgets
            direction = PySide2.QtWidgets.QBoxLayout.Direction()
            qWidget = PySide2.QtWidgets.QWidget()
            qStyleOptionFrame = PySide2.QtWidgets.QStyleOptionFrame()
            qAction = PySide2.QtWidgets.QAction(qObject)
            renderFlags = PySide2.QtWidgets.QWidget.RenderFlags
        except AttributeError:
            pass

        for func in new_functions.splitlines():
            func = func.strip()
            if func.startswith("#"):
                # this is a crashing or otherwise untestable function
                print(func)
                continue
            try:
                exec(func)
            except NotImplementedError:
                print(func, "# raises NotImplementedError")
            else:
                print(func)

    def testQAppSignatures(self):
        """
        Verify that qApp.palette owns three signatures, especially
        palette() without argument.
        """
        try:
            qApp = (PySide2.QtWidgets.QApplication.instance() or
                    PySide2.QtWidgets.QApplication([]))
        except AttributeError:
            unittest.TestCase().skipTest("this test makes only sense if QtWidgets is available.")
        try:
            PySide2.QtWidgets.QApplication.palette(42) # raises
        except TypeError as e:
            lines = e.args[0].splitlines()
        heading_pos = lines.index("Supported signatures:")
        lines = lines[heading_pos+1:]
        self.assertEqual(len(lines), 3)
        txt = '\n'.join(lines)
        print("Signatures found:")
        print(txt)
        self.assertTrue("palette()" in txt)

if __name__ == '__main__':
    unittest.main()