diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-09-03 11:14:55 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-09-03 12:25:11 +0000 |
commit | e796600c9663a26ccf1929aca8336eb0cb23fe5d (patch) | |
tree | d59e8b19dc85aa28bb90c3764b16cb0357e3a4c6 | |
parent | 4d918d73e94c2fea125107369a650dff99513e0c (diff) |
Remove Python2 from shiboken tests
Task-number: PYSIDE-1339
Task-number: PYSIDE-904
Change-Id: I78f18430eecf37c6a66593ac3a725d92b5a6c061
Reviewed-by: Christian Tismer <tismer@stackless.com>
16 files changed, 34 insertions, 247 deletions
diff --git a/sources/shiboken2/tests/minimalbinding/listuser_test.py b/sources/shiboken2/tests/minimalbinding/listuser_test.py index e69bce346..3668cb55f 100644 --- a/sources/shiboken2/tests/minimalbinding/listuser_test.py +++ b/sources/shiboken2/tests/minimalbinding/listuser_test.py @@ -29,6 +29,7 @@ ## ############################################################################# +from functools import reduce import os import sys import unittest @@ -38,11 +39,6 @@ from shiboken_paths import init_paths init_paths() from minimal import ListUser, Val, Obj -from py3kcompat import IS_PY3K - -if IS_PY3K: - import functools - reduce = functools.reduce class ExtListUser(ListUser): diff --git a/sources/shiboken2/tests/minimalbinding/typedef_test.py b/sources/shiboken2/tests/minimalbinding/typedef_test.py index 6595d0467..e8dd5cd16 100644 --- a/sources/shiboken2/tests/minimalbinding/typedef_test.py +++ b/sources/shiboken2/tests/minimalbinding/typedef_test.py @@ -29,6 +29,7 @@ ## ############################################################################# +from functools import reduce import os import sys import unittest @@ -37,7 +38,6 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from shiboken_paths import init_paths init_paths() from minimal import * -from py3kcompat import IS_PY3K try: import numpy as np @@ -46,11 +46,6 @@ except ImportError as e: np = None -if IS_PY3K: - import functools - reduce = functools.reduce - - class TypedefTest(unittest.TestCase): def setUp(self): diff --git a/sources/shiboken2/tests/otherbinding/module_reload_test.py b/sources/shiboken2/tests/otherbinding/module_reload_test.py index 368425cd0..c63af188e 100644 --- a/sources/shiboken2/tests/otherbinding/module_reload_test.py +++ b/sources/shiboken2/tests/otherbinding/module_reload_test.py @@ -29,6 +29,7 @@ ## ############################################################################# +from importlib import reload import os import shutil import sys @@ -38,10 +39,6 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from shiboken_paths import init_paths init_paths() -from py3kcompat import IS_PY3K - -if IS_PY3K: - from imp import reload orig_path = os.path.join(os.path.dirname(__file__)) workdir = os.getcwd() diff --git a/sources/shiboken2/tests/py3k.py b/sources/shiboken2/tests/py3k.py deleted file mode 100644 index 5f2961a6a..000000000 --- a/sources/shiboken2/tests/py3k.py +++ /dev/null @@ -1,2 +0,0 @@ -def printToFile(f, str): - print(str, file=f) diff --git a/sources/shiboken2/tests/py3kcompat.py b/sources/shiboken2/tests/py3kcompat.py deleted file mode 100644 index 357ea4fba..000000000 --- a/sources/shiboken2/tests/py3kcompat.py +++ /dev/null @@ -1,82 +0,0 @@ -# -*- coding: utf-8 -*- - -############################################################################# -## -## Copyright (C) 2020 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$ -## -############################################################################# - -# Copy of ../../pyside2/tests/util/py3kcompat.py - -import sys - -IS_PY3K = sys.version_info[0] == 3 - -if IS_PY3K: - 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_ -else: - 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/shiboken2/tests/samplebinding/bug_704_test.py b/sources/shiboken2/tests/samplebinding/bug_704_test.py index 28c90aba4..d7cb0acd6 100644 --- a/sources/shiboken2/tests/samplebinding/bug_704_test.py +++ b/sources/shiboken2/tests/samplebinding/bug_704_test.py @@ -36,7 +36,6 @@ import unittest sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from shiboken_paths import init_paths init_paths() -from py3kcompat import IS_PY3K from sample import ObjectType @@ -45,17 +44,11 @@ class NewStyle(object): def name(self): return "NewStyle" -class OldStyle: - def name(self): - return "OldStyle" def defineNewStyle(): class MyObjectNew(ObjectType, NewStyle): pass -def defineOldStyle(): - class MyObjectOld(ObjectType, OldStyle): - pass class ObjectTypeTest(unittest.TestCase): '''Test cases to avoid declaring Shiboken classes with multiple inheritance from old style classes.''' @@ -63,10 +56,6 @@ class ObjectTypeTest(unittest.TestCase): def testObjectTypeNewStype(self): defineNewStyle() - def testObjectTypeOldStype(self): - # Py 3k doesn't have old style classes - if not IS_PY3K: - self.assertRaises(TypeError, defineOldStyle) if __name__ == '__main__': diff --git a/sources/shiboken2/tests/samplebinding/bytearray_test.py b/sources/shiboken2/tests/samplebinding/bytearray_test.py index f1094e54e..af887493b 100644 --- a/sources/shiboken2/tests/samplebinding/bytearray_test.py +++ b/sources/shiboken2/tests/samplebinding/bytearray_test.py @@ -38,7 +38,6 @@ from shiboken_paths import init_paths init_paths() from os.path import isdir from sample import ByteArray -from py3kcompat import b class ByteArrayBufferProtocolTest(unittest.TestCase): @@ -102,14 +101,14 @@ class ByteArrayOperatorAt(unittest.TestCase): string = 'abcdefgh' obj = ByteArray(string) for i in range(len(string)): - self.assertEqual(obj[i], b(string[i])) + self.assertEqual(obj[i], bytes(string[i], "UTF8")) def testInRangeReverse(self): # ByteArray[x] where x is a valid index (reverse order). string = 'abcdefgh' obj = ByteArray(string) for i in range(len(string)-1, 0, -1): - self.assertEqual(obj[i], b(string[i])) + self.assertEqual(obj[i], bytes(string[i], "UTF8")) def testOutOfRange(self): # ByteArray[x] where x is out of index. @@ -120,7 +119,7 @@ class ByteArrayOperatorAt(unittest.TestCase): def testNullStrings(self): ba = ByteArray('\x00') self.assertEqual(ba.at(0), '\x00') - self.assertEqual(ba[0], b('\x00')) + self.assertEqual(ba[0], bytes('\x00', "UTF8")) class ByteArrayOperatorLen(unittest.TestCase): @@ -144,7 +143,7 @@ class ByteArrayAndPythonStr(unittest.TestCase): self.assertEqual(ByteArray('aaa').__str__(), 'aaa') def testPythonStrAndNull(self): - s1 = b('123\000321') + s1 = bytes('123\000321', "UTF8") ba = ByteArray(s1) s2 = ba.data() self.assertEqual(s1, s2) diff --git a/sources/shiboken2/tests/samplebinding/duck_punching_test.py b/sources/shiboken2/tests/samplebinding/duck_punching_test.py index 3f9d69b47..11c55d00b 100644 --- a/sources/shiboken2/tests/samplebinding/duck_punching_test.py +++ b/sources/shiboken2/tests/samplebinding/duck_punching_test.py @@ -39,15 +39,12 @@ import unittest sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from shiboken_paths import init_paths init_paths() -from py3kcompat import IS_PY3K from sample import VirtualMethods, SimpleFile, Point def MethodTypeCompat(func, instance): - if IS_PY3K: - return types.MethodType(func, instance) - else: - return types.MethodType(func, instance, type(instance)) + return types.MethodType(func, instance) + class Duck(VirtualMethods): def __init__(self): diff --git a/sources/shiboken2/tests/samplebinding/enum_test.py b/sources/shiboken2/tests/samplebinding/enum_test.py index 0beb72033..2ebc8d406 100644 --- a/sources/shiboken2/tests/samplebinding/enum_test.py +++ b/sources/shiboken2/tests/samplebinding/enum_test.py @@ -44,7 +44,6 @@ import shiboken2 import sample from sample import SampleNamespace, ObjectType, Event -from py3kcompat import IS_PY3K, b def createTempFile(): if sys.version_info >= (2, 6): @@ -133,13 +132,7 @@ class EnumTest(unittest.TestCase): def testEnumTpPrintImplementation(self): '''Without SbkEnum.tp_print 'print' returns the enum represented as an int.''' tmpfile = createTempFile() - if IS_PY3K: - from py3k import printToFile - printToFile(tmpfile, Event.ANY_EVENT) - else: - sys.stdout = tmpfile - print(Event.ANY_EVENT) - sys.stdout = sys.__stdout__ + print(Event.ANY_EVENT, file=tmpfile) tmpfile.seek(0) text = tmpfile.read().strip() tmpfile.close() diff --git a/sources/shiboken2/tests/samplebinding/implicitconv_numerical_test.py b/sources/shiboken2/tests/samplebinding/implicitconv_numerical_test.py index ebecf9ad8..94f2a5de7 100644 --- a/sources/shiboken2/tests/samplebinding/implicitconv_numerical_test.py +++ b/sources/shiboken2/tests/samplebinding/implicitconv_numerical_test.py @@ -40,7 +40,6 @@ from shiboken_paths import init_paths init_paths() import sys import sample -from py3kcompat import IS_PY3K, l, long # Hardcode the limits of the underlying C-types depending on architecture and memory # model (taking MSVC using LLP64 into account). @@ -48,7 +47,7 @@ cIntMin = -2147483648 cIntMax = 2147483647 cLongMin = cIntMin cLongMax = cIntMax -maxRepresentableInt = sys.maxsize if IS_PY3K else sys.maxint +maxRepresentableInt = sys.maxsize is64bitArchitecture = maxRepresentableInt > 2**32 if is64bitArchitecture and sys.platform != 'win32': cLongMin = -9223372036854775808 @@ -81,13 +80,13 @@ class FloatImplicitConvert(NumericTester): def testFloatAsUInt(self): '''Float as unsigned Int''' - self.check_value(3.14, 3, sample.acceptUInt, long) + self.check_value(3.14, 3, sample.acceptUInt, int) self.assertRaises(OverflowError, sample.acceptUInt, -3.14) def testFloatAsULong(self): '''Float as unsigned Long''' #FIXME Breaking with SystemError "bad argument to internal function" - self.check_value(3.14, 3, sample.acceptULong, long) + self.check_value(3.14, 3, sample.acceptULong, int) self.assertRaises(OverflowError, sample.acceptULong, -3.14) def testFloatAsDouble(self): @@ -112,12 +111,12 @@ class IntImplicitConvert(NumericTester): def testIntAsUInt(self): '''Int as unsigned Int''' - self.check_value(3, 3, sample.acceptUInt, long) + self.check_value(3, 3, sample.acceptUInt, int) self.assertRaises(OverflowError, sample.acceptUInt, -3) def testIntAsULong(self): '''Int as unsigned Long''' - self.check_value(3, 3, sample.acceptULong, long) + self.check_value(3, 3, sample.acceptULong, int) self.assertRaises(OverflowError, sample.acceptULong, -3) def testFloatAsDouble(self): @@ -130,27 +129,27 @@ class LongImplicitConvert(NumericTester): def testLongAsInt(self): '''Long as Int''' - self.check_value(l(24224), 24224, sample.acceptInt, int) + self.check_value(24224, 24224, sample.acceptInt, int) self.assertRaises(OverflowError, sample.acceptInt, cIntMax + 20) def testLongAsLong(self): '''Long as Long''' - self.check_value(l(2405), 2405, sample.acceptLong, int) + self.check_value(2405, 2405, sample.acceptLong, int) self.assertRaises(OverflowError, sample.acceptLong, cLongMax + 20) def testLongAsUInt(self): '''Long as unsigned Int''' - self.check_value(l(260), 260, sample.acceptUInt, long) + self.check_value(260, 260, sample.acceptUInt, int) self.assertRaises(OverflowError, sample.acceptUInt, -42) def testLongAsULong(self): '''Long as unsigned Long''' - self.check_value(l(128), 128, sample.acceptULong, long) - self.assertRaises(OverflowError, sample.acceptULong, l(-334)) + self.check_value(128, 128, sample.acceptULong, int) + self.assertRaises(OverflowError, sample.acceptULong, -334) def testLongAsDouble(self): '''Float as double''' - self.check_value(l(42), 42, sample.acceptDouble, float) + self.check_value(42, 42, sample.acceptDouble, float) if __name__ == '__main__': diff --git a/sources/shiboken2/tests/samplebinding/oldstyleclass_as_number_test.py b/sources/shiboken2/tests/samplebinding/oldstyleclass_as_number_test.py deleted file mode 100644 index e0f864636..000000000 --- a/sources/shiboken2/tests/samplebinding/oldstyleclass_as_number_test.py +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env 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$ -## -############################################################################# - -import os -import sys -import unittest - -sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -from shiboken_paths import init_paths -init_paths() - -import sample -from py3kcompat import IS_PY3K - -class OldStyle: - pass - -class NewStyle(object): - pass - -class OldStyleNumber: - def __init__(self, value): - self.value = value - def __trunc__(self): - return self.value - -class NewStyleNumber(object): - def __init__(self, value): - self.value = value - def __int__(self): - return int(self.value) - def __trunc__(self): - return self.value - -class TestOldStyleClassAsNumber(unittest.TestCase): - - def testBasic(self): - '''For the sake of calibration...''' - self.assertEqual(sample.acceptInt(123), 123) - - def testOldStyleClassPassedAsInteger(self): - '''Old-style classes aren't numbers and shouldn't be accepted.''' - obj = OldStyle() - self.assertRaises(TypeError, sample.acceptInt, obj) - - def testNewStyleClassPassedAsInteger(self): - '''New-style classes aren't numbers and shouldn't be accepted.''' - obj = NewStyle() - self.assertRaises(TypeError, sample.acceptInt, obj) - - def testOldStyleClassWithNumberProtocol(self): - obj = OldStyleNumber(123) - self.assertEqual(sample.acceptInt(obj), obj.value) - - def testNewStyleClassWithNumberProtocol(self): - obj = NewStyleNumber(123) - self.assertEqual(sample.acceptInt(obj), obj.value) - -if __name__ == "__main__" and not IS_PY3K: - unittest.main() - diff --git a/sources/shiboken2/tests/samplebinding/overflow_test.py b/sources/shiboken2/tests/samplebinding/overflow_test.py index 56a5d98c7..237bb6615 100644 --- a/sources/shiboken2/tests/samplebinding/overflow_test.py +++ b/sources/shiboken2/tests/samplebinding/overflow_test.py @@ -40,7 +40,7 @@ from shiboken_paths import init_paths init_paths() from sample import * -from py3kcompat import IS_PY3K, long + class OverflowTest(unittest.TestCase): '''Test case for overflowing C++ numeric types.''' @@ -56,7 +56,7 @@ class OverflowTest(unittest.TestCase): '''C++ function receives an long long argument and raise OverflowError if the value is negative.''' val = 100 self.assertEqual(doubleLongLong(val), 2 * val) - val = long(100) + val = int(100) self.assertEqual(doubleLongLong(val), 2 * val) val = (2 << 64) + 1 self.assertRaises(OverflowError, doubleLongLong, val) @@ -65,11 +65,11 @@ class OverflowTest(unittest.TestCase): '''C++ function receives an unsigned long long argument and raise OverflowError if the value is negative.''' val = 100 self.assertEqual(doubleUnsignedLongLong(val), 2 * val) - val = long(100) + val = int(100) self.assertEqual(doubleUnsignedLongLong(val), 2 * val) val = -100 self.assertRaises(OverflowError, doubleUnsignedLongLong, val) - val = long(-200) + val = int(-200) self.assertRaises(OverflowError, doubleUnsignedLongLong, val) def testOverflow(self): diff --git a/sources/shiboken2/tests/samplebinding/overloadwithdefault_test.py b/sources/shiboken2/tests/samplebinding/overloadwithdefault_test.py index dbd318091..9444f9066 100644 --- a/sources/shiboken2/tests/samplebinding/overloadwithdefault_test.py +++ b/sources/shiboken2/tests/samplebinding/overloadwithdefault_test.py @@ -38,7 +38,7 @@ from shiboken_paths import init_paths init_paths() from sample import Overload, Str -from py3kcompat import b + class OverloadTest(unittest.TestCase): @@ -59,11 +59,11 @@ class OverloadTest(unittest.TestCase): def testStringArgumentAsBuffer(self): overload = Overload() - self.assertEqual(overload.strBufferOverloads(b'', 0), Overload.Function1) + self.assertEqual(overload.strBufferOverloads(bytes('', "UTF-8"), 0), Overload.Function1) def testBufferArgument(self): overload = Overload() - self.assertEqual(overload.strBufferOverloads(b(''), 0), Overload.Function1) + self.assertEqual(overload.strBufferOverloads(bytes('', "UTF-8"), 0), Overload.Function1) if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken2/tests/samplebinding/ownership_delete_child_in_python_test.py b/sources/shiboken2/tests/samplebinding/ownership_delete_child_in_python_test.py index 206a65ce9..f9504227c 100644 --- a/sources/shiboken2/tests/samplebinding/ownership_delete_child_in_python_test.py +++ b/sources/shiboken2/tests/samplebinding/ownership_delete_child_in_python_test.py @@ -42,10 +42,6 @@ from shiboken_paths import init_paths init_paths() from sample import ObjectType -from py3kcompat import IS_PY3K - -if IS_PY3K: - string.letters = string.ascii_letters class DeleteChildInPython(unittest.TestCase): @@ -55,7 +51,7 @@ class DeleteChildInPython(unittest.TestCase): '''Delete child in python should not invalidate child''' parent = ObjectType() child = ObjectType(parent) - name = ''.join(random.sample(string.letters, 5)) + name = ''.join(random.sample(string.ascii_letters, 5)) child.setObjectName(name) del child diff --git a/sources/shiboken2/tests/samplebinding/point_test.py b/sources/shiboken2/tests/samplebinding/point_test.py index e2beb78ae..6d254128f 100644 --- a/sources/shiboken2/tests/samplebinding/point_test.py +++ b/sources/shiboken2/tests/samplebinding/point_test.py @@ -40,7 +40,6 @@ from shiboken_paths import init_paths init_paths() from sample import Point -from py3kcompat import unicode class PointTest(unittest.TestCase): '''Test case for Point class, including operator overloads.''' @@ -97,12 +96,12 @@ class PointTest(unittest.TestCase): def testAddedOperator(self): p = Point(0.0, 0.0) - r = p - unicode('Hi') - self.assertEqual(r, unicode('Hi')) + r = p - 'Hi' + self.assertEqual(r, 'Hi') # now the reverse op. - r = unicode('Hi') - p - self.assertEqual(r, unicode('Hi')) + r = 'Hi' - p + self.assertEqual(r, 'Hi') def testModifiedMethod(self): pt1 = Point(0.0, 0.0) diff --git a/sources/shiboken2/tests/shiboken_paths.py b/sources/shiboken2/tests/shiboken_paths.py index 1f60baac2..c9d1d129a 100644 --- a/sources/shiboken2/tests/shiboken_paths.py +++ b/sources/shiboken2/tests/shiboken_paths.py @@ -102,7 +102,7 @@ def shiboken_paths(include_shiboken_tests=False): src_dir = os.path.dirname(os.path.abspath(__file__)) python_dirs = [] if include_shiboken_tests: - python_dirs.append(src_dir) # For py3kcompat + python_dirs.append(src_dir) # For shiboken_test_helper shiboken_dir = os.path.join(get_build_dir(), 'shiboken2') python_dirs.append(os.path.join(shiboken_dir, 'shibokenmodule')) lib_dirs = [os.path.join(shiboken_dir, 'libshiboken')] |