diff options
Diffstat (limited to 'sources/pyside2/tests/util')
29 files changed, 1363 insertions, 0 deletions
diff --git a/sources/pyside2/tests/util/color.py b/sources/pyside2/tests/util/color.py new file mode 100644 index 000000000..e7ab84d0e --- /dev/null +++ b/sources/pyside2/tests/util/color.py @@ -0,0 +1,41 @@ +############################################################################# +## +## Copyright (C) 2016 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 + +'''Function to print a colored line to terminal''' + +RED='\033[0;31m%s\033[m' + +def print_colored(message, color=RED): + print(color % message) + +if __name__ == '__main__': + print('42 - the answer') + print_colored("But what's the question?") + print('Hum?') diff --git a/sources/pyside2/tests/util/helper/__init__.py b/sources/pyside2/tests/util/helper/__init__.py new file mode 100644 index 000000000..ff7af6999 --- /dev/null +++ b/sources/pyside2/tests/util/helper/__init__.py @@ -0,0 +1,160 @@ +############################################################################# +## +## Copyright (C) 2016 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$ +## +############################################################################# + +'''Helper classes and functions''' + +import os +import unittest + +from random import randint + +from PySide2.QtCore import QCoreApplication, QTimer + +try: + from PySide2.QtWidgets import QApplication +except ImportError: + has_gui = False +else: + has_gui = True + +def adjust_filename(filename, orig_mod_filename): + dirpath = os.path.dirname(os.path.abspath(orig_mod_filename)) + return os.path.join(dirpath, filename) + +class NoQtGuiError(Exception): + def __init__(self): + Exception.__init__(self, 'No QtGui found') + +class BasicPySlotCase(object): + '''Base class that tests python slots and signal emissions. + + Python slots are defined as any callable passed to QObject.connect(). + ''' + def setUp(self): + self.called = False + + def tearDown(self): + try: + del self.args + except: + pass + + def cb(self, *args): + '''Simple callback with arbitrary arguments. + + The test function must setup the 'args' attribute with a sequence + containing the arguments expected to be received by this slot. + Currently only a single connection is supported. + ''' + if tuple(self.args) == args: + self.called = True + else: + raise ValueError('Invalid arguments for callback') + + +_instance = None +_timed_instance = None + +if has_gui: + class UsesQApplication(unittest.TestCase): + '''Helper class to provide QApplication instances''' + + qapplication = True + + def setUp(self): + '''Creates the QApplication instance''' + + # Simple way of making instance a singleton + super(UsesQApplication, self).setUp() + global _instance + if _instance is None: + _instance = QApplication([]) + + self.app = _instance + + def tearDown(self): + '''Deletes the reference owned by self''' + del self.app + super(UsesQApplication, self).tearDown() + + + class TimedQApplication(unittest.TestCase): + '''Helper class with timed QApplication exec loop''' + + def setUp(self, timeout=100): + '''Setups this Application. + + timeout - timeout in milisseconds''' + global _timed_instance + if _timed_instance is None: + _timed_instance = QApplication([]) + + self.app = _timed_instance + QTimer.singleShot(timeout, self.app.quit) + + def tearDown(self): + '''Delete resources''' + del self.app +else: + class UsesQApplication(unittest.TestCase): + def setUp(self): + raise NoQtGuiError() + class TimedQapplication(unittest.TestCase): + def setUp(self): + raise NoQtGuiError() + + +_core_instance = None + +class UsesQCoreApplication(unittest.TestCase): + '''Helper class for test cases that require an QCoreApplication + Just connect or call self.exit_app_cb. When called, will ask + self.app to exit. + ''' + + def setUp(self): + '''Set up resources''' + + global _core_instance + if _core_instance is None: + _core_instance = QCoreApplication([]) + + self.app = _core_instance + + def tearDown(self): + '''Release resources''' + del self.app + + def exit_app_cb(self): + '''Quits the application''' + self.app.exit(0) + + +def random_string(size=5): + '''Generate random string with the given size''' + return ''.join(map(chr, [randint(33, 126) for x in range(size)])) diff --git a/sources/pyside2/tests/util/helper/docmodifier.py b/sources/pyside2/tests/util/helper/docmodifier.py new file mode 100644 index 000000000..16d3e28ad --- /dev/null +++ b/sources/pyside2/tests/util/helper/docmodifier.py @@ -0,0 +1,116 @@ +############################################################################# +## +## Copyright (C) 2016 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$ +## +############################################################################# + +'''Helper metaclass do 'decorate' docstrings from base test case classes''' + +import types + + +def copy_func(func): + '''Helper function to copy a function object (except docstring)''' + return types.FunctionType(func.func_code, func.func_globals, func.func_name, + func.func_defaults, func.func_closure) + + +class DocModifier(type): + '''Metaclass for modifiying method documentation. + + It allows the managed class to modify the method documentation, adding + prefixes and suffixes to a given set of methods. + + For example, you have some unittest.TestCases that run on different set + of data. These methods could be written once in a base class and the + inheriting class just setup different setUp/tearDown methods with the + proper data. To differentiate the methods when using docstrings, you + can add a suffix or prefix to the docstring. + + Variables in the implementing class: + + doc_prefix - The prefix to the docstring + doc_suffix - The suffix to the docstring + doc_filter - The function to filter the methods. If not provided, this + no docstrings are changed.''' + + def __new__(mcs, name, bases, dct): + + # FIXME currently we have to define doc_filter on each subclass + filter_function = dct.get('doc_filter') + if not filter_function: + filter_function = lambda x: False + + for base in bases: + for attr in [x for x in base.__dict__ if filter_function(x)]: + original = getattr(base, attr) + + if original.__doc__: + copy = copy_func(original) + copy.__doc__ = (dct.get('doc_prefix', '') + + original.__doc__ + + dct.get('doc_suffix', '')) + dct[attr] = copy + + return type.__new__(mcs, name, bases, dct) + + def __init__(mcs, name, bases, dct): + super(DocModifier, mcs).__init__(name, bases, dct) + + +if __name__ == '__main__': + + # tests + class BaseTest(object): + __metaclass__ = DocModifier + + def testBase(self): + '''base''' + + def testWithoutDoc(self): + pass + + class Implementing(BaseTest): + + doc_filter = lambda x: x.startswith('test') + doc_prefix = 'prefix' + doc_suffix = 'suffix' + + class OnlyPrefix(BaseTest): + + doc_filter = lambda x: x.startswith('test') + doc_prefix = 'prefix' + + class OnlySuffix(BaseTest): + + doc_filter = lambda x: x.startswith('test') + doc_suffix = 'suffix' + + assert(Implementing.testBase.__doc__ == 'prefixbasesuffix') + assert(Implementing.testWithoutDoc.__doc__ == None) + assert(OnlySuffix.testBase.__doc__ == 'basesuffix') + assert(OnlySuffix.testWithoutDoc.__doc__ == None) + assert(OnlyPrefix.testBase.__doc__ == 'prefixbase') + assert(OnlyPrefix.testWithoutDoc.__doc__ == None) diff --git a/sources/pyside2/tests/util/httpd.py b/sources/pyside2/tests/util/httpd.py new file mode 100644 index 000000000..8214cf033 --- /dev/null +++ b/sources/pyside2/tests/util/httpd.py @@ -0,0 +1,177 @@ +############################################################################# +## +## Copyright (C) 2016 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 os +import sys +import threading +import select +import random +import py3kcompat as py3k + +if py3k.IS_PY3K: + import socketserver as SocketServer + import http.server as BaseHTTPServer +else: + import SocketServer + import BaseHTTPServer + +class TestHandler(BaseHTTPServer.BaseHTTPRequestHandler): + DATA = "PySide Server" + allow_reuse_address = True + + def do_GET(self): + self.send_head() + self.wfile.write(TestHandler.DATA) + + def do_HEAD(self): + self.send_head() + + def send_head(self): + self.send_response(200) + self.send_header("Content-type", "text/plain") + self.send_header("Content-Length", str(len(TestHandler.DATA))) + self.end_headers() + +class TestSecureHandler(BaseHTTPServer.BaseHTTPRequestHandler): + DATA = "PySide" + allow_reuse_address = True + + def do_GET(self): + self.send_head() + self.wfile.write(py3k.b(TestHandler.DATA)) + + def do_HEAD(self): + self.send_head() + + def send_head(self): + try: + handler = self.marshall_handler() + handler.do_request(self) + except: + self.send_response(401) + self.send_header("WWW-Authenticate", "Basic realm='Secure Area'") + self.send_header("Content-type", "text/plain") + self.send_header("Content-Length", str(len(TestHandler.DATA))) + self.end_headers() + +# Workaround for the missing shutdown method in python2.5 +class CompatTCPServer(SocketServer.TCPServer): + def __init__(self, server_address, RequestHandlerClass): + SocketServer.TCPServer.__init__(self, server_address, RequestHandlerClass) + + self.isPy25 = sys.version_info[0] == 2 and sys.version_info[1] == 5 + if self.isPy25: + self.__is_shut_down = threading.Event() + self.__serving = False + + def serve_forever(self, poll_interval=0.5): + """Handle one request at a time until shutdown. + + Polls for shutdown every poll_interval seconds. Ignores + self.timeout. If you need to do periodic tasks, do them in + another thread. + """ + if self.isPy25: + self.__serving = True + self.__is_shut_down.clear() + while self.__serving: + # XXX: Consider using another file descriptor or + # connecting to the socket to wake this up instead of + # polling. Polling reduces our responsiveness to a + # shutdown request and wastes cpu at all other times. + r, w, e = select.select([self], [], [], poll_interval) + if r: + self.py25_handle_request_noblock() + self.__is_shut_down.set() + else: + SocketServer.TCPServer.serve_forever(self, poll_interval) + + def py25_handle_request_noblock(self): + """Handle one request, without blocking. + + I assume that select.select has returned that the socket is + readable before this function was called, so there should be + no risk of blocking in get_request(). + """ + if self.isPy25: + try: + request, client_address = self.get_request() + except socket.error: + return + if self.verify_request(request, client_address): + try: + self.process_request(request, client_address) + except: + self.handle_error(request, client_address) + self.close_request(request) + + def shutdown(self): + """Stops the serve_forever loop. + + Blocks until the loop has finished. This must be called while + serve_forever() is running in another thread, or it will + deadlock. + """ + if self.isPy25: + self.__serving = False + if not self.__is_shut_down: + self.__is_shut_down.wait() + else: + SocketServer.TCPServer.shutdown(self) + + +class TestServer(threading.Thread): + + def __init__(self, secure=False): + threading.Thread.__init__(self) + + self._port = int(os.getenv("PYSIDE_TESTSERVER_PORT") or 12321) + self.keep_running = True + + if secure: + handle = TestSecureHandler + else: + handle = TestHandler + + while True: + try: + self.httpd = CompatTCPServer(('' , self._port), handle) + break + except: + self._port = self._port + random.randint(1, 100) + + def port(self): + return self._port + + def run(self): + self.httpd.serve_forever() + + def shutdown(self): + self.httpd.shutdown() + self.join() + diff --git a/sources/pyside2/tests/util/module_wrapper/PySide/QtAssistant.py b/sources/pyside2/tests/util/module_wrapper/PySide/QtAssistant.py new file mode 100644 index 000000000..d0975d51e --- /dev/null +++ b/sources/pyside2/tests/util/module_wrapper/PySide/QtAssistant.py @@ -0,0 +1,2 @@ + +from PyQt4.QtAssistant import * diff --git a/sources/pyside2/tests/util/module_wrapper/PySide/QtCore.py b/sources/pyside2/tests/util/module_wrapper/PySide/QtCore.py new file mode 100644 index 000000000..a6a225649 --- /dev/null +++ b/sources/pyside2/tests/util/module_wrapper/PySide/QtCore.py @@ -0,0 +1,2 @@ + +from PyQt4.QtCore import * diff --git a/sources/pyside2/tests/util/module_wrapper/PySide/QtDesigner.py b/sources/pyside2/tests/util/module_wrapper/PySide/QtDesigner.py new file mode 100644 index 000000000..5cf9d5f6d --- /dev/null +++ b/sources/pyside2/tests/util/module_wrapper/PySide/QtDesigner.py @@ -0,0 +1,2 @@ + +from PyQt4.QtDesigner import * diff --git a/sources/pyside2/tests/util/module_wrapper/PySide/QtGui.py b/sources/pyside2/tests/util/module_wrapper/PySide/QtGui.py new file mode 100644 index 000000000..0b8b4e957 --- /dev/null +++ b/sources/pyside2/tests/util/module_wrapper/PySide/QtGui.py @@ -0,0 +1,2 @@ + +from PyQt4.QtGui import * diff --git a/sources/pyside2/tests/util/module_wrapper/PySide/QtHelp.py b/sources/pyside2/tests/util/module_wrapper/PySide/QtHelp.py new file mode 100644 index 000000000..dd3fd6cd8 --- /dev/null +++ b/sources/pyside2/tests/util/module_wrapper/PySide/QtHelp.py @@ -0,0 +1,2 @@ + +from PyQt4.QtHelp import * diff --git a/sources/pyside2/tests/util/module_wrapper/PySide/QtNetwork.py b/sources/pyside2/tests/util/module_wrapper/PySide/QtNetwork.py new file mode 100644 index 000000000..1a669a421 --- /dev/null +++ b/sources/pyside2/tests/util/module_wrapper/PySide/QtNetwork.py @@ -0,0 +1,2 @@ + +from PyQt4.QtNetwork import * diff --git a/sources/pyside2/tests/util/module_wrapper/PySide/QtScript.py b/sources/pyside2/tests/util/module_wrapper/PySide/QtScript.py new file mode 100644 index 000000000..4f6b30e8e --- /dev/null +++ b/sources/pyside2/tests/util/module_wrapper/PySide/QtScript.py @@ -0,0 +1,2 @@ + +from PyQt4.QtScript import * diff --git a/sources/pyside2/tests/util/module_wrapper/PySide/QtSql.py b/sources/pyside2/tests/util/module_wrapper/PySide/QtSql.py new file mode 100644 index 000000000..35dd0a106 --- /dev/null +++ b/sources/pyside2/tests/util/module_wrapper/PySide/QtSql.py @@ -0,0 +1,2 @@ + +from PyQt4.QtSql import * diff --git a/sources/pyside2/tests/util/module_wrapper/PySide/QtSvg.py b/sources/pyside2/tests/util/module_wrapper/PySide/QtSvg.py new file mode 100644 index 000000000..f308222b9 --- /dev/null +++ b/sources/pyside2/tests/util/module_wrapper/PySide/QtSvg.py @@ -0,0 +1,2 @@ + +from PyQt4.QtSvg import * diff --git a/sources/pyside2/tests/util/module_wrapper/PySide/QtTest.py b/sources/pyside2/tests/util/module_wrapper/PySide/QtTest.py new file mode 100644 index 000000000..95f64006b --- /dev/null +++ b/sources/pyside2/tests/util/module_wrapper/PySide/QtTest.py @@ -0,0 +1,2 @@ + +from PyQt4.QtTest import * diff --git a/sources/pyside2/tests/util/module_wrapper/PySide/QtWebKit.py b/sources/pyside2/tests/util/module_wrapper/PySide/QtWebKit.py new file mode 100644 index 000000000..bffc79968 --- /dev/null +++ b/sources/pyside2/tests/util/module_wrapper/PySide/QtWebKit.py @@ -0,0 +1,2 @@ + +from PyQt4.QtWebKit import * diff --git a/sources/pyside2/tests/util/module_wrapper/PySide/QtXml.py b/sources/pyside2/tests/util/module_wrapper/PySide/QtXml.py new file mode 100644 index 000000000..2888a4e49 --- /dev/null +++ b/sources/pyside2/tests/util/module_wrapper/PySide/QtXml.py @@ -0,0 +1,2 @@ + +from PyQt4.QtXml import * diff --git a/sources/pyside2/tests/util/module_wrapper/PySide/QtXmlPatterns.py b/sources/pyside2/tests/util/module_wrapper/PySide/QtXmlPatterns.py new file mode 100644 index 000000000..6de76d830 --- /dev/null +++ b/sources/pyside2/tests/util/module_wrapper/PySide/QtXmlPatterns.py @@ -0,0 +1,2 @@ + +from PyQt4.QtXmlPatterns import * diff --git a/sources/pyside2/tests/util/module_wrapper/PySide/__init__.py b/sources/pyside2/tests/util/module_wrapper/PySide/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/sources/pyside2/tests/util/module_wrapper/PySide/__init__.py diff --git a/sources/pyside2/tests/util/processtimer.py b/sources/pyside2/tests/util/processtimer.py new file mode 100644 index 000000000..19206472e --- /dev/null +++ b/sources/pyside2/tests/util/processtimer.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python + +############################################################################# +## +## Copyright (C) 2016 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 time,os + +class TimeoutException(Exception): + def __init__(self, msg): + self.msg = msg + + def __str__(self): + return repr(self.msg) + +class ProcessTimer(object): + '''Timeout function for controlling a subprocess.Popen instance. + + Naive implementation using busy loop, see later other means + of doing this. + ''' + + def __init__(self, proc, timeout): + self.proc = proc + self.timeout = timeout + + def waitfor(self): + time_passed = 0 + while(self.proc.poll() is None and time_passed < self.timeout): + time_passed = time_passed + 1 + time.sleep(1) + + if time_passed >= self.timeout: + raise TimeoutException("Timeout expired, possible deadlock") + +if __name__ == "__main__": + #simple example + + from subprocess import Popen + + proc = Popen(['sleep','10']) + t = ProcessTimer(proc,5) + try: + t.waitfor() + except TimeoutException: + print "timeout - PID: %d" % (t.proc.pid) + #TODO: detect SO and kill accordingly + #Linux + os.kill(t.proc.pid, 9) + #Windows (not tested) + #subprocess.Popen("taskkill /F /T /PID %i"%handle.pid , shell=True) + print "exit code: %d" % (t.proc.poll()) + diff --git a/sources/pyside2/tests/util/py2xfunctions.py b/sources/pyside2/tests/util/py2xfunctions.py new file mode 100644 index 000000000..d848c2c61 --- /dev/null +++ b/sources/pyside2/tests/util/py2xfunctions.py @@ -0,0 +1,46 @@ +############################################################################# +## +## Copyright (C) 2016 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$ +## +############################################################################# + +def b(s): + return s + +def l(n): + return long(n) + +def unicode_(s): + if type(s) == str: + import codecs + c = codecs.lookup('utf-8') + s2 = c.decode(s, 'ignore') + return s2[0] + return u'%s' % s + +unicode = unicode +unichr = unichr +long = long +buffer = buffer diff --git a/sources/pyside2/tests/util/py3kcompat.py b/sources/pyside2/tests/util/py3kcompat.py new file mode 100644 index 000000000..19e50dc71 --- /dev/null +++ b/sources/pyside2/tests/util/py3kcompat.py @@ -0,0 +1,38 @@ +# -*- 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 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 sys + +IS_PY3K = sys.version_info[0] == 3 + +if IS_PY3K: + from py3xfunctions import b, l, unicode_, unicode, unichr, long, unichr, buffer +else: + from py2xfunctions import b, l, unicode_, unicode, unichr, long, unichr, buffer + diff --git a/sources/pyside2/tests/util/py3xfunctions.py b/sources/pyside2/tests/util/py3xfunctions.py new file mode 100644 index 000000000..e7014e56a --- /dev/null +++ b/sources/pyside2/tests/util/py3xfunctions.py @@ -0,0 +1,54 @@ +############################################################################# +## +## Copyright (C) 2016 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$ +## +############################################################################# + +def b(s): + if type(s) == bytes: + return s + return bytes(s, "UTF8") + +def buffer_(s): + if s == None: + return None + elif type(s) == str: + return bytes(s, "UTF8") + elif type(s) == bytes: + return s + else: + memoryview(s) + +def l(n): + return n + +def unicode_(s): + return s + +unicode = str +unichr = chr +long = int +unichr = chr +buffer = buffer_ diff --git a/sources/pyside2/tests/util/pyqt_diff.py b/sources/pyside2/tests/util/pyqt_diff.py new file mode 100644 index 000000000..04e873556 --- /dev/null +++ b/sources/pyside2/tests/util/pyqt_diff.py @@ -0,0 +1,64 @@ +############################################################################# +## +## Copyright (C) 2016 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 + +'''Script to show the difference between PyQt5 and ours''' + +import sys + +from color import print_colored + +def check_module_diff(module_name): + '''Difference between PySide2 and PyQt5 versions of qt bindings. + Returns a tuple with the members present only on PySide2 and only on PyQt5''' + shiboken_module = getattr(__import__('PySide2.' + module_name), module_name) + orig_module = getattr(__import__('PyQt5.' + module_name), module_name) + + shiboken_set = set(dir(shiboken_module)) + orig_set = set(dir(orig_module)) + + return sorted(shiboken_set - orig_set), sorted(orig_set - shiboken_set) + + +def main(argv=None): + if argv is None: + argv = sys.argv + + module_name = argv[1] if len(argv) >= 2 else 'QtCore' + + only_shiboken, only_orig = check_module_diff(module_name) + + print_colored('Only on Shiboken version') + print(only_shiboken) + + print_colored('Only on SIP version') + print(only_orig) + +if __name__ == '__main__': + main() diff --git a/sources/pyside2/tests/util/pyqtcheck.py b/sources/pyside2/tests/util/pyqtcheck.py new file mode 100644 index 000000000..7734ea6a7 --- /dev/null +++ b/sources/pyside2/tests/util/pyqtcheck.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python + +############################################################################# +## +## Copyright (C) 2016 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 sys +from optparse import OptionParser + +import PyQt4 +from PyQt4 import QtCore, QtGui, QtNetwork + +modules = [QtCore, QtGui, QtNetwork] + +def search(klass, method=None): + for module in modules: + try: + klass_obj = getattr(module, klass) + print "%s *found* on module %s" % (klass, module.__name__) + except AttributeError: + print "%s not found on module %s" % (klass, module.__name__) + continue + + if method is None: + continue + + try: + meth_obj = getattr(klass_obj, method) + + meth_name = ".".join([klass, method]) + klass_name = ".".join([module.__name__, klass]) + print "\"%s\" *found* on class %s" % (meth_name, klass_name) + except AttributeError: + print "\"%s\" not found on class %s" % (method, klass) + + +def main(argv=None): + if argv is None: + argv = sys.argv[1:] + + try: + klass, method = argv[0].split(".") + except: + klass = argv[0] + method = None + + search(klass, method) + +if __name__ == '__main__': + main() diff --git a/sources/pyside2/tests/util/rename_imports.sh b/sources/pyside2/tests/util/rename_imports.sh new file mode 100755 index 000000000..e985a9100 --- /dev/null +++ b/sources/pyside2/tests/util/rename_imports.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +############################################################################# +## +## Copyright (C) 2016 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$ +## +############################################################################# + +# Rename import statements from .py script to use a specific module name +set -e + +if [ $# -lt 3 ]; then + echo "Usage: $0 <old_name> <new_name> <directories...>" + exit 1 +fi + +old_name=$1; shift +new_name=$1; shift + +find "$@" -name "*.py" -exec sed -ri "s/(import|from) $old_name/\1 $new_name/" '{}' \; diff --git a/sources/pyside2/tests/util/test_processtimer.py b/sources/pyside2/tests/util/test_processtimer.py new file mode 100644 index 000000000..66a2a57db --- /dev/null +++ b/sources/pyside2/tests/util/test_processtimer.py @@ -0,0 +1,93 @@ +############################################################################# +## +## Copyright (C) 2016 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$ +## +############################################################################# + +'Tests for processtimer.py' + +import unittest +import os + +from subprocess import Popen, PIPE +from processtimer import TimeoutException, ProcessTimer + +class TimeoutTest(unittest.TestCase): + + def tearDown(self): + try: + os.kill(self.proc.pid, 9) + except OSError: + pass + + def testRaise(self): + self.proc = Popen(['python2.5', '-c', 'while True: pass' ], stdout=PIPE, stderr=PIPE) + timer = ProcessTimer(self.proc, 1) + self.assertRaises(TimeoutException, timer.waitfor) + +class SimpleTest(unittest.TestCase): + + def tearDown(self): + try: + os.kill(self.proc.pid, 9) + except OSError: + pass + def testSimple(self): + self.proc = Popen(['python2.5', '-c', '"print"'], stdout=PIPE, stderr=PIPE) + timer = ProcessTimer(self.proc, 10) + timer.waitfor() + +class TestEchoOutput(unittest.TestCase): + + def tearDown(self): + try: + os.kill(self.proc.pid, 9) + except OSError: + pass + + def testOutput(self): + self.proc = Popen(['python2.5', '-c', 'print 1',], stdout=PIPE, stderr=PIPE) + timer = ProcessTimer(self.proc, 1) + timer.waitfor() + self.assertEqual(self.proc.stdout.read().strip(), '1') + +class TestRetCode(unittest.TestCase): + + def tearDown(self): + try: + os.kill(self.proc.pid, 9) + except OSError: + pass + + def testSimple(self): + self.proc = Popen(['python2.5', '-c', 'print 1'], stdout=PIPE, stderr=PIPE) + timer = ProcessTimer(self.proc, 10) + timer.waitfor() + + self.assertEqual(self.proc.poll(), 0) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/util/use_pyqt4.sh b/sources/pyside2/tests/util/use_pyqt4.sh new file mode 100644 index 000000000..5b88fa5c7 --- /dev/null +++ b/sources/pyside2/tests/util/use_pyqt4.sh @@ -0,0 +1,3 @@ + +OLD_PYTHONPATH=$PYTHONPATH +PYTHONPATH=`pwd`/util/module_wrapper:$PYTHONPATH diff --git a/sources/pyside2/tests/util/use_pyside.sh b/sources/pyside2/tests/util/use_pyside.sh new file mode 100644 index 000000000..516207473 --- /dev/null +++ b/sources/pyside2/tests/util/use_pyside.sh @@ -0,0 +1,3 @@ + +PYTHONPATH=$OLD_PYTHONPATH +unset OLD_PYTHONPATH diff --git a/sources/pyside2/tests/util/valgrind-python.supp b/sources/pyside2/tests/util/valgrind-python.supp new file mode 100644 index 000000000..a54b451b3 --- /dev/null +++ b/sources/pyside2/tests/util/valgrind-python.supp @@ -0,0 +1,349 @@ +# +# This is a valgrind suppression file that should be used when using valgrind. +# +# Here's an example of running valgrind: +# +# cd python/dist/src +# valgrind --tool=memcheck --suppressions=Misc/valgrind-python.supp \ +# ./python -E -tt ./Lib/test/regrtest.py -u bsddb,network +# +# You must edit Objects/obmalloc.c and uncomment Py_USING_MEMORY_DEBUGGER +# to use the preferred suppressions with Py_ADDRESS_IN_RANGE. +# +# If you do not want to recompile Python, you can uncomment +# suppressions for PyObject_Free and PyObject_Realloc. +# +# See Misc/README.valgrind for more information. + +# all tool names: Addrcheck,Memcheck,cachegrind,helgrind,massif +{ + ADDRESS_IN_RANGE/Invalid read of size 4 + Memcheck:Addr4 + fun:Py_ADDRESS_IN_RANGE +} + +{ + ADDRESS_IN_RANGE/Invalid read of size 4 + Memcheck:Value4 + fun:Py_ADDRESS_IN_RANGE +} + +{ + ADDRESS_IN_RANGE/Invalid read of size 8 (x86_64 aka amd64) + Memcheck:Value8 + fun:Py_ADDRESS_IN_RANGE +} + +{ + ADDRESS_IN_RANGE/Conditional jump or move depends on uninitialised value + Memcheck:Cond + fun:Py_ADDRESS_IN_RANGE +} + +# +# Leaks (including possible leaks) +# Hmmm, I wonder if this masks some real leaks. I think it does. +# Will need to fix that. +# + +{ + Handle PyMalloc confusing valgrind (possibly leaked) + Memcheck:Leak + fun:realloc + fun:_PyObject_GC_Resize + fun:COMMENT_THIS_LINE_TO_DISABLE_LEAK_WARNING +} + +{ + Handle PyMalloc confusing valgrind (possibly leaked) + Memcheck:Leak + fun:malloc + fun:_PyObject_GC_New + fun:COMMENT_THIS_LINE_TO_DISABLE_LEAK_WARNING +} + +{ + Handle PyMalloc confusing valgrind (possibly leaked) + Memcheck:Leak + fun:malloc + fun:_PyObject_GC_NewVar + fun:COMMENT_THIS_LINE_TO_DISABLE_LEAK_WARNING +} + +# +# Non-python specific leaks +# + +{ + Handle pthread issue (possibly leaked) + Memcheck:Leak + fun:calloc + fun:allocate_dtv + fun:_dl_allocate_tls_storage + fun:_dl_allocate_tls +} + +{ + Handle pthread issue (possibly leaked) + Memcheck:Leak + fun:memalign + fun:_dl_allocate_tls_storage + fun:_dl_allocate_tls +} + +{ + ADDRESS_IN_RANGE/Invalid read of size 4 + Memcheck:Addr4 + fun:PyObject_Free +} + +{ + ADDRESS_IN_RANGE/Invalid read of size 4 + Memcheck:Value4 + fun:PyObject_Free +} + +{ + ADDRESS_IN_RANGE/Conditional jump or move depends on uninitialised value + Memcheck:Cond + fun:PyObject_Free +} + +{ + ADDRESS_IN_RANGE/Invalid read of size 4 + Memcheck:Addr4 + fun:PyObject_Realloc +} + +{ + ADDRESS_IN_RANGE/Invalid read of size 4 + Memcheck:Value4 + fun:PyObject_Realloc +} + +{ + ADDRESS_IN_RANGE/Conditional jump or move depends on uninitialised value + Memcheck:Cond + fun:PyObject_Realloc +} + +### +### All the suppressions below are for errors that occur within libraries +### that Python uses. The problems to not appear to be related to Python's +### use of the libraries. +### + +{ + Generic gentoo ld problems + Memcheck:Cond + obj:/lib/ld-2.3.4.so + obj:/lib/ld-2.3.4.so + obj:/lib/ld-2.3.4.so + obj:/lib/ld-2.3.4.so +} + +{ + DBM problems, see test_dbm + Memcheck:Param + write(buf) + fun:write + obj:/usr/lib/libdb1.so.2 + obj:/usr/lib/libdb1.so.2 + obj:/usr/lib/libdb1.so.2 + obj:/usr/lib/libdb1.so.2 + fun:dbm_close +} + +{ + DBM problems, see test_dbm + Memcheck:Value8 + fun:memmove + obj:/usr/lib/libdb1.so.2 + obj:/usr/lib/libdb1.so.2 + obj:/usr/lib/libdb1.so.2 + obj:/usr/lib/libdb1.so.2 + fun:dbm_store + fun:dbm_ass_sub +} + +{ + DBM problems, see test_dbm + Memcheck:Cond + obj:/usr/lib/libdb1.so.2 + obj:/usr/lib/libdb1.so.2 + obj:/usr/lib/libdb1.so.2 + fun:dbm_store + fun:dbm_ass_sub +} + +{ + DBM problems, see test_dbm + Memcheck:Cond + fun:memmove + obj:/usr/lib/libdb1.so.2 + obj:/usr/lib/libdb1.so.2 + obj:/usr/lib/libdb1.so.2 + obj:/usr/lib/libdb1.so.2 + fun:dbm_store + fun:dbm_ass_sub +} + +{ + GDBM problems, see test_gdbm + Memcheck:Param + write(buf) + fun:write + fun:gdbm_open + +} + +{ + ZLIB problems, see test_gzip + Memcheck:Cond + obj:/lib/libz.so.1.2.3 + obj:/lib/libz.so.1.2.3 + fun:deflate +} + +{ + Avoid problems w/readline doing a putenv and leaking on exit + Memcheck:Leak + fun:malloc + fun:xmalloc + fun:sh_set_lines_and_columns + fun:_rl_get_screen_size + fun:_rl_init_terminal_io + obj:/lib/libreadline.so.4.3 + fun:rl_initialize +} + +### +### These occur from somewhere within the SSL, when running +### test_socket_sll. They are too general to leave on by default. +### +###{ +### somewhere in SSL stuff +### Memcheck:Cond +### fun:memset +###} +###{ +### somewhere in SSL stuff +### Memcheck:Value4 +### fun:memset +###} +### +###{ +### somewhere in SSL stuff +### Memcheck:Cond +### fun:MD5_Update +###} +### +###{ +### somewhere in SSL stuff +### Memcheck:Value4 +### fun:MD5_Update +###} + +# +# All of these problems come from using test_socket_ssl +# +{ + from test_socket_ssl + Memcheck:Cond + fun:BN_bin2bn +} + +{ + from test_socket_ssl + Memcheck:Cond + fun:BN_num_bits_word +} + +{ + from test_socket_ssl + Memcheck:Value4 + fun:BN_num_bits_word +} + +{ + from test_socket_ssl + Memcheck:Cond + fun:BN_mod_exp_mont_word +} + +{ + from test_socket_ssl + Memcheck:Cond + fun:BN_mod_exp_mont +} + +{ + from test_socket_ssl + Memcheck:Param + write(buf) + fun:write + obj:/usr/lib/libcrypto.so.0.9.7 +} + +{ + from test_socket_ssl + Memcheck:Cond + fun:RSA_verify +} + +{ + from test_socket_ssl + Memcheck:Value4 + fun:RSA_verify +} + +{ + from test_socket_ssl + Memcheck:Value4 + fun:DES_set_key_unchecked +} + +{ + from test_socket_ssl + Memcheck:Value4 + fun:DES_encrypt2 +} + +{ + from test_socket_ssl + Memcheck:Cond + obj:/usr/lib/libssl.so.0.9.7 +} + +{ + from test_socket_ssl + Memcheck:Value4 + obj:/usr/lib/libssl.so.0.9.7 +} + +{ + from test_socket_ssl + Memcheck:Cond + fun:BUF_MEM_grow_clean +} + +{ + from test_socket_ssl + Memcheck:Cond + fun:memcpy + fun:ssl3_read_bytes +} + +{ + from test_socket_ssl + Memcheck:Cond + fun:SHA1_Update +} + +{ + from test_socket_ssl + Memcheck:Value4 + fun:SHA1_Update +} + + |