aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/tests/util
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside6/tests/util')
-rw-r--r--sources/pyside6/tests/util/color.py1
-rw-r--r--sources/pyside6/tests/util/httpd.py5
-rw-r--r--sources/pyside6/tests/util/processtimer.py71
-rw-r--r--sources/pyside6/tests/util/pyqt_diff.py2
-rw-r--r--sources/pyside6/tests/util/test_processtimer.py7
5 files changed, 50 insertions, 36 deletions
diff --git a/sources/pyside6/tests/util/color.py b/sources/pyside6/tests/util/color.py
index 1602fbb00..aee452ad8 100644
--- a/sources/pyside6/tests/util/color.py
+++ b/sources/pyside6/tests/util/color.py
@@ -32,6 +32,7 @@
def print_colored(message):
print(f'\033[0;31m{message}\033[m') # red
+
if __name__ == '__main__':
print('42 - the answer')
print_colored("But what's the question?")
diff --git a/sources/pyside6/tests/util/httpd.py b/sources/pyside6/tests/util/httpd.py
index 2cbaa130e..dbd78aeb8 100644
--- a/sources/pyside6/tests/util/httpd.py
+++ b/sources/pyside6/tests/util/httpd.py
@@ -55,6 +55,7 @@ class TestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
self.send_header("Content-Length", str(len(TestHandler.DATA)))
self.end_headers()
+
class TestSecureHandler(BaseHTTPServer.BaseHTTPRequestHandler):
DATA = "PySide"
allow_reuse_address = True
@@ -78,6 +79,8 @@ class TestSecureHandler(BaseHTTPServer.BaseHTTPRequestHandler):
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)
@@ -158,7 +161,7 @@ class TestServer(threading.Thread):
while True:
try:
- self.httpd = CompatTCPServer(('' , self._port), handle)
+ self.httpd = CompatTCPServer(('', self._port), handle)
break
except:
self._port = self._port + random.randint(1, 100)
diff --git a/sources/pyside6/tests/util/processtimer.py b/sources/pyside6/tests/util/processtimer.py
index 067f1d29c..35102e592 100644
--- a/sources/pyside6/tests/util/processtimer.py
+++ b/sources/pyside6/tests/util/processtimer.py
@@ -28,50 +28,53 @@
##
#############################################################################
-import time,os
+import os
+import time
+
class TimeoutException(Exception):
- def __init__(self, msg):
- self.msg = msg
+ def __init__(self, msg):
+ self.msg = msg
+
+ def __str__(self):
+ return repr(self.msg)
- def __str__(self):
- return repr(self.msg)
class ProcessTimer(object):
- '''Timeout function for controlling a subprocess.Popen instance.
+ '''Timeout function for controlling a subprocess.Popen instance.
- Naive implementation using busy loop, see later other means
- of doing this.
- '''
+ Naive implementation using busy loop, see later other means
+ of doing this.
+ '''
- def __init__(self, proc, timeout):
- self.proc = proc
- self.timeout = timeout
+ 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)
+ 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 time_passed >= self.timeout:
+ raise TimeoutException("Timeout expired, possible deadlock")
-if __name__ == "__main__":
- #simple example
- from subprocess import Popen
+if __name__ == "__main__":
+ # simple example
- proc = Popen(['sleep','10'])
- t = ProcessTimer(proc,5)
- try:
- t.waitfor()
- except TimeoutException:
- print(f"timeout - PID: {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(f"exit code: {t.proc.poll()}")
+ from subprocess import Popen
+ proc = Popen(['sleep', '10'])
+ t = ProcessTimer(proc, 5)
+ try:
+ t.waitfor()
+ except TimeoutException:
+ print(f"timeout - PID: {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(f"exit code: {t.proc.poll()}")
diff --git a/sources/pyside6/tests/util/pyqt_diff.py b/sources/pyside6/tests/util/pyqt_diff.py
index 380fd08e0..ca10ef049 100644
--- a/sources/pyside6/tests/util/pyqt_diff.py
+++ b/sources/pyside6/tests/util/pyqt_diff.py
@@ -32,6 +32,7 @@ import sys
from color import print_colored
+
def check_module_diff(module_name):
'''Difference between PySide6 and PyQt5 versions of qt bindings.
Returns a tuple with the members present only on PySide6 and only on PyQt5'''
@@ -58,5 +59,6 @@ def main(argv=None):
print_colored('Only on SIP version')
print(only_orig)
+
if __name__ == '__main__':
main()
diff --git a/sources/pyside6/tests/util/test_processtimer.py b/sources/pyside6/tests/util/test_processtimer.py
index ba3e99775..026e14b6b 100644
--- a/sources/pyside6/tests/util/test_processtimer.py
+++ b/sources/pyside6/tests/util/test_processtimer.py
@@ -34,6 +34,7 @@ import os
from subprocess import Popen, PIPE
from processtimer import TimeoutException, ProcessTimer
+
class TimeoutTest(unittest.TestCase):
def tearDown(self):
@@ -43,10 +44,11 @@ class TimeoutTest(unittest.TestCase):
pass
def testRaise(self):
- self.proc = Popen(['python2.5', '-c', 'while True: pass' ], stdout=PIPE, stderr=PIPE)
+ 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):
@@ -54,11 +56,13 @@ class SimpleTest(unittest.TestCase):
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):
@@ -73,6 +77,7 @@ class TestEchoOutput(unittest.TestCase):
timer.waitfor()
self.assertEqual(self.proc.stdout.read().strip(), '1')
+
class TestRetCode(unittest.TestCase):
def tearDown(self):