diff options
Diffstat (limited to 'sources/shiboken6/tests/samplebinding')
134 files changed, 1653 insertions, 4332 deletions
diff --git a/sources/shiboken6/tests/samplebinding/CMakeLists.txt b/sources/shiboken6/tests/samplebinding/CMakeLists.txt index cfdc21041..fc812feb8 100644 --- a/sources/shiboken6/tests/samplebinding/CMakeLists.txt +++ b/sources/shiboken6/tests/samplebinding/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + project(sample) set(sample_TYPESYSTEM @@ -15,6 +18,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/base4_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/base5_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/base6_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/blackbox_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/brush_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/bytearray_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/bucket_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/classwithfunctionpointer_wrapper.cpp @@ -26,6 +30,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/customoverloadsequence_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/cvlistuser_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/cvvaluetype_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/sbkdate_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/deleteddefaultctor_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/derived_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/derivedusingct_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/derived_someinnerclass_wrapper.cpp @@ -105,17 +110,20 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/sample_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/sample_sample_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/samplenamespace_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/samplenamespace_ctparam_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/samplenamespace_inlinenamespace_classwithininlinenamespace_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/samplenamespace_someclass_someinnerclass_okthisisrecursiveenough_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/samplenamespace_someclass_someinnerclass_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/samplenamespace_someclass_someotherinnerclass_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/samplenamespace_someclass_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/samplenamespace_derivedfromnamespace_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/stdcomplex_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/simplefile_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/size_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/sizef_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/snakecasetest_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/snakecasederivedtest_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/sonofmderived1_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/spaceshipcomparisontester_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/str_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/strlist_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/time_wrapper.cpp @@ -140,13 +148,19 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/union_wrapper.cpp configure_file("${CMAKE_CURRENT_SOURCE_DIR}/sample-binding.txt.in" "${CMAKE_CURRENT_BINARY_DIR}/sample-binding.txt" @ONLY) +shiboken_get_tool_shell_wrapper(shiboken tool_wrapper) + add_custom_command( -OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" -BYPRODUCTS ${sample_SRC} -COMMAND shiboken6 --project-file=${CMAKE_CURRENT_BINARY_DIR}/sample-binding.txt ${GENERATOR_EXTRA_FLAGS} -DEPENDS ${sample_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h shiboken6 -WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -COMMENT "Running generator for 'sample' test binding..." + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" + BYPRODUCTS ${sample_SRC} + COMMAND + ${tool_wrapper} + $<TARGET_FILE:Shiboken6::shiboken6> + --project-file=${CMAKE_CURRENT_BINARY_DIR}/sample-binding.txt + ${GENERATOR_EXTRA_FLAGS} + DEPENDS ${sample_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h Shiboken6::shiboken6 + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Running generator for 'sample' test binding..." ) add_library(sample MODULE ${sample_SRC}) diff --git a/sources/shiboken6/tests/samplebinding/__del___test.py b/sources/shiboken6/tests/samplebinding/__del___test.py index 146e6e409..456886614 100644 --- a/sources/shiboken6/tests/samplebinding/__del___test.py +++ b/sources/shiboken6/tests/samplebinding/__del___test.py @@ -1,34 +1,8 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +import gc import os import sys import unittest @@ -42,17 +16,21 @@ import sample delCalled = False + class MyObject(sample.ObjectType): def __del__(self): global delCalled delCalled = True + class TestDel(unittest.TestCase): def testIt(self): a = MyObject() del a + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertTrue(delCalled) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/abstract_test.py b/sources/shiboken6/tests/samplebinding/abstract_test.py index 7fa0a0012..89e87be1d 100644 --- a/sources/shiboken6/tests/samplebinding/abstract_test.py +++ b/sources/shiboken6/tests/samplebinding/abstract_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for Abstract class''' @@ -42,10 +15,12 @@ init_paths() from sample import Abstract + class Incomplete(Abstract): def __init__(self): Abstract.__init__(self) + class Concrete(Abstract): def __init__(self): Abstract.__init__(self) @@ -87,12 +62,7 @@ class AbstractTest(unittest.TestCase): # Python and calling it from C++ is undefined until it's decided how to # cast the Python data types to void pointers c = Concrete() - self.assertEqual(c.pureVirtualReturningVoidPtr(),42) - - def testReimplementedVirtualMethodCall(self): - '''Test if instanciation of an abstract class raises the correct exception.''' - i = Concrete() - self.assertRaises(NotImplementedError, i.callPureVirtual) + self.assertEqual(c.pureVirtualReturningVoidPtr(), 42) def testReimplementedVirtualMethodCall(self): '''Test if a Python override of a virtual method is correctly called from C++.''' @@ -112,6 +82,6 @@ class AbstractTest(unittest.TestCase): c.callVirtualGettingEnum(Abstract.Short) self.assertTrue(c.virtual_getting_enum) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/addedfunction_test.py b/sources/shiboken6/tests/samplebinding/addedfunction_test.py index 134e73c55..0b5680143 100644 --- a/sources/shiboken6/tests/samplebinding/addedfunction_test.py +++ b/sources/shiboken6/tests/samplebinding/addedfunction_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for added functions.''' @@ -41,6 +14,7 @@ from shiboken_paths import init_paths init_paths() from sample import SampleNamespace, ObjectType, Point + class TestAddedFunctionsWithSimilarTypes(unittest.TestCase): '''Adds new signatures very similar to already existing ones.''' @@ -65,5 +39,6 @@ class TestAddedFunctionsWithSimilarTypes(unittest.TestCase): control = len(obj.objectName()) self.assertEqual(SampleNamespace.passReferenceToObjectType(obj), control) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/addedfunction_with_container_args_test.py b/sources/shiboken6/tests/samplebinding/addedfunction_with_container_args_test.py index 570d3ddd9..2a739033b 100644 --- a/sources/shiboken6/tests/samplebinding/addedfunction_with_container_args_test.py +++ b/sources/shiboken6/tests/samplebinding/addedfunction_with_container_args_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for added functions with nested and multi-argument container types.''' @@ -41,18 +14,20 @@ from shiboken_paths import init_paths init_paths() from sample import sum2d, sumproduct + class TestAddedFunctionsWithContainerArgs(unittest.TestCase): '''Tests added functions with nested and multi-argument container types.''' def testNestedContainerType(self): '''Test added function with single-argument containers.''' - values = [[1,2],[3,4,5],[6]] + values = [[1, 2], [3, 4, 5], [6]] self.assertEqual(sum2d(values), 21) def testMultiArgContainerType(self): '''Test added function with a two-argument container.''' - values = [(1,2),(3,4),(5,6)] + values = [(1, 2), (3, 4), (5, 6)] self.assertEqual(sumproduct(values), 44) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/argumentmodifications_test.py b/sources/shiboken6/tests/samplebinding/argumentmodifications_test.py index 86d0a4731..b0ca56a6d 100644 --- a/sources/shiboken6/tests/samplebinding/argumentmodifications_test.py +++ b/sources/shiboken6/tests/samplebinding/argumentmodifications_test.py @@ -1,36 +1,10 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for method arguments modifications performed as described on typesystem.''' +import gc import os import sys import unittest @@ -42,6 +16,7 @@ init_paths() from sample import Modifications, Point + class ArgumentModificationsTest(unittest.TestCase): '''Test cases for method arguments modifications performed as described on typesystem.''' @@ -50,6 +25,8 @@ class ArgumentModificationsTest(unittest.TestCase): def tearDown(self): del self.mods + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() def testArgRemoval0(self): '''Tests argument removal modifications on Modifications.argRemoval0.''' @@ -64,7 +41,8 @@ class ArgumentModificationsTest(unittest.TestCase): def testArgRemoval1(self): '''Tests argument removal modifications on Modifications.argRemoval1.''' - # void [-> PyObject*] argRemoval1(int, bool, Point = Point(1, 2) [removed], Point = Point(3, 4) [removed], int = 333) + # void [-> PyObject*] argRemoval1(int, bool, Point = Point(1, 2) [removed], + # Point = Point(3, 4) [removed], int = 333) # code-injection: returns tuple with received parameters plus removed ones a0, a1, a2 = 1, True, 2 self.assertEqual(self.mods.argRemoval1(a0, a1), (a0, a1, Point(1, 2), Point(3, 4), 333)) @@ -75,7 +53,8 @@ class ArgumentModificationsTest(unittest.TestCase): def testArgRemoval2(self): '''Tests argument removal modifications on Modifications.argRemoval2.''' - # void [-> PyObject*] argRemoval2(int, bool, Point = Point(1, 2) [removed], Point = Point(3, 4) [removed], int = 333) + # void [-> PyObject*] argRemoval2(int, bool, Point = Point(1, 2) + # [removed], Point = Point(3, 4) [removed], int = 333) # code-injection: returns tuple with received parameters plus removed ones a0, a1, a2 = 1, True, 2 self.assertEqual(self.mods.argRemoval2(a0, a1), (a0, a1, Point(1, 2), Point(3, 4), 333)) @@ -83,7 +62,8 @@ class ArgumentModificationsTest(unittest.TestCase): def testArgRemoval3(self): '''Tests argument removal modifications on Modifications.argRemoval3.''' - # void [-> PyObject*] argRemoval3(int, Point = Point(1, 2) [removed], bool = true, Point = Point(3, 4) [removed], int = 333) + # void [-> PyObject*] argRemoval3(int, Point = Point(1, 2) [removed], + # bool = true, Point = Point(3, 4) [removed], int = 333) # code-injection: returns tuple with received parameters plus removed ones a0, a1, a2 = 1, True, 2 self.assertEqual(self.mods.argRemoval3(a0), (a0, Point(1, 2), True, Point(3, 4), 333)) @@ -92,7 +72,8 @@ class ArgumentModificationsTest(unittest.TestCase): def testArgRemoval4(self): '''Tests argument removal modifications on Modifications.argRemoval4.''' - # void [-> PyObject*] argRemoval4(int, Point [removed, new val = Point(6, 9)], bool, Point = Point(3, 4) [removed], int = 333) + # void [-> PyObject*] argRemoval4(int, Point [removed, new val = Point(6, 9)], bool, + # Point = Point(3, 4) [removed], int = 333) # code-injection: returns tuple with received parameters plus removed ones a0, a1, a2 = 1, True, 2 self.assertRaises(TypeError, self.mods.argRemoval4, a0) @@ -112,6 +93,6 @@ class ArgumentModificationsTest(unittest.TestCase): # code-injection: returns tuple with received parameters plus removed ones self.assertEqual(self.mods.argRemoval5(a0, a1, a2), (200, a0, a1, a2)) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/array_numpy_test.py b/sources/shiboken6/tests/samplebinding/array_numpy_test.py index c3d438a88..0d73bca1c 100644 --- a/sources/shiboken6/tests/samplebinding/array_numpy_test.py +++ b/sources/shiboken6/tests/samplebinding/array_numpy_test.py @@ -1,32 +1,6 @@ #!/usr/bin/env python - -############################################################################# -## -## Copyright (C) 2017 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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test case for NumPy Array types.''' @@ -48,24 +22,26 @@ try: except ImportError: pass + class ArrayTester(unittest.TestCase): '''Test case for NumPy arrays.''' def testIntArray(self): - intList = numpy.array([1, 2, 3, 4], dtype = 'int32') + intList = numpy.array([1, 2, 3, 4], dtype='int32') self.assertEqual(sample.sumIntArray(intList), 10) def testDoubleArray(self): - doubleList = numpy.array([1, 2, 3, 4], dtype = 'double') + doubleList = numpy.array([1, 2, 3, 4], dtype='double') self.assertEqual(sample.sumDoubleArray(doubleList), 10) def testIntMatrix(self): - intMatrix = numpy.array([[1, 2, 3], [4, 5, 6]], dtype = 'int32') + intMatrix = numpy.array([[1, 2, 3], [4, 5, 6]], dtype='int32') self.assertEqual(sample.sumIntMatrix(intMatrix), 21) def testDoubleMatrix(self): - doubleMatrix = numpy.array([[1, 2, 3], [4, 5, 6]], dtype = 'double') + doubleMatrix = numpy.array([[1, 2, 3], [4, 5, 6]], dtype='double') self.assertEqual(sample.sumDoubleMatrix(doubleMatrix), 21) + if __name__ == '__main__' and hasNumPy: unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/array_sequence_test.py b/sources/shiboken6/tests/samplebinding/array_sequence_test.py index e39c2733c..ad65d58db 100644 --- a/sources/shiboken6/tests/samplebinding/array_sequence_test.py +++ b/sources/shiboken6/tests/samplebinding/array_sequence_test.py @@ -1,32 +1,6 @@ #!/usr/bin/env python - -############################################################################# -## -## Copyright (C) 2017 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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test case for Array types (PySequence).''' @@ -40,6 +14,7 @@ from shiboken_paths import init_paths init_paths() import sample + class ArrayTester(unittest.TestCase): '''Test case for arrays.''' @@ -56,5 +31,6 @@ class ArrayTester(unittest.TestCase): doubleList = [1.2, 2.3, 3.4, 4.5] self.assertEqual(sample.sumDoubleArray(doubleList), 11.4) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/bug_554_test.py b/sources/shiboken6/tests/samplebinding/bug_554_test.py index f3950af9c..a7e7a7210 100644 --- a/sources/shiboken6/tests/samplebinding/bug_554_test.py +++ b/sources/shiboken6/tests/samplebinding/bug_554_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Unit test for bug#554''' @@ -38,15 +11,15 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import ObjectType + class Bug554: def crash(self): class Crasher(ObjectType): pass + if __name__ == '__main__': bug = Bug554() bug.crash() - - diff --git a/sources/shiboken6/tests/samplebinding/bug_704_test.py b/sources/shiboken6/tests/samplebinding/bug_704_test.py index 365941b46..c470fe723 100644 --- a/sources/shiboken6/tests/samplebinding/bug_704_test.py +++ b/sources/shiboken6/tests/samplebinding/bug_704_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -52,13 +25,12 @@ def defineNewStyle(): class ObjectTypeTest(unittest.TestCase): - '''Test cases to avoid declaring Shiboken classes with multiple inheritance from old style classes.''' + '''Test cases to avoid declaring Shiboken classes with multiple inheritance + from old style classes.''' def testObjectTypeNewStype(self): defineNewStyle() - if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/bytearray_test.py b/sources/shiboken6/tests/samplebinding/bytearray_test.py index bcf61a2d5..e51a899fa 100644 --- a/sources/shiboken6/tests/samplebinding/bytearray_test.py +++ b/sources/shiboken6/tests/samplebinding/bytearray_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -61,7 +34,7 @@ class ByteArrayConcatenationOperatorTest(unittest.TestCase): def testConcatPythonStringAndByteArray(self): # Test concatenation of a Python string with a ByteArray, in this order. - concat_python_string_add_qbytearray_worked = True + concat_python_string_add_qbytearray_worked = True # noqa: F841 ba = ByteArray('foo') result = 'bar\x00' + ba self.assertEqual(type(result), ByteArray) @@ -107,14 +80,14 @@ class ByteArrayOperatorAt(unittest.TestCase): # ByteArray[x] where x is a valid index (reverse order). string = 'abcdefgh' obj = ByteArray(string) - for i in range(len(string)-1, 0, -1): + for i in range(len(string) - 1, 0, -1): self.assertEqual(obj[i], bytes(string[i], "UTF8")) def testOutOfRange(self): # ByteArray[x] where x is out of index. string = '1234567' obj = ByteArray(string) - self.assertRaises(IndexError, lambda :obj[len(string)]) + self.assertRaises(IndexError, lambda: obj[len(string)]) def testNullStrings(self): ba = ByteArray('\x00') diff --git a/sources/shiboken6/tests/samplebinding/child_return_test.py b/sources/shiboken6/tests/samplebinding/child_return_test.py index 4b9a18e7b..f0ac70626 100644 --- a/sources/shiboken6/tests/samplebinding/child_return_test.py +++ b/sources/shiboken6/tests/samplebinding/child_return_test.py @@ -1,36 +1,10 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''The BlackBox class has cases of ownership transference between C++ and Python.''' +import gc import os import sys import unittest @@ -40,7 +14,8 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import ObjectType + class ReturnOfChildTest(unittest.TestCase): '''The BlackBox class has cases of ownership transference between C++ and Python.''' @@ -50,6 +25,8 @@ class ReturnOfChildTest(unittest.TestCase): o1 = ObjectType.createWithChild() child = o1.children()[0] del o1 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, child.objectName) def testKillParentKeepingChild2(self): @@ -57,8 +34,10 @@ class ReturnOfChildTest(unittest.TestCase): o1 = ObjectType.createWithChild() child = o1.findChild("child") del o1 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, child.objectName) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/class_fields_test.py b/sources/shiboken6/tests/samplebinding/class_fields_test.py index a29c84b1a..1eeb3d446 100644 --- a/sources/shiboken6/tests/samplebinding/class_fields_test.py +++ b/sources/shiboken6/tests/samplebinding/class_fields_test.py @@ -1,39 +1,11 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Simple test case for accessing the exposed C++ class fields.''' import os import sys -from sys import getrefcount import unittest from pathlib import Path @@ -43,6 +15,7 @@ init_paths() from sample import Derived, Point, ObjectType + class TestAccessingCppFields(unittest.TestCase): '''Simple test case for accessing the exposed C++ class fields.''' @@ -64,7 +37,7 @@ class TestAccessingCppFields(unittest.TestCase): self.assertEqual(d.primitiveField, int(value)) # attribution with invalid type - self.assertRaises(TypeError, lambda : setattr(d, 'primitiveField', None)) + self.assertRaises(TypeError, lambda: setattr(d, 'primitiveField', None)) def testAccessingRenamedFields(self): '''Reads and writes a renamed field.''' @@ -100,7 +73,7 @@ class TestAccessingCppFields(unittest.TestCase): self.assertNotEqual(d.userPrimitiveField, old_value) # attribution with invalid type - self.assertRaises(TypeError, lambda : setattr(d, 'userPrimitiveField', None)) + self.assertRaises(TypeError, lambda: setattr(d, 'userPrimitiveField', None)) def testAccessingValueTypeField(self): '''Reads and writes a value type (in this case a 'Point') field.''' @@ -108,7 +81,7 @@ class TestAccessingCppFields(unittest.TestCase): self.assertEqual(type(d.valueTypeField), Point) # attribution - old_value = d.valueTypeField + old_value = d.valueTypeField # noqa: F841 new_value = Point(-10, 537) d.valueTypeField = new_value self.assertEqual(d.valueTypeField, new_value) @@ -120,7 +93,7 @@ class TestAccessingCppFields(unittest.TestCase): self.assertEqual(d.valueTypeField.y(), 20) # attribution with invalid type - self.assertRaises(TypeError, lambda : setattr(d, 'valueTypeField', 123)) + self.assertRaises(TypeError, lambda: setattr(d, 'valueTypeField', 123)) def testAccessingObjectTypeField(self): '''Reads and writes a object type (in this case an 'ObjectType') field.''' @@ -139,36 +112,40 @@ class TestAccessingCppFields(unittest.TestCase): self.assertEqual(d.objectTypeField, value) # attribution with invalid type - self.assertRaises(TypeError, lambda : setattr(d, 'objectTypeField', 123)) + self.assertRaises(TypeError, lambda: setattr(d, 'objectTypeField', 123)) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testRefCountingAccessingObjectTypeField(self): '''Accessing a object type field should respect the reference counting rules.''' d = Derived() # attributing object to instance's field should increase its reference count o1 = ObjectType() - refcount1 = getrefcount(o1) + refcount1 = sys.getrefcount(o1) d.objectTypeField = o1 self.assertEqual(d.objectTypeField, o1) - self.assertEqual(getrefcount(d.objectTypeField), refcount1 + 1) + self.assertEqual(sys.getrefcount(d.objectTypeField), refcount1 + 1) - # attributing a new object to instance's field should decrease the previous object's reference count + # attributing a new object to instance's field should decrease the previous + # object's reference count o2 = ObjectType() - refcount2 = getrefcount(o2) + refcount2 = sys.getrefcount(o2) d.objectTypeField = o2 self.assertEqual(d.objectTypeField, o2) - self.assertEqual(getrefcount(o1), refcount1) - self.assertEqual(getrefcount(d.objectTypeField), refcount2 + 1) + self.assertEqual(sys.getrefcount(o1), refcount1) + self.assertEqual(sys.getrefcount(d.objectTypeField), refcount2 + 1) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testRefCountingOfReferredObjectAfterDeletingReferrer(self): - '''Deleting the object referring to other object should decrease the reference count of the referee.''' + '''Deleting the object referring to other object should decrease the + reference count of the referee.''' d = Derived() o = ObjectType() - refcount = getrefcount(o) + refcount = sys.getrefcount(o) d.objectTypeField = o - self.assertEqual(getrefcount(o), refcount + 1) + self.assertEqual(sys.getrefcount(o), refcount + 1) del d - self.assertEqual(getrefcount(o), refcount) + self.assertEqual(sys.getrefcount(o), refcount) def testStaticField(self): self.assertEqual(Derived.staticPrimitiveField, 0) @@ -179,7 +156,7 @@ class TestAccessingCppFields(unittest.TestCase): # attribution old_value = d.bitField new_value = 1 - d.bitField= new_value + d.bitField = new_value self.assertEqual(d.bitField, new_value) self.assertNotEqual(d.bitField, old_value) @@ -189,7 +166,7 @@ class TestAccessingCppFields(unittest.TestCase): self.assertEqual(d.bitField, int(value)) # attribution with invalid type - self.assertRaises(TypeError, lambda : setattr(d, 'bitField', None)) + self.assertRaises(TypeError, lambda: setattr(d, 'bitField', None)) if __name__ == '__main__': diff --git a/sources/shiboken6/tests/samplebinding/collector_test.py b/sources/shiboken6/tests/samplebinding/collector_test.py index c68230474..4caebc62a 100644 --- a/sources/shiboken6/tests/samplebinding/collector_test.py +++ b/sources/shiboken6/tests/samplebinding/collector_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for Collector class' shift operators.''' @@ -60,6 +33,7 @@ class CollectorTest(unittest.TestCase): self.assertEqual(collector.size(), 5) self.assertEqual(collector.items(), [2, 3, 5, 7, 11]) + class CollectorExternalOperator(unittest.TestCase): '''Test cases for external operators of Collector''' @@ -84,4 +58,3 @@ class CollectorObjectType(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/complex_test.py b/sources/shiboken6/tests/samplebinding/complex_test.py index 272eee357..454aff100 100644 --- a/sources/shiboken6/tests/samplebinding/complex_test.py +++ b/sources/shiboken6/tests/samplebinding/complex_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for Complex class''' @@ -43,6 +16,7 @@ init_paths() import sample from sample import Point + class ComplexTest(unittest.TestCase): '''Test case for conversions between C++ Complex class to Python complex class''' @@ -74,11 +48,14 @@ class ComplexTest(unittest.TestCase): def testUsingTuples(self): cpx1, cpx2 = (1.2, 3.4), (5.6, 7.8) - self.assertEqual(sample.sumComplexPair((cpx1, cpx2)), sample.sumComplexPair((complex(*cpx1), complex(*cpx2)))) + self.assertEqual(sample.sumComplexPair((cpx1, cpx2)), + sample.sumComplexPair((complex(*cpx1), complex(*cpx2)))) cpx1, cpx2 = (1, 3), (5, 7) - self.assertEqual(sample.sumComplexPair((cpx1, cpx2)), sample.sumComplexPair((complex(*cpx1), complex(*cpx2)))) + self.assertEqual(sample.sumComplexPair((cpx1, cpx2)), + sample.sumComplexPair((complex(*cpx1), complex(*cpx2)))) cpx1, cpx2 = (1.2, 3), (5.6, 7) - self.assertEqual(sample.sumComplexPair((cpx1, cpx2)), sample.sumComplexPair((complex(*cpx1), complex(*cpx2)))) + self.assertEqual(sample.sumComplexPair((cpx1, cpx2)), + sample.sumComplexPair((complex(*cpx1), complex(*cpx2)))) cpx1, cpx2 = (1, 2, 3), (4, 5, 7) self.assertRaises(TypeError, sample.sumComplexPair, (cpx1, cpx2)) cpx1, cpx2 = ('1', '2'), ('4', '5') @@ -87,4 +64,3 @@ class ComplexTest(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/conversion_operator_test.py b/sources/shiboken6/tests/samplebinding/conversion_operator_test.py index eb802f43b..7e76245b1 100644 --- a/sources/shiboken6/tests/samplebinding/conversion_operator_test.py +++ b/sources/shiboken6/tests/samplebinding/conversion_operator_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for implicit conversion generated by conversion operator.''' @@ -42,11 +15,13 @@ init_paths() from sample import Time, StrList + class ConversionOperatorTest(unittest.TestCase): '''Test cases for implicit conversion generated by conversion operator.''' def testConversionOperator(self): - '''Time defined an conversion operator for Str, so passing a Time object to a method expecting a Str should work.''' + '''Time defined an conversion operator for Str, so passing a Time object + to a method expecting a Str should work.''' t = Time(1, 2, 3) t_str = t.toString() sl = StrList() @@ -57,6 +32,6 @@ class ConversionOperatorTest(unittest.TestCase): self.assertEqual(len(sl), 1) self.assertEqual(sl[0], t_str) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/copy_test.py b/sources/shiboken6/tests/samplebinding/copy_test.py index 63d9163ba..db539d1b9 100644 --- a/sources/shiboken6/tests/samplebinding/copy_test.py +++ b/sources/shiboken6/tests/samplebinding/copy_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for deep copy of objects''' @@ -90,4 +63,3 @@ class PicklingTest(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/ctorconvrule_test.py b/sources/shiboken6/tests/samplebinding/ctorconvrule_test.py index be8e11bc4..5e2695d72 100644 --- a/sources/shiboken6/tests/samplebinding/ctorconvrule_test.py +++ b/sources/shiboken6/tests/samplebinding/ctorconvrule_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for proper generation of constructor altered by conversion-rule tag.''' @@ -42,6 +15,7 @@ init_paths() from sample import CtorConvRule + class TestCtorConvRule(unittest.TestCase): '''Simple test case for CtorConvRule''' @@ -51,6 +25,6 @@ class TestCtorConvRule(unittest.TestCase): obj = CtorConvRule(value) self.assertEqual(obj.value(), value + 1) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/cyclic_test.py b/sources/shiboken6/tests/samplebinding/cyclic_test.py index 5a20216b6..4e4ae2603 100644 --- a/sources/shiboken6/tests/samplebinding/cyclic_test.py +++ b/sources/shiboken6/tests/samplebinding/cyclic_test.py @@ -1,34 +1,8 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +import gc import os import sys import unittest @@ -42,7 +16,6 @@ from sample import ObjectView from sample import ObjectModel - class ObjTest(unittest.TestCase): def test_cyclic_dependency_withParent(self): @@ -50,8 +23,6 @@ class ObjTest(unittest.TestCase): only be removed by the garbage collector, and then invoke the garbage collector in a different thread. """ - import gc - class CyclicChildObject(ObjectType): def __init__(self, parent): super(CyclicChildObject, self).__init__(parent) @@ -65,7 +36,7 @@ class ObjTest(unittest.TestCase): # turn off automatic garbage collection, to be able to trigger it # at the 'right' time gc.disable() - alive = lambda :sum(isinstance(o, CyclicObject) for o in gc.get_objects() ) + alive = lambda: sum(isinstance(o, CyclicObject) for o in gc.get_objects()) # noqa: E731 # # first proof that the wizard is only destructed by the garbage @@ -74,7 +45,9 @@ class ObjTest(unittest.TestCase): cycle = CyclicObject() self.assertTrue(alive()) del cycle - self.assertTrue(alive()) + if not hasattr(sys, "pypy_version_info"): + # PYSIDE-535: the semantics of gc.enable/gc.disable is different for PyPy + self.assertTrue(alive()) gc.collect() self.assertFalse(alive()) @@ -83,8 +56,6 @@ class ObjTest(unittest.TestCase): only be removed by the garbage collector, and then invoke the garbage collector in a different thread. """ - import gc - class CyclicChildObject(ObjectView): def __init__(self, model): super(CyclicChildObject, self).__init__(None) @@ -98,7 +69,7 @@ class ObjTest(unittest.TestCase): # turn off automatic garbage collection, to be able to trigger it # at the 'right' time gc.disable() - alive = lambda :sum(isinstance(o, CyclicObject) for o in gc.get_objects() ) + alive = lambda: sum(isinstance(o, CyclicObject) for o in gc.get_objects()) # noqa: E731 # # first proof that the wizard is only destructed by the garbage @@ -107,10 +78,12 @@ class ObjTest(unittest.TestCase): cycle = CyclicObject() self.assertTrue(alive()) del cycle - self.assertTrue(alive()) + if not hasattr(sys, "pypy_version_info"): + # PYSIDE-535: the semantics of gc.enable/gc.disable is different for PyPy + self.assertTrue(alive()) gc.collect() self.assertFalse(alive()) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/date_test.py b/sources/shiboken6/tests/samplebinding/date_test.py index ad1419391..2b6efcf18 100644 --- a/sources/shiboken6/tests/samplebinding/date_test.py +++ b/sources/shiboken6/tests/samplebinding/date_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for python conversions types ''' @@ -43,6 +16,7 @@ from datetime import date from sample import SbkDate + class DateConversionTest(unittest.TestCase): def testConstructorWithDateObject(self): @@ -59,6 +33,6 @@ class DateConversionTest(unittest.TestCase): self.assertTrue(cDate.month(), pyDate.month) self.assertTrue(cDate.year(), pyDate.year) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/decisor_test.py b/sources/shiboken6/tests/samplebinding/decisor_test.py index 128b3c913..0d39c5f96 100644 --- a/sources/shiboken6/tests/samplebinding/decisor_test.py +++ b/sources/shiboken6/tests/samplebinding/decisor_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for the method overload decisor.''' @@ -42,6 +15,7 @@ init_paths() from sample import SampleNamespace, Point, ObjectType, ObjectModel + class DecisorTest(unittest.TestCase): '''Test cases for the method overload decisor.''' @@ -64,11 +38,15 @@ class DecisorTest(unittest.TestCase): '''Call methods overloads that receive parent and inheritor classes' instances.''' objecttype = ObjectType() objectmodel = ObjectModel() - self.assertEqual(ObjectModel.receivesObjectTypeFamily(objecttype), ObjectModel.ObjectTypeCalled) - self.assertNotEqual(ObjectModel.receivesObjectTypeFamily(objecttype), ObjectModel.ObjectModelCalled) - self.assertEqual(ObjectModel.receivesObjectTypeFamily(objectmodel), ObjectModel.ObjectModelCalled) - self.assertNotEqual(ObjectModel.receivesObjectTypeFamily(objectmodel), ObjectModel.ObjectTypeCalled) + self.assertEqual(ObjectModel.receivesObjectTypeFamily(objecttype), + ObjectModel.ObjectTypeCalled) + self.assertNotEqual(ObjectModel.receivesObjectTypeFamily(objecttype), + ObjectModel.ObjectModelCalled) + self.assertEqual(ObjectModel.receivesObjectTypeFamily(objectmodel), + ObjectModel.ObjectModelCalled) + self.assertNotEqual(ObjectModel.receivesObjectTypeFamily(objectmodel), + ObjectModel.ObjectTypeCalled) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/delete_test.py b/sources/shiboken6/tests/samplebinding/delete_test.py index 8fb663eb1..57a792ae2 100644 --- a/sources/shiboken6/tests/samplebinding/delete_test.py +++ b/sources/shiboken6/tests/samplebinding/delete_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -41,15 +14,15 @@ init_paths() import sample from shiboken6 import Shiboken + class DeleteTest(unittest.TestCase): def testNonCppWrapperClassDelete(self): - """Would segfault when shiboken.delete called on obj not created from - Python """ + """Would segfault when shiboken.delete called on obj not created from Python.""" obj = sample.ObjectType() child = obj.createChild(None) Shiboken.delete(child) assert not Shiboken.isValid(child) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/deprecated_test.py b/sources/shiboken6/tests/samplebinding/deprecated_test.py index 8a1d37cfc..c371df94f 100644 --- a/sources/shiboken6/tests/samplebinding/deprecated_test.py +++ b/sources/shiboken6/tests/samplebinding/deprecated_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -41,11 +14,13 @@ init_paths() from sample import ObjectType + class TestDeprecatedCall(unittest.TestCase): def testCallWithError(self): o = ObjectType() warnings.simplefilter('error') self.assertRaises(DeprecationWarning, o.deprecatedFunction) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/derived_test.py b/sources/shiboken6/tests/samplebinding/derived_test.py index 8bdb051a8..346f29136 100644 --- a/sources/shiboken6/tests/samplebinding/derived_test.py +++ b/sources/shiboken6/tests/samplebinding/derived_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for Derived class''' @@ -43,6 +16,7 @@ init_paths() import sample from sample import Abstract, Derived, DerivedUsingCt, OverloadedFuncEnum + class Deviant(Derived): def __init__(self): Derived.__init__(self) @@ -58,6 +32,16 @@ class Deviant(Derived): def className(self): return 'Deviant' + +class ImplementVirtualWithOutParameter(Derived): + def __init__(self, value): + super().__init__() + self._value = value + + def virtualWithOutParameter(self): + return self._value + + class DerivedTest(unittest.TestCase): '''Test case for Derived class''' @@ -67,22 +51,6 @@ class DerivedTest(unittest.TestCase): 'id_', 'pureVirtual', 'unpureVirtual']) self.assertTrue(inherited_methods.issubset(dir(Derived))) - def testOverloadedMethodCall(self): - '''Test if the correct overloaded method is being called.''' - derived = Derived() - - result = derived.overloaded(1, 2) - self.assertEqual(type(result), OverloadedFuncEnum) - self.assertEqual(result, sample.OverloadedFunc_ii) - - result = derived.overloaded(3) - self.assertEqual(type(result), OverloadedFuncEnum) - self.assertEqual(result, sample.OverloadedFunc_ii) - - result = derived.overloaded(4.4) - self.assertEqual(type(result), OverloadedFuncEnum) - self.assertEqual(result, sample.OverloadedFunc_d) - def testOtherOverloadedMethodCall(self): '''Another test to check overloaded method calling, just to double check.''' derived = Derived() @@ -100,21 +68,23 @@ class DerivedTest(unittest.TestCase): derived = Derived() result = derived.overloaded(1.1, 2.2) self.assertEqual(type(result), OverloadedFuncEnum) - self.assertEqual(result, sample.OverloadedFunc_ii) def testOverloadedMethodCallWithWrongNumberOfArguments(self): - '''Test if a call to an overloaded method with the wrong number of arguments raises an exception.''' + '''Test if a call to an overloaded method with the wrong number of arguments + raises an exception.''' derived = Derived() self.assertRaises(TypeError, derived.otherOverloaded, 1, 2, True) def testReimplementedPureVirtualMethodCall(self): - '''Test if a Python override of a implemented pure virtual method is correctly called from C++.''' + '''Test if a Python override of a implemented pure virtual method is + correctly called from C++.''' d = Deviant() d.callPureVirtual() self.assertTrue(d.pure_virtual_called) def testReimplementedVirtualMethodCall(self): - '''Test if a Python override of a reimplemented virtual method is correctly called from C++.''' + '''Test if a Python override of a reimplemented virtual method is + correctly called from C++.''' d = Deviant() d.callUnpureVirtual() self.assertTrue(d.unpure_virtual_called) @@ -126,7 +96,8 @@ class DerivedTest(unittest.TestCase): self.assertEqual(d.getClassName(), 'Derived') def testReimplementedVirtualMethodCallReturningString(self): - '''Test if a Python override of a reimplemented virtual method is correctly called from C++.''' + '''Test if a Python override of a reimplemented virtual method is + correctly called from C++.''' d = Deviant() self.assertEqual(d.className(), 'Deviant') self.assertEqual(d.getClassName(), 'Deviant') @@ -150,7 +121,8 @@ class DerivedTest(unittest.TestCase): self.assertEqual(Abstract.getObjectId(d), objId) def testObjectCreationWithParentType(self): - '''Derived class creates an instance of itself in C++ and returns it as a pointer to its ancestor Abstract.''' + '''Derived class creates an instance of itself in C++ and returns it as + a pointer to its ancestor Abstract.''' obj = Derived.createObject() self.assertEqual(type(obj), Derived) @@ -159,7 +131,13 @@ class DerivedTest(unittest.TestCase): obj = DerivedUsingCt(42) self.assertEqual(obj.value(), 42) + def testVirtualWithOutParameter(self): + d = Derived() + self.assertEqual(d.callVirtualWithOutParameter(), 42) + + d = ImplementVirtualWithOutParameter(1) + self.assertEqual(d.callVirtualWithOutParameter(), 1) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/duck_punching_test.py b/sources/shiboken6/tests/samplebinding/duck_punching_test.py index 9b0d7a9ff..aa21a0f7e 100644 --- a/sources/shiboken6/tests/samplebinding/duck_punching_test.py +++ b/sources/shiboken6/tests/samplebinding/duck_punching_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for virtual methods.''' @@ -43,6 +16,7 @@ init_paths() from sample import VirtualMethods, SimpleFile, Point + def MethodTypeCompat(func, instance): return types.MethodType(func, instance) @@ -51,10 +25,12 @@ class Duck(VirtualMethods): def __init__(self): VirtualMethods.__init__(self) + class Monkey(SimpleFile): def __init__(self, filename): SimpleFile.__init__(self, filename) + class DuckPunchingTest(unittest.TestCase): '''Test case for duck punching (aka "monkey patching").''' @@ -83,7 +59,8 @@ class DuckPunchingTest(unittest.TestCase): result2 = vm.virtualMethod0(pt, val, cpx, b) self.assertEqual(result1, result2) - self.assertEqual(result1, VirtualMethods.virtualMethod0(vm, pt, val, cpx, b) * self.multiplier) + self.assertEqual(result1, + VirtualMethods.virtualMethod0(vm, pt, val, cpx, b) * self.multiplier) # This is done to decrease the refcount of the vm object # allowing the object wrapper to be deleted before the @@ -93,7 +70,8 @@ class DuckPunchingTest(unittest.TestCase): vm.virtualMethod0 = None def testMonkeyPatchOnVirtualMethodWithInheritance(self): - '''Injects new 'virtualMethod0' on an object that inherits from VirtualMethods and makes C++ call it.''' + '''Injects new 'virtualMethod0' on an object that inherits from + VirtualMethods and makes C++ call it.''' duck = Duck() pt, val, cpx, b = Point(1.1, 2.2), 4, complex(3.3, 4.4), True @@ -112,7 +90,8 @@ class DuckPunchingTest(unittest.TestCase): result2 = duck.virtualMethod0(pt, val, cpx, b) self.assertEqual(result1, result2) - self.assertEqual(result1, VirtualMethods.virtualMethod0(duck, pt, val, cpx, b) * self.multiplier) + self.assertEqual(result1, + VirtualMethods.virtualMethod0(duck, pt, val, cpx, b) * self.multiplier) duck.virtualMethod0 = None @@ -177,4 +156,3 @@ class DuckPunchingTest(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/echo_test.py b/sources/shiboken6/tests/samplebinding/echo_test.py index 67be482f2..f1859260e 100644 --- a/sources/shiboken6/tests/samplebinding/echo_test.py +++ b/sources/shiboken6/tests/samplebinding/echo_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for <add-function> with const char* as argument''' @@ -42,6 +15,7 @@ init_paths() from sample import Echo + class TestEcho(unittest.TestCase): '''Simple test case for Echo.echo''' @@ -53,7 +27,8 @@ class TestEcho(unittest.TestCase): def testCallOperator(self): e = Echo() - self.assertEqual(e("Hello", 3), "Hello3"); + self.assertEqual(e("Hello", 3), "Hello3") + + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/enum_test.py b/sources/shiboken6/tests/samplebinding/enum_test.py index 66d7daf5b..276b8d894 100644 --- a/sources/shiboken6/tests/samplebinding/enum_test.py +++ b/sources/shiboken6/tests/samplebinding/enum_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## 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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for Python representation of C++ enums.''' @@ -40,33 +13,27 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -import shiboken6 # This is needed after the introduction of BUILD_DIR. import sample from sample import SampleNamespace, ObjectType, Event + def createTempFile(): import tempfile return tempfile.SpooledTemporaryFile(mode='rw') + class EnumTest(unittest.TestCase): '''Test case for Python representation of C++ enums.''' - def testEnumRepr(self): - enum = SampleNamespace.Option(1) - self.assertEqual(eval(repr(enum)), enum) - - enum = SampleNamespace.Option(999) - self.assertEqual(eval(repr(enum)), enum) - def testHashability(self): self.assertEqual(hash(SampleNamespace.TwoIn), hash(SampleNamespace.TwoOut)) self.assertNotEqual(hash(SampleNamespace.TwoIn), hash(SampleNamespace.OneIn)) def testEnumValuesInsideEnum(self): '''Enum values should be accessible inside the enum as well as outside.''' - for value_name in SampleNamespace.Option.values: + for value_name in SampleNamespace.Option.__members__: enum_item1 = getattr(SampleNamespace.Option, value_name) enum_item2 = getattr(SampleNamespace, value_name) self.assertEqual(enum_item1, enum_item2) @@ -92,16 +59,18 @@ class EnumTest(unittest.TestCase): def testEnumConstructorWithTooManyParameters(self): '''Calling the constructor of non-extensible enum with the wrong number of parameters.''' - self.assertRaises(TypeError, SampleNamespace.InValue, 13, 14) + self.assertRaises((TypeError, ValueError), SampleNamespace.InValue, 13, 14) def testEnumConstructorWithNonNumberParameter(self): '''Calling the constructor of non-extensible enum with a string.''' - self.assertRaises(TypeError, SampleNamespace.InValue, '1') + self.assertRaises((TypeError, ValueError), SampleNamespace.InValue, '1') def testEnumItemAsDefaultValueToIntArgument(self): '''Calls function with an enum item as default value to an int argument.''' - self.assertEqual(SampleNamespace.enumItemAsDefaultValueToIntArgument(), SampleNamespace.ZeroIn) - self.assertEqual(SampleNamespace.enumItemAsDefaultValueToIntArgument(SampleNamespace.ZeroOut), SampleNamespace.ZeroOut) + self.assertEqual(SampleNamespace.enumItemAsDefaultValueToIntArgument(), + SampleNamespace.ZeroIn) + self.assertEqual(SampleNamespace.enumItemAsDefaultValueToIntArgument(SampleNamespace.ZeroOut), # noqa E:501 + SampleNamespace.ZeroOut) self.assertEqual(SampleNamespace.enumItemAsDefaultValueToIntArgument(123), 123) def testAnonymousGlobalEnums(self): @@ -126,49 +95,26 @@ class EnumTest(unittest.TestCase): self.assertEqual(event.eventType(), Event.BASIC_EVENT) event.setEventTypeByConstRef(Event.SOME_EVENT) self.assertEqual(event.eventType(), Event.SOME_EVENT) - - def testEnumTpPrintImplementation(self): - '''Without SbkEnum.tp_print 'print' returns the enum represented as an int.''' - tmpfile = createTempFile() - print(Event.ANY_EVENT, file=tmpfile) - tmpfile.seek(0) - text = tmpfile.read().strip() - tmpfile.close() - self.assertEqual(text, str(Event.ANY_EVENT)) - self.assertEqual(text, repr(Event.ANY_EVENT)) + event.setEventTypeByConstPtr(Event.BASIC_EVENT) + self.assertEqual(event.eventType(), Event.BASIC_EVENT) def testEnumArgumentWithDefaultValue(self): '''Option enumArgumentWithDefaultValue(Option opt = UnixTime);''' self.assertEqual(SampleNamespace.enumArgumentWithDefaultValue(), SampleNamespace.UnixTime) - self.assertEqual(SampleNamespace.enumArgumentWithDefaultValue(SampleNamespace.RandomNumber), SampleNamespace.RandomNumber) - - def testSignature(self): - enum = SampleNamespace.Option(1) - types = type(enum).mro() - klass = types[0] - base = types[1] - # The class has an empty signature. - self.assertEqual(klass.__signature__, None) - # The base class must be Enum - self.assertNotEqual(base.__signature__, None) - # It contains an int annotation. - param = base.__signature__.parameters["itemValue"] - self.assertEqual(param.annotation, int) + self.assertEqual(SampleNamespace.enumArgumentWithDefaultValue(SampleNamespace.RandomNumber), # noqa E:501 + SampleNamespace.RandomNumber) class MyEvent(Event): def __init__(self): - Event.__init__(self, Event.EventType(999)) + Event.__init__(self, Event.EventType(3)) + class OutOfBoundsTest(unittest.TestCase): def testValue(self): e = MyEvent() - self.assertEqual(repr(e.eventType()), 'sample.Event.EventType(999)') + self.assertEqual(repr(e.eventType()), "<EventType.ANY_EVENT: 3>") - def testNoneName(self): - e = MyEvent() - t = e.eventType() - self.assertEqual(t.name, None) class EnumOverloadTest(unittest.TestCase): '''Test case for overloads involving enums''' @@ -180,6 +126,7 @@ class EnumOverloadTest(unittest.TestCase): self.assertEqual(o.callWithEnum('', Event.ANY_EVENT, 9), 81) self.assertEqual(o.callWithEnum('', 9), 9) + class EnumOperators(unittest.TestCase): '''Test case for operations on enums''' @@ -189,4 +136,3 @@ class EnumOperators(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/enumfromremovednamespace_test.py b/sources/shiboken6/tests/samplebinding/enumfromremovednamespace_test.py index 72705c4c4..42ae23961 100644 --- a/sources/shiboken6/tests/samplebinding/enumfromremovednamespace_test.py +++ b/sources/shiboken6/tests/samplebinding/enumfromremovednamespace_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -41,15 +14,10 @@ init_paths() import sample from shiboken_test_helper import objectFullname +from shibokensupport.signature import get_signature + class TestEnumFromRemovedNamespace(unittest.TestCase): - def testEnumPromotedToGlobal(self): - sample.RemovedNamespace1_Enum - self.assertEqual(sample.RemovedNamespace1_Enum_Value0, 0) - self.assertEqual(sample.RemovedNamespace1_Enum_Value1, 1) - sample.RemovedNamespace1_AnonymousEnum_Value0 - sample.RemovedNamespace2_Enum - sample.RemovedNamespace2_Enum_Value0 def testNames(self): # Test if invisible namespace does not appear on type name @@ -59,10 +27,10 @@ class TestEnumFromRemovedNamespace(unittest.TestCase): "sample.ObjectOnInvisibleNamespace") # Function arguments - signature = sample.ObjectOnInvisibleNamespace.toInt.__signature__ + signature = get_signature(sample.ObjectOnInvisibleNamespace.toInt) self.assertEqual(objectFullname(signature.parameters['e'].annotation), "sample.RemovedNamespace1_Enum") - signature = sample.ObjectOnInvisibleNamespace.consume.__signature__ + signature = get_signature(sample.ObjectOnInvisibleNamespace.consume) self.assertEqual(objectFullname(signature.parameters['other'].annotation), "sample.ObjectOnInvisibleNamespace") @@ -76,9 +44,8 @@ class TestEnumFromRemovedNamespace(unittest.TestCase): sample.UnremovedNamespace.RemovedNamespace3_AnonymousEnum_Value0 def testNestedFunctionFromRemovedNamespace(self): - self.assertEqual(sample.UnremovedNamespace.nestedMathSum(1, 2), 3) + self.assertEqual(sample.UnremovedNamespace.nestedMathSum(1, 2), 3) if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/event_loop_call_virtual_test.py b/sources/shiboken6/tests/samplebinding/event_loop_call_virtual_test.py index 54ad28ff3..8e13d5d46 100644 --- a/sources/shiboken6/tests/samplebinding/event_loop_call_virtual_test.py +++ b/sources/shiboken6/tests/samplebinding/event_loop_call_virtual_test.py @@ -1,45 +1,17 @@ #!/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 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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Simple event loop dispatcher test.''' import os import sys -import time import unittest from pathlib import Path sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from random import random from sample import ObjectType, Event @@ -67,7 +39,7 @@ class TestEventLoop(unittest.TestCase): objs = [ObjectType(), NoOverride(), Override()] evaluated = ObjectType.processEvent(objs, - Event(Event.BASIC_EVENT)) + Event(Event.BASIC_EVENT)) self.assertEqual(evaluated, 3) self.assertTrue(objs[2].called) diff --git a/sources/shiboken6/tests/samplebinding/event_loop_thread_test.py b/sources/shiboken6/tests/samplebinding/event_loop_thread_test.py index 12410ed88..8b854fca6 100644 --- a/sources/shiboken6/tests/samplebinding/event_loop_thread_test.py +++ b/sources/shiboken6/tests/samplebinding/event_loop_thread_test.py @@ -1,32 +1,6 @@ #!/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 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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os from random import random @@ -90,7 +64,7 @@ class TestEventLoopWithThread(unittest.TestCase): thread.start() evaluated = ObjectType.processEvent(objs, - Event(Event.BASIC_EVENT)) + Event(Event.BASIC_EVENT)) thread.join() diff --git a/sources/shiboken6/tests/samplebinding/exception_test.py b/sources/shiboken6/tests/samplebinding/exception_test.py index 96c389aa8..d9e6b377f 100644 --- a/sources/shiboken6/tests/samplebinding/exception_test.py +++ b/sources/shiboken6/tests/samplebinding/exception_test.py @@ -1,32 +1,6 @@ #!/usr/bin/env python -# -############################################################################# -## -## Copyright (C) 2018 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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -39,6 +13,7 @@ init_paths() from sample import ExceptionTest + class CppExceptionTest(unittest.TestCase): def testVoid(self): @@ -49,14 +24,14 @@ class CppExceptionTest(unittest.TestCase): try: et.voidThrowStdException(True) - except: + except: # noqa: E722 exceptionCount += 1 et.voidThrowInt(False) try: et.voidThrowInt(True) - except: + except: # noqa: E722 exceptionCount += 1 self.assertEqual(exceptionCount, 2) @@ -65,21 +40,32 @@ class CppExceptionTest(unittest.TestCase): exceptionCount = 0 et = ExceptionTest() - result = et.intThrowStdException(False); + result = et.intThrowStdException(False) try: - result = et.intThrowStdException(True); - except: + result = et.intThrowStdException(True) + except: # noqa: E722 exceptionCount += 1 - result = et.intThrowInt(False); + result = et.intThrowInt(False) try: - result = et.intThrowInt(True); - except: + result = et.intThrowInt(True) # noqa: F841 + except: # noqa: E722 exceptionCount += 1 self.assertEqual(exceptionCount, 2) + def testModifications(self): + """PYSIDE-1995, test whether exceptions are propagated + when return ownership modifications are generated.""" + exceptionCount = 0 + try: + et = ExceptionTest.create(True) # noqa: F841 + except: # noqa: E722 + exceptionCount += 1 + self.assertEqual(exceptionCount, 1) + + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/filter_test.py b/sources/shiboken6/tests/samplebinding/filter_test.py index e9c2d5ccc..df805093f 100644 --- a/sources/shiboken6/tests/samplebinding/filter_test.py +++ b/sources/shiboken6/tests/samplebinding/filter_test.py @@ -1,30 +1,5 @@ -############################################################################# -## -## 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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -37,6 +12,7 @@ init_paths() from sample import Data, Intersection, Union + class TestFilters(unittest.TestCase): def testAnd(self): @@ -48,5 +24,6 @@ class TestFilters(unittest.TestCase): self.assertEqual(type(inter), Intersection) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/global.h b/sources/shiboken6/tests/samplebinding/global.h index dd24f274b..64806417a 100644 --- a/sources/shiboken6/tests/samplebinding/global.h +++ b/sources/shiboken6/tests/samplebinding/global.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "abstract.h" #include "blackbox.h" @@ -81,6 +56,7 @@ #include "removednamespaces.h" #include "sample.h" #include "samplenamespace.h" +#include "stdcomplex.h" #include "simplefile.h" #include "size.h" #include "snakecasetest.h" diff --git a/sources/shiboken6/tests/samplebinding/handleholder_test.py b/sources/shiboken6/tests/samplebinding/handleholder_test.py index c1879e3e9..af22328c5 100644 --- a/sources/shiboken6/tests/samplebinding/handleholder_test.py +++ b/sources/shiboken6/tests/samplebinding/handleholder_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 ''' Test case for a class that holds a unknown handle object. Test case for BUG #1105. @@ -44,6 +17,7 @@ init_paths() from sample import HandleHolder + class HandleHolderTest(unittest.TestCase): def testCreation(self): holder = HandleHolder(HandleHolder.createHandle()) @@ -60,5 +34,6 @@ class HandleHolderTest(unittest.TestCase): holder2 = HandleHolder(holder.handle2()) self.assertTrue(holder.compare2(holder2)) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/hashabletype_test.py b/sources/shiboken6/tests/samplebinding/hashabletype_test.py index fae9c724d..c41f5cc06 100644 --- a/sources/shiboken6/tests/samplebinding/hashabletype_test.py +++ b/sources/shiboken6/tests/samplebinding/hashabletype_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for __hash__''' @@ -40,7 +13,8 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import ObjectType, Str + class HashableTest(unittest.TestCase): @@ -56,6 +30,6 @@ class HashableTest(unittest.TestCase): h[o] = 2 self.assertTrue(h.get(o), 2) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/ignorederefop_test.py b/sources/shiboken6/tests/samplebinding/ignorederefop_test.py index 5bd497e43..feb78d045 100644 --- a/sources/shiboken6/tests/samplebinding/ignorederefop_test.py +++ b/sources/shiboken6/tests/samplebinding/ignorederefop_test.py @@ -1,30 +1,5 @@ -############################################################################# -## -## 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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -34,12 +9,14 @@ from pathlib import Path sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import Reference + class TestLackOfDereferenceOperators (unittest.TestCase): def testIf(self): r = Reference() self.assertFalse(hasattr(r, "__mul__")) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/implicitconv_numerical_test.py b/sources/shiboken6/tests/samplebinding/implicitconv_numerical_test.py index 0e3e99d64..081666281 100644 --- a/sources/shiboken6/tests/samplebinding/implicitconv_numerical_test.py +++ b/sources/shiboken6/tests/samplebinding/implicitconv_numerical_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test case for inplicit converting C++ numeric types.''' @@ -54,9 +27,15 @@ if is64bitArchitecture and sys.platform != 'win32': cLongMin = -9223372036854775808 cLongMax = 9223372036854775807 + class NumericTester(unittest.TestCase): '''Helper class for numeric comparison testing''' + def assertRaises(self, *args, **kwds): + if not hasattr(sys, "pypy_version_info"): + # PYSIDE-535: PyPy complains "Fatal RPython error: NotImplementedError" + return super().assertRaises(*args, **kwds) + def check_value(self, source, expected, callback, desired_type=None): result = callback(source) self.assertEqual(result, expected) diff --git a/sources/shiboken6/tests/samplebinding/implicitconv_test.py b/sources/shiboken6/tests/samplebinding/implicitconv_test.py index 782ddba2b..ebafe0c52 100644 --- a/sources/shiboken6/tests/samplebinding/implicitconv_test.py +++ b/sources/shiboken6/tests/samplebinding/implicitconv_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for implicit conversions''' @@ -42,6 +15,7 @@ init_paths() from sample import ImplicitConv, ObjectType + class ImplicitConvTest(unittest.TestCase): '''Test case for implicit conversions''' @@ -70,4 +44,3 @@ class ImplicitConvTest(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/inheritanceandscope_test.py b/sources/shiboken6/tests/samplebinding/inheritanceandscope_test.py index 5d1bde31d..28d62486a 100644 --- a/sources/shiboken6/tests/samplebinding/inheritanceandscope_test.py +++ b/sources/shiboken6/tests/samplebinding/inheritanceandscope_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for finding scope in cases involving inheritance.''' @@ -42,14 +15,16 @@ init_paths() from sample import SampleNamespace + class ScopeAndInheritanceTest(unittest.TestCase): '''Test cases for finding scope in cases involving inheritance.''' def testMethodCorrectlyWrapper(self): '''A method returning a type declared in the scope of the method's class parent must be found and the method correctly exported.''' - meth = getattr(SampleNamespace.DerivedFromNamespace, 'methodReturningTypeFromParentScope') + meth = getattr(SampleNamespace.DerivedFromNamespace, # noqa: F841 + 'methodReturningTypeFromParentScope') + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/injectcode_test.py b/sources/shiboken6/tests/samplebinding/injectcode_test.py index a6fb7a5ef..f673a7807 100644 --- a/sources/shiboken6/tests/samplebinding/injectcode_test.py +++ b/sources/shiboken6/tests/samplebinding/injectcode_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for std::list container conversions''' @@ -41,6 +14,7 @@ from shiboken_paths import init_paths init_paths() from sample import InjectCode + class MyInjectCode(InjectCode): def __init__(self): InjectCode.__init__(self) @@ -49,8 +23,11 @@ class MyInjectCode(InjectCode): def arrayMethod(self, values): return self.multiplier * sum(values) + class InjectCodeTest(unittest.TestCase): + @unittest.skipIf(hasattr(sys, "pypy_version_info"), + "PyPy type objects cannot be modified (yet) after creation") def testTypeNativeBeginning_TypeTargetBeginning(self): ic = InjectCode() self.assertEqual(str(ic), "Hi! I'm the inject code dummy class.") @@ -96,22 +73,24 @@ class InjectCodeTest(unittest.TestCase): self.assertEqual(result, sum(values)) def testCallReimplementedVirtualMethodWithArgumentRemovalAndArgumentTypeModification(self): - '''Calls a reimplemented virtual method that had its first argument removed and the second modified.''' + '''Calls a reimplemented virtual method that had its first argument removed + and the second modified.''' ic = MyInjectCode() values = (1, 2, 3, 4, 5) result = ic.callArrayMethod(values) self.assertEqual(result, ic.multiplier * sum(values)) def testUsageOfTypeSystemCheckVariableOnPrimitiveType(self): - '''When the sequence item is convertible to an integer -1 is returned, or -2 if its not convertible.''' + '''When the sequence item is convertible to an integer -1 is returned, + or -2 if its not convertible.''' ic = InjectCode() values = (1, 2, 3, 4, '5', 6.7) result = ic.arrayMethod(values) - fixedValues = [v for v in values if isinstance(v, int)]\ - + [-1 for v in values if isinstance(v, float)]\ - + [-2 for v in values if not isinstance(v, int) and not isinstance(v, float)] - self.assertEqual(result, sum(fixedValues)) + ints = [v for v in values if isinstance(v, int)] + floats = [-1 for v in values if isinstance(v, float)] + other = [-2 for v in values if not isinstance(v, int) and not isinstance(v, float)] + self.assertEqual(result, sum(ints + floats + other)) class IntArrayTest(unittest.TestCase): @@ -135,5 +114,6 @@ class IntArrayTest(unittest.TestCase): ic = InjectCode() self.assertEqual(sum([1, 2]) + len([1, 2]), ic.sumArrayAndLength(args)) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/innerclass_test.py b/sources/shiboken6/tests/samplebinding/innerclass_test.py index 6e5b23aa7..721f33483 100644 --- a/sources/shiboken6/tests/samplebinding/innerclass_test.py +++ b/sources/shiboken6/tests/samplebinding/innerclass_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -40,10 +13,11 @@ init_paths() from sample import Derived + class TestInnerClass(unittest.TestCase): def testInstaciate(self): - d = Derived.SomeInnerClass() + d = Derived.SomeInnerClass() # noqa: F841 + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/intlist_test.py b/sources/shiboken6/tests/samplebinding/intlist_test.py index 58e519d00..defa9ca71 100644 --- a/sources/shiboken6/tests/samplebinding/intlist_test.py +++ b/sources/shiboken6/tests/samplebinding/intlist_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -40,6 +13,7 @@ init_paths() from sample import IntList + class IntListTest(unittest.TestCase): def testAutoFunctionsToBaseList(self): @@ -101,5 +75,6 @@ class IntListTest(unittest.TestCase): self.assertEqual(il[1], int(432.1)) self.assertRaises(TypeError, il.__setitem__, 2, '78') + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/intwrapper_test.py b/sources/shiboken6/tests/samplebinding/intwrapper_test.py new file mode 100644 index 000000000..d883adf47 --- /dev/null +++ b/sources/shiboken6/tests/samplebinding/intwrapper_test.py @@ -0,0 +1,39 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +import os +import sys +import unittest + +from pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from shiboken_paths import init_paths +init_paths() + +from sample import IntWrapper + + +class IntWrapperTest(unittest.TestCase): + + def testOperators(self): + ten1 = IntWrapper(10) + ten2 = IntWrapper(10) + twenty = IntWrapper(20) + self.assertTrue(ten1 == ten2) + self.assertTrue(ten1 != twenty) + self.assertTrue(ten1 + ten2 == twenty) + self.assertTrue(ten1 - ten2 == IntWrapper(0)) + i = IntWrapper(ten1.toInt()) + i += ten2 + self.assertTrue(i == twenty) + i -= ten2 + self.assertTrue(i == ten1) + + def testAddPyMethodDef(self): + """Test of added free function (PYSIDE-1905).""" + i = IntWrapper(10) + self.assertEqual(i.add_ints(10, 20), 30) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/invalid_virtual_return_test.py b/sources/shiboken6/tests/samplebinding/invalid_virtual_return_test.py index 1456f5e7a..bb35b2bb1 100644 --- a/sources/shiboken6/tests/samplebinding/invalid_virtual_return_test.py +++ b/sources/shiboken6/tests/samplebinding/invalid_virtual_return_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test case for returning invalid types in a virtual function''' @@ -65,7 +38,7 @@ class ModelWrongReturnTest(unittest.TestCase): def testWrongTypeReturn(self): model = ListModelWrong() view = ObjectView(model) - self.assertRaises(RuntimeWarning, view.getRawModelData) # calls model.data() + self.assertRaises(RuntimeWarning, view.getRawModelData) # calls model.data() if __name__ == '__main__': diff --git a/sources/shiboken6/tests/samplebinding/keep_reference_test.py b/sources/shiboken6/tests/samplebinding/keep_reference_test.py index b68b52e9d..10591fec6 100644 --- a/sources/shiboken6/tests/samplebinding/keep_reference_test.py +++ b/sources/shiboken6/tests/samplebinding/keep_reference_test.py @@ -1,39 +1,9 @@ #!/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$ -## -############################################################################# - -'''Test case for objects that keep references to other object without owning them (e.g. model/view relationships).''' +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys -from sys import getrefcount import unittest from pathlib import Path @@ -43,46 +13,51 @@ init_paths() from sample import ObjectModel, ObjectView + class TestKeepReference(unittest.TestCase): - '''Test case for objects that keep references to other object without owning them (e.g. model/view relationships).''' + '''Test case for objects that keep references to other object without + owning them (e.g. model/view relationships).''' + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testReferenceCounting(self): '''Tests reference count of model-like object referred by view-like objects.''' model1 = ObjectModel() - refcount1 = getrefcount(model1) + refcount1 = sys.getrefcount(model1) view1 = ObjectView() view1.setModel(model1) - self.assertEqual(getrefcount(view1.model()), refcount1 + 1) + self.assertEqual(sys.getrefcount(view1.model()), refcount1 + 1) view2 = ObjectView() view2.setModel(model1) - self.assertEqual(getrefcount(view2.model()), refcount1 + 2) + self.assertEqual(sys.getrefcount(view2.model()), refcount1 + 2) model2 = ObjectModel() view2.setModel(model2) - self.assertEqual(getrefcount(view1.model()), refcount1 + 1) + self.assertEqual(sys.getrefcount(view1.model()), refcount1 + 1) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testReferenceCountingWhenDeletingReferrer(self): '''Tests reference count of model-like object referred by deceased view-like object.''' model = ObjectModel() - refcount1 = getrefcount(model) + refcount1 = sys.getrefcount(model) view = ObjectView() view.setModel(model) - self.assertEqual(getrefcount(view.model()), refcount1 + 1) + self.assertEqual(sys.getrefcount(view.model()), refcount1 + 1) del view - self.assertEqual(getrefcount(model), refcount1) + self.assertEqual(sys.getrefcount(model), refcount1) def testReferreedObjectSurvivalAfterContextEnd(self): - '''Model-like object assigned to a view-like object must survive after get out of context.''' + '''Model-like object assigned to a view-like object must survive + after get out of context.''' def createModelAndSetToView(view): model = ObjectModel() model.setObjectName('created model') view.setModel(model) view = ObjectView() createModelAndSetToView(view) - model = view.model() + model = view.model() # noqa: F841 + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/list_test.py b/sources/shiboken6/tests/samplebinding/list_test.py index b7257a320..b668bfd90 100644 --- a/sources/shiboken6/tests/samplebinding/list_test.py +++ b/sources/shiboken6/tests/samplebinding/list_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for std::list container conversions''' @@ -42,6 +15,7 @@ init_paths() from sample import ListUser, Point, PointF + class ExtendedListUser(ListUser): def __init__(self): ListUser.__init__(self) @@ -51,6 +25,7 @@ class ExtendedListUser(ListUser): self.create_list_called = True return [2, 3, 5, 7, 13] + class ListConversionTest(unittest.TestCase): '''Test case for std::list container conversions''' @@ -96,7 +71,8 @@ class ListConversionTest(unittest.TestCase): self.assertEqual(result, lst) def testConversionInBothDirectionsWithSimilarContainer(self): - '''Test converting a tuple, instead of the expected list, from Python to C++ and back again.''' + '''Test converting a tuple, instead of the expected list, + from Python to C++ and back again.''' lu = ListUser() lst = (3, 5, 7) lu.setList(lst) @@ -123,6 +99,6 @@ class ListConversionTest(unittest.TestCase): self.assertEqual(ListUser.ListOfPointF, ListUser.listOfPoints([PointF()])) self.assertEqual(ListUser.ListOfPoint, ListUser.listOfPoints([Point()])) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/lock_test.py b/sources/shiboken6/tests/samplebinding/lock_test.py index eaaf4ca05..acd47634a 100644 --- a/sources/shiboken6/tests/samplebinding/lock_test.py +++ b/sources/shiboken6/tests/samplebinding/lock_test.py @@ -1,32 +1,6 @@ #!/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 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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Simple test with a blocking C++ method that should allow python threads to run.''' @@ -89,7 +63,8 @@ class TestLockUnlock(unittest.TestCase): self.assertTrue(result) def testReimplementedVirtualBlocker(self): - '''Same as the basic case but blocker method is a C++ virtual reimplemented in Python and called from C++.''' + '''Same as the basic case but blocker method is a C++ virtual reimplemented + in Python and called from C++.''' mybucket = MyBucket() unlocker = Unlocker(mybucket) @@ -98,5 +73,6 @@ class TestLockUnlock(unittest.TestCase): unlocker.join() self.assertTrue(result) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/map_test.py b/sources/shiboken6/tests/samplebinding/map_test.py index 205075bc3..fa99ad2e7 100644 --- a/sources/shiboken6/tests/samplebinding/map_test.py +++ b/sources/shiboken6/tests/samplebinding/map_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for std::map container conversions''' @@ -42,6 +15,7 @@ init_paths() from sample import MapUser + class ExtendedMapUser(MapUser): def __init__(self): MapUser.__init__(self) @@ -49,10 +23,11 @@ class ExtendedMapUser(MapUser): def createMap(self): self.create_map_called = True - return {'two' : (complex(2.2, 2.2), 2), - 'three' : (complex(3.3, 3.3), 3), - 'five' : (complex(5.5, 5.5), 5), - 'seven' : (complex(7.7, 7.7), 7)} + return {'two': (complex(2.2, 2.2), 2), + 'three': (complex(3.3, 3.3), 3), + 'five': (complex(5.5, 5.5), 5), + 'seven': (complex(7.7, 7.7), 7)} + class MapConversionTest(unittest.TestCase): '''Test case for std::map container conversions''' @@ -71,7 +46,7 @@ class MapConversionTest(unittest.TestCase): def testConversionInBothDirections(self): '''Test converting a map from Python to C++ and back again.''' mu = MapUser() - map_ = {'odds' : [2, 4, 6], 'evens' : [3, 5, 7], 'primes' : [3, 4, 6]} + map_ = {'odds': [2, 4, 6], 'evens': [3, 5, 7], 'primes': [3, 4, 6]} mu.setMap(map_) result = mu.getMap() self.assertEqual(result, map_) @@ -79,9 +54,10 @@ class MapConversionTest(unittest.TestCase): def testConversionMapIntKeyValueTypeValue(self): '''C++ signature: MapUser::passMapIntValueType(const std::map<int, const ByteArray>&)''' mu = MapUser() - map_ = {0 : 'string'} + map_ = {0: 'string'} result = mu.passMapIntValueType(map_) self.assertEqual(map_, result) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/metaclass_test.py b/sources/shiboken6/tests/samplebinding/metaclass_test.py index ed07626a0..4d7eeda96 100644 --- a/sources/shiboken6/tests/samplebinding/metaclass_test.py +++ b/sources/shiboken6/tests/samplebinding/metaclass_test.py @@ -1,30 +1,5 @@ -############################################################################# -## -## 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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -35,32 +10,40 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import Point + class MetaA(type): pass + class A(object): __metaclass__ = MetaA + MetaB = type(Point) B = Point + class MetaC(MetaA, MetaB): pass + + class C(A, B): __metaclass__ = MetaC + class D(C): pass + class TestMetaClass(unittest.TestCase): def testIt(self): - w1 = C() # works + w1 = C() # works w1.setX(1) w1.setY(2) - w2 = D() # should work! + w2 = D() # should work! w2.setX(3) w2.setY(4) diff --git a/sources/shiboken6/tests/samplebinding/mi_virtual_methods_test.py b/sources/shiboken6/tests/samplebinding/mi_virtual_methods_test.py index ba92bdb85..8d324db59 100644 --- a/sources/shiboken6/tests/samplebinding/mi_virtual_methods_test.py +++ b/sources/shiboken6/tests/samplebinding/mi_virtual_methods_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for virtual methods in multiple inheritance scenarios''' diff --git a/sources/shiboken6/tests/samplebinding/mixed_mi_test.py b/sources/shiboken6/tests/samplebinding/mixed_mi_test.py index f303ea0db..fa8481600 100644 --- a/sources/shiboken6/tests/samplebinding/mixed_mi_test.py +++ b/sources/shiboken6/tests/samplebinding/mixed_mi_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for multiple inheritance in mixed Python/C++ scenarios''' @@ -79,5 +52,3 @@ class MixedInheritanceTest(unittest.TestCase): if __name__ == '__main__': unittest.main() - - diff --git a/sources/shiboken6/tests/samplebinding/modelindex_test.py b/sources/shiboken6/tests/samplebinding/modelindex_test.py index 1a4ed2407..e23503eff 100644 --- a/sources/shiboken6/tests/samplebinding/modelindex_test.py +++ b/sources/shiboken6/tests/samplebinding/modelindex_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -40,6 +13,7 @@ init_paths() from sample import ModelIndex, ReferentModelIndex, PersistentModelIndex + class TestCastOperator(unittest.TestCase): def testCastOperatorReturningValue(self): @@ -57,4 +31,3 @@ class TestCastOperator(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/modelview_test.py b/sources/shiboken6/tests/samplebinding/modelview_test.py index dff7b68fb..b5663a04e 100644 --- a/sources/shiboken6/tests/samplebinding/modelview_test.py +++ b/sources/shiboken6/tests/samplebinding/modelview_test.py @@ -1,35 +1,9 @@ #!/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$ -## -############################################################################# - -'''Test case for objects that keep references to other object without owning them (e.g. model/view relationships).''' +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +'''Test case for objects that keep references to other object without owning them + (e.g. model/view relationships).''' import os import sys @@ -44,9 +18,11 @@ from sample import ObjectModel, ObjectType, ObjectView object_name = 'test object' + class MyObject(ObjectType): pass + class ListModelKeepsReference(ObjectModel): def __init__(self, parent=None): ObjectModel.__init__(self, parent) @@ -56,6 +32,7 @@ class ListModelKeepsReference(ObjectModel): def data(self): return self.obj + class ListModelDoesntKeepsReference(ObjectModel): def data(self): obj = MyObject() @@ -82,4 +59,3 @@ class ModelViewTest(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/modifications_test.py b/sources/shiboken6/tests/samplebinding/modifications_test.py index 3429ccd0f..dced14396 100644 --- a/sources/shiboken6/tests/samplebinding/modifications_test.py +++ b/sources/shiboken6/tests/samplebinding/modifications_test.py @@ -1,36 +1,10 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for method modifications performed as described on type system. ''' +import gc import os import sys import unittest @@ -42,6 +16,7 @@ init_paths() from sample import Modifications, Point, ByteArray + class ExtModifications(Modifications): def __init__(self): Modifications.__init__(self) @@ -64,25 +39,18 @@ class ModificationsTest(unittest.TestCase): def tearDown(self): del self.mods - - def testClassMembersAvailability(self): - '''Test if Modified class really have the expected members.''' - expected_members = set(['OverloadedModFunc', 'OverloadedNone', - 'Overloaded_ibiP', 'Overloaded_ibib', - 'Overloaded_ibid', 'Overloaded_ibii', - 'calculateArea', 'doublePlus', 'increment', - 'multiplyPointCoordsPlusValue', 'name', - 'pointToPair', 'overloaded', 'power', - 'timesTen']) - self.assertTrue(expected_members.issubset(dir(Modifications))) + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() def testRenamedMethodAvailability(self): - '''Test if Modification class really have renamed the 'className' virtual method to 'name'.''' + '''Test if Modification class really have renamed the 'className' + virtual method to 'name'.''' self.assertTrue('className' not in dir(Modifications)) self.assertTrue('name' in dir(Modifications)) def testReimplementationOfRenamedVirtualMethod(self): - '''Test if class inheriting from Modification class have the reimplementation of renamed virtual method called.''' + '''Test if class inheriting from Modification class have the reimplementation + of renamed virtual method called.''' em = ExtModifications() self.assertEqual(self.mods.name(), 'Modifications') self.assertEqual(em.name(), 'ExtModifications') @@ -103,12 +71,14 @@ class ModificationsTest(unittest.TestCase): self.assertEqual(self.mods.doublePlus(7), 14) def testDefaultValueRemoval(self): - '''Test if default value was removed from first argument of Modifications::increment(int).''' + '''Test if default value was removed from first argument of + Modifications::increment(int).''' self.assertRaises(TypeError, self.mods.increment) self.assertEqual(self.mods.increment(7), 8) def testDefaultValueReplacement(self): - '''Test if default values for both arguments of Modifications::power(int, int) were modified.''' + '''Test if default values for both arguments of Modifications::power(int, int) + were modified.''' # original default values: int power(int base = 1, int exponent = 0); self.assertNotEqual(self.mods.power(4), 1) # modified default values: int power(int base = 2, int exponent = 1); @@ -117,12 +87,14 @@ class ModificationsTest(unittest.TestCase): self.assertEqual(self.mods.power(5, 3), 5**3) def testSetNewDefaultValue(self): - '''Test if default value was correctly set to 10 for first argument of Modifications::timesTen(int).''' + '''Test if default value was correctly set to 10 for first argument of + Modifications::timesTen(int).''' self.assertEqual(self.mods.timesTen(7), 70) self.assertEqual(self.mods.timesTen(), 100) def testArgumentRemovalAndReturnTypeModificationWithTypesystemTemplates1(self): - '''Test modifications to method signature and return value using type system templates (case 1).''' + '''Test modifications to method signature and return value using type + system templates (case 1).''' result, ok = self.mods.pointToPair(Point(2, 5)) self.assertEqual(type(ok), bool) self.assertEqual(type(result), tuple) @@ -133,7 +105,8 @@ class ModificationsTest(unittest.TestCase): self.assertEqual(result[1], 5.0) def testArgumentRemovalAndReturnTypeModificationWithTypesystemTemplates2(self): - '''Test modifications to method signature and return value using type system templates (case 2).''' + '''Test modifications to method signature and return value using + type system templates (case 2).''' result, ok = self.mods.multiplyPointCoordsPlusValue(Point(2, 5), 4.1) self.assertEqual(type(ok), bool) self.assertEqual(type(result), float) @@ -147,9 +120,11 @@ class ModificationsTest(unittest.TestCase): self.assertEqual(self.mods.overloaded(1, True, 2), Modifications.Overloaded_ibii) # the others weren't modified self.assertEqual(self.mods.overloaded(1, True, 2, False), Modifications.Overloaded_ibib) - self.assertEqual(self.mods.overloaded(1, False, 2, Point(3, 4)), Modifications.Overloaded_ibiP) + self.assertEqual(self.mods.overloaded(1, False, 2, Point(3, 4)), + Modifications.Overloaded_ibiP) self.assertRaises(TypeError, self.mods.overloaded, 1, True, Point(2, 3), Point(4, 5)) - self.assertEqual(self.mods.over(1, True, Point(2, 3), Point(4, 5)), Modifications.Overloaded_ibPP) + self.assertEqual(self.mods.over(1, True, Point(2, 3), Point(4, 5)), + Modifications.Overloaded_ibPP) def testPointArrayModification(self): points = (Point(1, 1), Point(2, 2)) diff --git a/sources/shiboken6/tests/samplebinding/modified_constructor_test.py b/sources/shiboken6/tests/samplebinding/modified_constructor_test.py index 63cec6556..9791a3491 100644 --- a/sources/shiboken6/tests/samplebinding/modified_constructor_test.py +++ b/sources/shiboken6/tests/samplebinding/modified_constructor_test.py @@ -1,37 +1,9 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Tests cases for ConstructorWithModifiedArgument class.''' -import sys import os import sys import unittest @@ -41,7 +13,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import ModifiedConstructor class ConstructorWithModifiedArgumentTest(unittest.TestCase): @@ -51,6 +23,6 @@ class ConstructorWithModifiedArgumentTest(unittest.TestCase): sampleClass = ModifiedConstructor("10") self.assertTrue(sampleClass.retrieveValue(), 10) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/modifiedvirtualmethods_test.py b/sources/shiboken6/tests/samplebinding/modifiedvirtualmethods_test.py index b59e64a00..dcb487f1a 100644 --- a/sources/shiboken6/tests/samplebinding/modifiedvirtualmethods_test.py +++ b/sources/shiboken6/tests/samplebinding/modifiedvirtualmethods_test.py @@ -1,36 +1,10 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for modified virtual methods.''' +import gc import os import sys import unittest @@ -42,6 +16,7 @@ init_paths() from sample import VirtualMethods, Str + class ExtendedVirtualMethods(VirtualMethods): def __init__(self): VirtualMethods.__init__(self) @@ -87,7 +62,7 @@ class ExtendedVirtualMethods(VirtualMethods): self.callMe_called += 1 def getMargins(self): - return tuple([m*2 for m in VirtualMethods.getMargins(self)]) + return tuple([m * 2 for m in VirtualMethods.getMargins(self)]) class VirtualMethodsTest(unittest.TestCase): @@ -100,6 +75,8 @@ class VirtualMethodsTest(unittest.TestCase): def tearDown(self): del self.vm del self.evm + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() def testModifiedVirtualMethod0(self): '''Renamed virtual method.''' @@ -209,7 +186,8 @@ class VirtualMethodsTest(unittest.TestCase): removed_arg_value = 2011 default_value = 3000 result = self.evm.callSum4(a0, removed_arg_value, a1) - self.assertEqual(result, (a0 - removed_arg_value + a1 + default_value) * self.evm.multiplier) + self.assertEqual(result, + (a0 - removed_arg_value + a1 + default_value) * self.evm.multiplier) self.assertTrue(self.evm.sum4_called) def testOverridenMethodResultModification(self): @@ -241,15 +219,15 @@ class VirtualMethodsTest(unittest.TestCase): def testExtendedAllArgumentsRemoved(self): values = (10, 20, 30, 40) self.evm.setMargins(*values) - double = tuple([m*2 for m in values]) + double = tuple([m * 2 for m in values]) self.assertEqual(self.evm.getMargins(), double) def testExtendedAllArgumentsRemovedCallVirtual(self): values = (10, 20, 30, 40) self.evm.setMargins(*values) - double = tuple([m*2 for m in values]) + double = tuple([m * 2 for m in values]) self.assertEqual(self.evm.callGetMargins(), double) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/multi_cpp_inheritance_test.py b/sources/shiboken6/tests/samplebinding/multi_cpp_inheritance_test.py index c522d0e38..fc6b26c3f 100644 --- a/sources/shiboken6/tests/samplebinding/multi_cpp_inheritance_test.py +++ b/sources/shiboken6/tests/samplebinding/multi_cpp_inheritance_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for multiple inheritance''' @@ -40,72 +13,85 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import ObjectType, Point, Str + class SimpleUseCase(ObjectType, Str): def __init__(self, name): ObjectType.__init__(self) Str.__init__(self, name) + class SimpleUseCaseReverse(Str, ObjectType): def __init__(self, name): ObjectType.__init__(self) Str.__init__(self, name) + class SimpleUseCase2(SimpleUseCase): def __init__(self, name): SimpleUseCase.__init__(self, name) + class ComplexUseCase(SimpleUseCase2, Point): def __init__(self, name): SimpleUseCase2.__init__(self, name) Point.__init__(self) + class ComplexUseCaseReverse(Point, SimpleUseCase2): def __init__(self, name): SimpleUseCase2.__init__(self, name) Point.__init__(self) + class MultipleCppDerivedTest(unittest.TestCase): - def testInstanciation(self): + def testInstantiation(self): s = SimpleUseCase("Hi") self.assertEqual(s, "Hi") s.setObjectName(s) self.assertEqual(s.objectName(), "Hi") - def testInstanciation2(self): + def testInstantiation2(self): s = SimpleUseCase2("Hi") self.assertEqual(s, "Hi") s.setObjectName(s) self.assertEqual(s.objectName(), "Hi") - def testComplexInstanciation(self): + def testComplexInstantiation(self): c = ComplexUseCase("Hi") self.assertEqual(c, "Hi") c.setObjectName(c) self.assertEqual(c.objectName(), "Hi") - c.setX(2); + c.setX(2) self.assertEqual(c.x(), 2) + class MultipleCppDerivedReverseTest(unittest.TestCase): - def testInstanciation(self): + def testInstantiation(self): s = SimpleUseCaseReverse("Hi") self.assertEqual(s, "Hi") s.setObjectName(s) self.assertEqual(s.objectName(), "Hi") - def testInstanciation2(self): + def testInstantiation2(self): s = SimpleUseCase2("Hi") self.assertEqual(s, "Hi") s.setObjectName(s) self.assertEqual(s.objectName(), "Hi") - def testComplexInstanciation(self): - c = ComplexUseCaseReverse("Hi") - c.setObjectName(c) - self.assertEqual(c.objectName(), "Hi") - c.setX(2); - self.assertEqual(c, Point(2, 0)) + def testComplexInstantiation(self): + # PYSIDE-1564: This test can no longer work because of this MRO: + # ('ComplexUseCaseReverse', 'Point', 'SimpleUseCase2', 'SimpleUseCase', + # 'ObjectType', 'Str', 'Object', 'object') + # By multiple inheritance Point would be called first but has no argument. + with self.assertRaises(TypeError): + c = ComplexUseCaseReverse("Hi") # noqa: F841 + # c.setObjectName(c) + # self.assertEqual(c.objectName(), "Hi") + # c.setX(2); + # self.assertEqual(c, Point(2, 0)) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/multiple_derived_test.py b/sources/shiboken6/tests/samplebinding/multiple_derived_test.py index 08a13445d..7497714a8 100644 --- a/sources/shiboken6/tests/samplebinding/multiple_derived_test.py +++ b/sources/shiboken6/tests/samplebinding/multiple_derived_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for multiple inheritance''' @@ -40,17 +13,20 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import Base1, Base2, Base3, Base4, Base5, Base6 +from sample import Base1, Base2 from sample import MDerived1, MDerived2, MDerived3, MDerived4, MDerived5, SonOfMDerived1 + class ExtMDerived1(MDerived1): def __init__(self): MDerived1.__init__(self) self.multiplier = 20 self.base2Method_called = False + def base2Method(self): return Base2.base2Method(self) * self.multiplier + class MultipleDerivedTest(unittest.TestCase): '''Test cases for multiple inheritance''' @@ -67,19 +43,22 @@ class MultipleDerivedTest(unittest.TestCase): self.assertTrue(issubclass(MDerived1, Base2)) def testCallToFunctionWithBase1ArgumentThatCastsBackToMDerived1(self): - '''MDerived1 is passed as an Base1 argument to a method that returns it casted back to MDerived1.''' + '''MDerived1 is passed as an Base1 argument to a method that returns + it casted back to MDerived1.''' a = MDerived1() b = MDerived1.transformFromBase1(a) self.assertEqual(a, b) def testCallToFunctionWithBase2ArgumentThatCastsBackToMDerived1(self): - '''MDerived1 is passed as an Base2 argument to a method that returns it casted back to MDerived1.''' + '''MDerived1 is passed as an Base2 argument to a method that returns + it casted back to MDerived1.''' a = MDerived1() b = MDerived1.transformFromBase2(a) self.assertEqual(a, b) def testPythonClassIsInstance(self): - '''Python defined class ExtMDerived1 is instance of its parents MDerived1, Base1 and Base2.''' + '''Python defined class ExtMDerived1 is instance of its parents + MDerived1, Base1 and Base2.''' a = ExtMDerived1() self.assertTrue(isinstance(a, ExtMDerived1)) self.assertTrue(isinstance(a, MDerived1)) @@ -87,13 +66,16 @@ class MultipleDerivedTest(unittest.TestCase): self.assertTrue(isinstance(a, Base2)) def testPythonClassIsSubclass(self): - '''Python defined class ExtMDerived1 is subclass of its parents MDerived1, Base1 and Base2.''' + '''Python defined class ExtMDerived1 is subclass of its parents + MDerived1, Base1 and Base2.''' self.assertTrue(issubclass(ExtMDerived1, MDerived1)) self.assertTrue(issubclass(ExtMDerived1, Base1)) self.assertTrue(issubclass(ExtMDerived1, Base2)) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testCastFromMDerived1ToBases(self): - '''MDerived1 is casted by C++ to its parents and the binding must return the MDerived1 wrapper.''' + '''MDerived1 is casted by C++ to its parents and the binding must return the + MDerived1 wrapper.''' a = MDerived1() refcnt = sys.getrefcount(a) b1 = a.castToBase1() @@ -104,8 +86,10 @@ class MultipleDerivedTest(unittest.TestCase): self.assertEqual(a, b2) self.assertEqual(sys.getrefcount(a), refcnt + 2) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testCastFromExtMDerived1ToMDerived1Bases(self): - '''Python defined class ExtMDerived1 is casted by C++ to MDerived1 parents and the binding must return the correct ExtMDerived1 instance.''' + '''Python defined class ExtMDerived1 is casted by C++ to MDerived1 parents + and the binding must return the correct ExtMDerived1 instance.''' a = ExtMDerived1() refcnt = sys.getrefcount(a) b1 = a.castToBase1() @@ -118,8 +102,10 @@ class MultipleDerivedTest(unittest.TestCase): self.assertEqual(a, b2) self.assertEqual(sys.getrefcount(a), refcnt + 2) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testCastFromSonOfMDerived1ToBases(self): - '''SonOfMDerived1 is casted by C++ to its parents and the binding must return the SonOfMDerived1 wrapper.''' + '''SonOfMDerived1 is casted by C++ to its parents and the binding must return + the SonOfMDerived1 wrapper.''' a = SonOfMDerived1() refcnt = sys.getrefcount(a) md1 = a.castToMDerived1() @@ -138,8 +124,10 @@ class MultipleDerivedTest(unittest.TestCase): value = a.base2Method() self.assertTrue(value, Base2.base2Method(a) * a.multiplier) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testCastFromMDerived2ToBases(self): - '''MDerived2 is casted by C++ to its parents and the binding must return the MDerived2 wrapper.''' + '''MDerived2 is casted by C++ to its parents and the binding must + return the MDerived2 wrapper.''' a = MDerived2() refcnt = sys.getrefcount(a) b3 = a.castToBase3() @@ -156,8 +144,10 @@ class MultipleDerivedTest(unittest.TestCase): self.assertEqual(a, b6) self.assertEqual(sys.getrefcount(a), refcnt + 4) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testCastFromMDerived3ToBases(self): - '''MDerived3 is casted by C++ to its parents and the binding must return the MDerived3 wrapper.''' + '''MDerived3 is casted by C++ to its parents and the binding must + return the MDerived3 wrapper.''' a = MDerived3() refcnt = sys.getrefcount(a) md1 = a.castToMDerived1() @@ -186,8 +176,10 @@ class MultipleDerivedTest(unittest.TestCase): self.assertEqual(a, b6) self.assertEqual(sys.getrefcount(a), refcnt + 8) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testCastFromMDerived4ToBases(self): - '''MDerived4 is casted by C++ to its parents and the binding must return the MDerived4 wrapper.''' + '''MDerived4 is casted by C++ to its parents and the binding must + return the MDerived4 wrapper.''' a = MDerived4() refcnt = sys.getrefcount(a) b3 = a.castToBase3() @@ -198,8 +190,10 @@ class MultipleDerivedTest(unittest.TestCase): self.assertEqual(a, b4) self.assertEqual(sys.getrefcount(a), refcnt + 2) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testCastFromMDerived5ToBases(self): - '''MDerived5 is casted by C++ to its parents and the binding must return the MDerived5 wrapper.''' + '''MDerived5 is casted by C++ to its parents and the binding must + return the MDerived5 wrapper.''' a = MDerived5() refcnt = sys.getrefcount(a) b3 = a.castToBase3() @@ -210,8 +204,10 @@ class MultipleDerivedTest(unittest.TestCase): self.assertEqual(a, b4) self.assertEqual(sys.getrefcount(a), refcnt + 2) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testCastFromMDerived3ToBase3(self): - '''MDerived3 is casted by C++ to Base3 grandparent using both the inherited and reimplement castToBase3 methods.''' + '''MDerived3 is casted by C++ to Base3 grandparent using both the inherited + and reimplement castToBase3 methods.''' a = MDerived3() refcnt = sys.getrefcount(a) b3_reimplemented = a.castToBase3() @@ -222,6 +218,6 @@ class MultipleDerivedTest(unittest.TestCase): self.assertEqual(a, b3_inherited) self.assertEqual(sys.getrefcount(a), refcnt + 2) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/namespace_test.py b/sources/shiboken6/tests/samplebinding/namespace_test.py index 3dc79fa96..64a6792ac 100644 --- a/sources/shiboken6/tests/samplebinding/namespace_test.py +++ b/sources/shiboken6/tests/samplebinding/namespace_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for std::map container conversions''' @@ -40,9 +13,10 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import SampleNamespace from shiboken_test_helper import objectFullname +from shibokensupport.signature import get_signature # For tests of invisible namespaces, see # enumfromremovednamespace_test.py / removednamespaces.h @@ -50,17 +24,17 @@ from shiboken_test_helper import objectFullname class TestVariablesUnderNamespace(unittest.TestCase): def testIt(self): - self.assertEqual(SampleNamespace.variableInNamespace, 42) + self.assertEqual(SampleNamespace.variableInNamespace, 42) class TestClassesUnderNamespace(unittest.TestCase): def testIt(self): - c1 = SampleNamespace.SomeClass() - e1 = SampleNamespace.SomeClass.ProtectedEnum() - c2 = SampleNamespace.SomeClass.SomeInnerClass() - e2 = SampleNamespace.SomeClass.SomeInnerClass.ProtectedEnum() - c3 = SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough() - e3 = SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough.NiceEnum() + c1 = SampleNamespace.SomeClass() # noqa F841 + e1 = SampleNamespace.SomeClass.ProtectedEnum() # noqa F841 + c2 = SampleNamespace.SomeClass.SomeInnerClass() # noqa F841 + e2 = SampleNamespace.SomeClass.SomeInnerClass.ProtectedEnum() # noqa F841 + c3 = SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough() # noqa F841 + e3 = SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough.NiceEnum(0) # noqa F841 def testFunctionAddedOnNamespace(self): res = SampleNamespace.ImInsideANamespace(2, 2) @@ -68,21 +42,26 @@ class TestClassesUnderNamespace(unittest.TestCase): def testTpNames(self): self.assertEqual(str(SampleNamespace.SomeClass), - "<class 'sample.SampleNamespace.SomeClass'>") + "<class 'sample.SampleNamespace.SomeClass'>") self.assertEqual(str(SampleNamespace.SomeClass.ProtectedEnum), - "<class 'sample.SampleNamespace.SomeClass.ProtectedEnum'>") + "<enum 'ProtectedEnum'>") self.assertEqual(str(SampleNamespace.SomeClass.SomeInnerClass.ProtectedEnum), - "<class 'sample.SampleNamespace.SomeClass.SomeInnerClass.ProtectedEnum'>") + "<enum 'ProtectedEnum'>") self.assertEqual(str(SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough), - "<class 'sample.SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough'>") - self.assertEqual(str(SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough.NiceEnum), - "<class 'sample.SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough.NiceEnum'>") + "<class 'sample.SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough'>") # noqa: E501 + self.assertEqual(str(SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough.NiceEnum), # noqa: E501 + "<enum 'NiceEnum'>") # Test if enum inside of class is correct represented - self.assertEqual(objectFullname(SampleNamespace.enumInEnumOut.__signature__.parameters['in_'].annotation), - "sample.SampleNamespace.InValue") - self.assertEqual(objectFullname(SampleNamespace.enumAsInt.__signature__.parameters['value'].annotation), - "sample.SampleNamespace.SomeClass.PublicScopedEnum") + an = objectFullname(get_signature(SampleNamespace.enumInEnumOut).parameters['in_'].annotation) # noqa: E501 + self.assertEqual(an, "sample.SampleNamespace.InValue") + an = objectFullname(get_signature(SampleNamespace.enumAsInt).parameters['value'].annotation) + self.assertEqual(an, "sample.SampleNamespace.SomeClass.PublicScopedEnum") + + def testInlineNamespaces(self): + cls = SampleNamespace.ClassWithinInlineNamespace() + cls.setValue(SampleNamespace.EWIN_Value1) + self.assertEqual(cls.value(), SampleNamespace.EWIN_Value1) if __name__ == '__main__': diff --git a/sources/shiboken6/tests/samplebinding/newdivision_test.py b/sources/shiboken6/tests/samplebinding/newdivision_test.py index a9152f4a1..0e7dfbee1 100644 --- a/sources/shiboken6/tests/samplebinding/newdivision_test.py +++ b/sources/shiboken6/tests/samplebinding/newdivision_test.py @@ -1,30 +1,5 @@ -############################################################################# -## -## 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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -35,16 +10,16 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import Point class TestNewDivision(unittest.TestCase): def testIt(self): p = Point(4, 4) - p2 = p/2 + p2 = p / 2 self.assertEqual(p2, Point(2, 2)) + if __name__ == "__main__": unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/nondefaultctor_test.py b/sources/shiboken6/tests/samplebinding/nondefaultctor_test.py index 31a51995e..bc8d29e50 100644 --- a/sources/shiboken6/tests/samplebinding/nondefaultctor_test.py +++ b/sources/shiboken6/tests/samplebinding/nondefaultctor_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for ...''' @@ -42,14 +15,17 @@ init_paths() from sample import NonDefaultCtor + class DerivedNonDefaultCtor (NonDefaultCtor): def returnMyselfVirtual(self): - return NonDefaultCtor(self.value()+1) + return NonDefaultCtor(self.value() + 1) + class AnotherDerivedNonDefaultCtor (NonDefaultCtor): def __init__(self, some_string): pass + class NonDefaultCtorTest(unittest.TestCase): def testNonDefaultCtor(self): @@ -70,8 +46,8 @@ class NonDefaultCtorTest(unittest.TestCase): self.assertEqual(c.callReturnMyselfVirtual().value(), 4) def testCtorOverload(self): - c = AnotherDerivedNonDefaultCtor("testing") + c = AnotherDerivedNonDefaultCtor("testing") # noqa: F841 + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/nontypetemplate_test.py b/sources/shiboken6/tests/samplebinding/nontypetemplate_test.py index b329f5672..a10547728 100644 --- a/sources/shiboken6/tests/samplebinding/nontypetemplate_test.py +++ b/sources/shiboken6/tests/samplebinding/nontypetemplate_test.py @@ -1,32 +1,6 @@ #!/usr/bin/env python -# -############################################################################# -## -## Copyright (C) 2018 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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 hasNumPy = False @@ -47,6 +21,7 @@ init_paths() from sample import IntArray2, IntArray3 + class NonTypeTemplateTest(unittest.TestCase): def testNonTypeTemplate(self): @@ -58,7 +33,7 @@ class NonTypeTemplateTest(unittest.TestCase): def testArrayInitializer(self): if not hasNumPy: return - array3 = IntArray3(numpy.array([1, 2, 3], dtype = 'int32')) + array3 = IntArray3(numpy.array([1, 2, 3], dtype='int32')) self.assertEqual(array3.sum(), 6) diff --git a/sources/shiboken6/tests/samplebinding/nonzero_test.py b/sources/shiboken6/tests/samplebinding/nonzero_test.py index 0e14b674b..7be239fc4 100644 --- a/sources/shiboken6/tests/samplebinding/nonzero_test.py +++ b/sources/shiboken6/tests/samplebinding/nonzero_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -38,14 +11,24 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import Color, Brush + class TestNonZeroOperator(unittest.TestCase): - def testIt(self): + def testColor(self): + """Color has a Qt-style isNull()""" c = Color() self.assertFalse(c) c = Color(2) self.assertTrue(c) + def testBrush(self): + """Brush enables its operator bool in the typesystem XML""" + b = Brush() + self.assertFalse(b) + b = Brush(Color(2)) + self.assertTrue(b) + + if __name__ == "__main__": unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/numericaltypedef_test.py b/sources/shiboken6/tests/samplebinding/numericaltypedef_test.py index 5512a2de6..f714a4fc8 100644 --- a/sources/shiboken6/tests/samplebinding/numericaltypedef_test.py +++ b/sources/shiboken6/tests/samplebinding/numericaltypedef_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -40,6 +13,7 @@ init_paths() from sample import SizeF + class NumericalTypedefTest(unittest.TestCase): def testNumericalTypedefExact(self): @@ -59,5 +33,6 @@ class NumericalTypedefTest(unittest.TestCase): self.assertEqual(SizeF.passTypedefOfUnsignedShort(321), 321) self.assertNotEqual(SizeF.passTypedefOfUnsignedShort(123), 0) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/numpy_test.py b/sources/shiboken6/tests/samplebinding/numpy_test.py index 61f8c7103..42094a463 100644 --- a/sources/shiboken6/tests/samplebinding/numpy_test.py +++ b/sources/shiboken6/tests/samplebinding/numpy_test.py @@ -1,39 +1,14 @@ -############################################################################# -## -## 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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import sys try: - from distutils import sysconfig + import sysconfig if bool(sysconfig.get_config_var('Py_DEBUG')): sys.exit(0) import numpy -except: +except: # noqa: E722 sys.exit(0) import os @@ -46,6 +21,7 @@ from shiboken_paths import init_paths init_paths() from sample import PointF + class TestNumpyTypes(unittest.TestCase): def testNumpyConverted(self): @@ -60,6 +36,6 @@ class TestNumpyTypes(unittest.TestCase): self.assertAlmostEqual(p.x(), x) self.assertAlmostEqual(p.y(), y) + if __name__ == "__main__": unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/objecttype_test.py b/sources/shiboken6/tests/samplebinding/objecttype_test.py index fb655c435..ead68ba13 100644 --- a/sources/shiboken6/tests/samplebinding/objecttype_test.py +++ b/sources/shiboken6/tests/samplebinding/objecttype_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Tests ObjectType class of object-type with privates copy constructor and = operator.''' @@ -75,6 +48,7 @@ class ObjectTypeTest(unittest.TestCase): o.setNullObject(None) self.assertEqual(o.callId(), 1) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testParentFromCpp(self): o = ObjectType() self.assertEqual(sys.getrefcount(o), 2) @@ -94,7 +68,7 @@ class ObjectTypeTest(unittest.TestCase): def testNextInFocusChainCycle(self): parent = ObjectType() child = ObjectType(parent) - next_focus = child.nextInFocusChain() + next_focus = child.nextInFocusChain() # noqa: F841 Shiboken.invalidate(parent) @@ -113,6 +87,7 @@ class ObjectTypeTest(unittest.TestCase): Shiboken.invalidate(parents) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testClassDecref(self): # Bug was that class PyTypeObject wasn't decrefed when instance died before = sys.getrefcount(ObjectType) @@ -127,11 +102,9 @@ class ObjectTypeTest(unittest.TestCase): def testInvalidProperty(self): o = ObjectType() - try: + with self.assertRaises(AttributeError): o.typo - self.assertFail() - except AttributeError as error: - self.assertEqual(error.args[0], "'sample.ObjectType' object has no attribute 'typo'") + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/objecttype_with_named_args_test.py b/sources/shiboken6/tests/samplebinding/objecttype_with_named_args_test.py index f9944e61b..285e2313b 100644 --- a/sources/shiboken6/tests/samplebinding/objecttype_with_named_args_test.py +++ b/sources/shiboken6/tests/samplebinding/objecttype_with_named_args_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -40,6 +13,7 @@ init_paths() from sample import ObjectType + class NamedArgsTest(unittest.TestCase): def testOneArgument(self): @@ -62,18 +36,15 @@ class NamedArgsTest(unittest.TestCase): o.setObjectNameWithSize(size=6, name="pyside") self.assertEqual(o.objectName(), "pyside") - def testUseDefaultValues(self): o = ObjectType() o.setObjectNameWithSize(size=3) - self.assertEqual(o.objectName(), "<un") # use name='unknown' default argument + self.assertEqual(o.objectName(), "<un") # use name='unknown' default argument o.setObjectSplittedName("") - self.assertEqual(o.objectName(), "<unknown>") # user prefix='<unk' and suffix='nown>' - + self.assertEqual(o.objectName(), "<unknown>") # user prefix='<unk' and suffix='nown>' if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/objecttypebyvalue_test.py b/sources/shiboken6/tests/samplebinding/objecttypebyvalue_test.py index 52253f241..8f74af3ab 100644 --- a/sources/shiboken6/tests/samplebinding/objecttypebyvalue_test.py +++ b/sources/shiboken6/tests/samplebinding/objecttypebyvalue_test.py @@ -1,30 +1,5 @@ -############################################################################# -## -## 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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -35,7 +10,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import ObjectTypeByValue class ObjectTypeByValueTest (unittest.TestCase): @@ -47,5 +22,6 @@ class ObjectTypeByValueTest (unittest.TestCase): # just to make sure it will segfault obj.prop.protectedValueTypeProperty.setY(2.0) + if __name__ == "__main__": unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/objecttypelayout_test.py b/sources/shiboken6/tests/samplebinding/objecttypelayout_test.py index 76f028f51..677b89281 100644 --- a/sources/shiboken6/tests/samplebinding/objecttypelayout_test.py +++ b/sources/shiboken6/tests/samplebinding/objecttypelayout_test.py @@ -1,36 +1,10 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Tests cases for ObjectTypeLayout class.''' +import gc import os import sys import unittest @@ -40,23 +14,23 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import ObjectType, ObjectTypeLayout class ObjectTypeLayoutTest(unittest.TestCase): '''Test cases for ObjectTypeLayout class.''' + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testOwnershipOverride(self): - l = ObjectTypeLayout() + lt = ObjectTypeLayout() - o1 = ObjectType(l) + o1 = ObjectType(lt) o1.setObjectName('o1') self.assertEqual(sys.getrefcount(o1), 3) - l.takeChild('o1') + lt.takeChild('o1') self.assertEqual(sys.getrefcount(o1), 2) - def testSetNullLayout(self): '''ObjectType.setLayout(0).''' o2 = ObjectType() @@ -82,7 +56,9 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertEqual(c3.parent(), None) p1.setLayout(layout) - del p1 # This must kill c1, c2 and c3 + del p1 # This must kill c1, c2 and c3 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, c1.objectName) self.assertRaises(RuntimeError, c2.objectName) @@ -104,7 +80,9 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertEqual(c3.parent(), None) p1.setLayout(layout) - del p1 # This must kill c1, c2 and c3 + del p1 # This must kill c1, c2 and c3 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, c1.objectName) self.assertRaises(RuntimeError, c2.objectName) @@ -112,7 +90,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertRaises(RuntimeError, layout.objectName) def testObjectTypeLayoutTransference(self): - '''Transfer a layout from one ObjectType to another, so that all the items in the layout get reparented.''' + '''Transfer a layout from one ObjectType to another, so that all the items in + the layout get reparented.''' p1 = ObjectType() p2 = ObjectType() c1 = ObjectType() @@ -164,6 +143,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertEqual(l2.parent(), l1) del p1 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, c1.objectName) self.assertRaises(RuntimeError, c2.objectName) @@ -173,7 +154,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertRaises(RuntimeError, l2.objectName) def testObjectTypeLayoutInsideAnotherLayoutAndEveryoneCreatedInCpp(self): - '''Adds one ObjectTypeLayout to another and sets the parent to an ObjectType. All the objects are created in C++.''' + '''Adds one ObjectTypeLayout to another and sets the parent to an ObjectType. + All the objects are created in C++.''' p1 = ObjectType.create() l1 = ObjectTypeLayout.create() @@ -200,6 +182,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertEqual(l2.parent(), l1) del p1 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, c1.objectName) self.assertRaises(RuntimeError, c2.objectName) @@ -209,7 +193,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertRaises(RuntimeError, l2.objectName) def testTransferNestedLayoutsBetweenObjects(self): - '''Adds one ObjectTypeLayout to another, sets the parent to an ObjectType and then transfer it to another object.''' + '''Adds one ObjectTypeLayout to another, sets the parent to an ObjectType + and then transfer it to another object.''' p1 = ObjectType() p2 = ObjectType() @@ -238,6 +223,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): p2.setLayout(l1) del p1 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(c1.parent(), p2) self.assertEqual(c2.parent(), p2) @@ -247,6 +234,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertEqual(l2.parent(), l1) del p2 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, c1.objectName) self.assertRaises(RuntimeError, c2.objectName) @@ -256,8 +245,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertRaises(RuntimeError, l2.objectName) def testTransferNestedLayoutsBetweenObjectsAndEveryoneCreatedInCpp(self): - '''Adds one ObjectTypeLayout to another, sets the parent to an ObjectType and then transfer it to another object. - All the objects are created in C++.''' + '''Adds one ObjectTypeLayout to another, sets the parent to an ObjectType and then + transfer it to another object. All the objects are created in C++.''' p1 = ObjectType.create() p2 = ObjectType.create() @@ -286,6 +275,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): p2.setLayout(l1) del p1 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(c1.parent(), p2) self.assertEqual(c2.parent(), p2) @@ -295,6 +286,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertEqual(l2.parent(), l1) del p2 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, c1.objectName) self.assertRaises(RuntimeError, c2.objectName) @@ -303,6 +296,6 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertRaises(RuntimeError, l1.objectName) self.assertRaises(RuntimeError, l2.objectName) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/objecttypeoperators_test.py b/sources/shiboken6/tests/samplebinding/objecttypeoperators_test.py index a82c54b7e..ceeee6c8d 100644 --- a/sources/shiboken6/tests/samplebinding/objecttypeoperators_test.py +++ b/sources/shiboken6/tests/samplebinding/objecttypeoperators_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -37,7 +10,8 @@ from pathlib import Path sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import ObjectTypeOperators + class ObjectTypeOperatorsTest(unittest.TestCase): @@ -53,7 +27,7 @@ class ObjectTypeOperatorsTest(unittest.TestCase): def testPointerOpeators(self): a = ObjectTypeOperators("a") - b = ObjectTypeOperators("b") + b = ObjectTypeOperators("b") # noqa: F841 self.assertEqual(a + "bc", "abc") self.assertEqual("bc" + a, "bca") self.assertEqual("a", a) @@ -63,5 +37,6 @@ class ObjectTypeOperatorsTest(unittest.TestCase): a = ObjectTypeOperators("a") self.assertNotEqual(a, "b") + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/objecttypereferenceasvirtualmethodargument_test.py b/sources/shiboken6/tests/samplebinding/objecttypereferenceasvirtualmethodargument_test.py index cb270c69b..5fa6f824e 100644 --- a/sources/shiboken6/tests/samplebinding/objecttypereferenceasvirtualmethodargument_test.py +++ b/sources/shiboken6/tests/samplebinding/objecttypereferenceasvirtualmethodargument_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -39,6 +12,7 @@ from shiboken_paths import init_paths init_paths() from sample import ObjectTypeHolder + class TestObjectTypeReferenceAsVirtualMethodArgument(unittest.TestCase): def testBasic(self): @@ -52,5 +26,6 @@ class TestObjectTypeReferenceAsVirtualMethodArgument(unittest.TestCase): holder = Holder('TheObjectFromC++') self.assertEqual(holder.callPassObjectTypeAsReference(), 'ThisIsTheObjectFromC++') + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/oddbool_test.py b/sources/shiboken6/tests/samplebinding/oddbool_test.py index a65b1228c..87a8cdb1f 100644 --- a/sources/shiboken6/tests/samplebinding/oddbool_test.py +++ b/sources/shiboken6/tests/samplebinding/oddbool_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for OddBool user's primitive type conversion.''' @@ -40,13 +13,15 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import OddBoolUser, ComparisonTester +from sample import OddBoolUser, ComparisonTester, SpaceshipComparisonTester + class DerivedOddBoolUser (OddBoolUser): def returnMyselfVirtual(self): return OddBoolUser() pass + class OddBoolTest(unittest.TestCase): def testOddBoolUser(self): @@ -57,13 +32,13 @@ class OddBoolTest(unittest.TestCase): self.assertEqual(obuTrue.oddBool(), True) self.assertEqual(obuTrue.callInvertedOddBool(), False) - self.assertEqual(obuTrue.oddBool() == True, True) - self.assertEqual(False == obuFalse.oddBool(), True) - self.assertEqual(obuTrue.oddBool() == obuFalse.oddBool(), False) + self.assertTrue(obuTrue.oddBool()) + self.assertFalse(obuFalse.oddBool()) + self.assertTrue(obuTrue.oddBool() != obuFalse.oddBool()) - self.assertEqual(obuFalse.oddBool() != True, True) - self.assertEqual(True != obuFalse.oddBool(), True) - self.assertEqual(obuTrue.oddBool() != obuFalse.oddBool(), True) + self.assertFalse(obuFalse.oddBool()) + self.assertFalse(obuFalse.oddBool()) + self.assertTrue(obuTrue.oddBool() != obuFalse.oddBool()) def testVirtuals(self): dobu = DerivedOddBoolUser() @@ -86,6 +61,19 @@ class OddBoolTest(unittest.TestCase): t2 = ComparisonTester(42) self.assertEqual(t1, t2) + def testSpaceshipOperator(self): + if not SpaceshipComparisonTester.HasSpaceshipOperator: + print("Skipping Spaceship Operator test") + return + t1 = SpaceshipComparisonTester(42) + t2 = SpaceshipComparisonTester(42) + self.assertEqual(t1, t2) + self.assertTrue(t1 <= t2) + self.assertTrue(t1 >= t2) + t2 = SpaceshipComparisonTester(43) + self.assertTrue(t1 < t2) + self.assertFalse(t1 > t2) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/onlycopyclass_test.py b/sources/shiboken6/tests/samplebinding/onlycopyclass_test.py index 65ec14cd7..bcb154c52 100644 --- a/sources/shiboken6/tests/samplebinding/onlycopyclass_test.py +++ b/sources/shiboken6/tests/samplebinding/onlycopyclass_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -40,6 +13,7 @@ init_paths() from sample import OnlyCopy, FriendOfOnlyCopy + class ClassWithOnlyCopyCtorTest(unittest.TestCase): def testGetOne(self): obj = FriendOfOnlyCopy.createOnlyCopy(123) @@ -61,5 +35,6 @@ class ClassWithOnlyCopyCtorTest(unittest.TestCase): obj = FriendOfOnlyCopy.createOnlyCopy(123) self.assertEqual(obj.value(), OnlyCopy.getValueFromReference(obj)) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/overflow_test.py b/sources/shiboken6/tests/samplebinding/overflow_test.py index 5635eeed2..84442306a 100644 --- a/sources/shiboken6/tests/samplebinding/overflow_test.py +++ b/sources/shiboken6/tests/samplebinding/overflow_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test case for overflowing C++ numeric types.''' @@ -40,21 +13,29 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import (Point, doubleLongLong, doubleShort, doubleUnsignedInt, + doubleUnsignedLongLong) class OverflowTest(unittest.TestCase): '''Test case for overflowing C++ numeric types.''' + def assertRaises(self, *args, **kwds): + if not hasattr(sys, "pypy_version_info"): + # PYSIDE-535: PyPy complains "Fatal RPython error: NotImplementedError" + return super().assertRaises(*args, **kwds) + def testUnsignedInt(self): - '''C++ function receives an unsigned int argument and raise OverflowError if the value is negative.''' + '''C++ function receives an unsigned int argument and raise OverflowError + if the value is negative.''' val = 100 self.assertEqual(doubleUnsignedInt(val), 2 * val) val *= -1 self.assertRaises(OverflowError, doubleUnsignedInt, val) def testLongLong(self): - '''C++ function receives an long long argument and raise OverflowError if the value is negative.''' + '''C++ function receives an long long argument and raise OverflowError + if the value is negative.''' val = 100 self.assertEqual(doubleLongLong(val), 2 * val) val = int(100) @@ -63,7 +44,8 @@ class OverflowTest(unittest.TestCase): self.assertRaises(OverflowError, doubleLongLong, val) def testUnsignedLongLong(self): - '''C++ function receives an unsigned long long argument and raise OverflowError if the value is negative.''' + '''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 = int(100) @@ -81,13 +63,13 @@ class OverflowTest(unittest.TestCase): def testShortOverflow(self): '''Calls function with short parameter using an overflowing value.''' doubleShort(-3) - self.assertRaises(OverflowError, doubleShort, 0xFFFF*-1) + self.assertRaises(OverflowError, doubleShort, 0xFFFF * -1) self.assertRaises(OverflowError, doubleShort, 0xFFFF + 1) def testOverflowOnCtor(self): '''Calls object ctor with int parameter using overflowing values.''' self.assertRaises(OverflowError, Point, 42415335332353253, 42415335332353253) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/overload_sorting_test.py b/sources/shiboken6/tests/samplebinding/overload_sorting_test.py index ff941e016..060d91510 100644 --- a/sources/shiboken6/tests/samplebinding/overload_sorting_test.py +++ b/sources/shiboken6/tests/samplebinding/overload_sorting_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for overload sorting''' @@ -40,11 +13,14 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import (CustomOverloadSequence, ImplicitBase, ImplicitConv, + ImplicitTarget, SortedOverload) + class Dummy(object): pass + class SimpleOverloadSorting(unittest.TestCase): def setUp(self): @@ -90,6 +66,7 @@ class DeepOverloadSorting(unittest.TestCase): '''Deep Overload - (int, ImplicitBase *)''' self.assertEqual(self.obj.overloadDeep(1, ImplicitBase()), "ImplicitBase") + class EnumOverIntSorting(unittest.TestCase): def testEnumOverInt(self): ic = ImplicitConv(ImplicitConv.CtorTwo) diff --git a/sources/shiboken6/tests/samplebinding/overload_test.py b/sources/shiboken6/tests/samplebinding/overload_test.py index 50f587eec..62fa8d8d2 100644 --- a/sources/shiboken6/tests/samplebinding/overload_test.py +++ b/sources/shiboken6/tests/samplebinding/overload_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for Overload class''' @@ -48,11 +21,10 @@ def raisesWithErrorMessage(func, arguments, errorType, errorMsg): try: func(*arguments) return False - except Exception as err: - if type(err) != TypeError: - return False - if not errorMsg in str(err): - return False + except TypeError as err: + return errorMsg in str(err) + except Exception: + return False return True @@ -205,12 +177,13 @@ class OverloadTest(unittest.TestCase): def testAcceptSequencePyObject(self): # Overload.acceptSequence(void*) overload = Overload() + class Foo(object): pass + foo = Foo() self.assertEqual(overload.acceptSequence(foo), Overload.Function5) if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/overloadwithdefault_test.py b/sources/shiboken6/tests/samplebinding/overloadwithdefault_test.py index 9d8b0aeab..269b97299 100644 --- a/sources/shiboken6/tests/samplebinding/overloadwithdefault_test.py +++ b/sources/shiboken6/tests/samplebinding/overloadwithdefault_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -66,6 +39,6 @@ class OverloadTest(unittest.TestCase): overload = Overload() self.assertEqual(overload.strBufferOverloads(bytes('', "UTF-8"), 0), Overload.Function1) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/ownership_argument_invalidation_test.py b/sources/shiboken6/tests/samplebinding/ownership_argument_invalidation_test.py index 3b5ae5c8e..8a55d3ab8 100644 --- a/sources/shiboken6/tests/samplebinding/ownership_argument_invalidation_test.py +++ b/sources/shiboken6/tests/samplebinding/ownership_argument_invalidation_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Wrapper validity tests for arguments.''' @@ -42,6 +15,7 @@ init_paths() from sample import Polygon, Point + class WrapperValidityOfArgumentsTest(unittest.TestCase): '''Wrapper validity tests for arguments.''' @@ -52,17 +26,19 @@ class WrapperValidityOfArgumentsTest(unittest.TestCase): self.assertRaises(RuntimeError, Polygon.doublePolygonScale, poly) def testInvalidArgumentToConstructor(self): - '''Call to constructor using invalidated Python wrapper as argument should raise RuntimeError.''' + '''Call to constructor using invalidated Python wrapper as argument + should raise RuntimeError.''' pt = Point(1, 2) Polygon.stealOwnershipFromPython(pt) self.assertRaises(RuntimeError, Polygon, pt) def testInvalidArgumentWithImplicitConversion(self): - '''Call to method using invalidated Python wrapper to be implicitly converted should raise RuntimeError.''' + '''Call to method using invalidated Python wrapper to be implicitly converted + should raise RuntimeError.''' pt = Point(1, 2) Polygon.stealOwnershipFromPython(pt) self.assertRaises(RuntimeError, Polygon.doublePolygonScale, pt) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/ownership_delete_child_in_cpp_test.py b/sources/shiboken6/tests/samplebinding/ownership_delete_child_in_cpp_test.py index be010c84b..25c6fea26 100644 --- a/sources/shiboken6/tests/samplebinding/ownership_delete_child_in_cpp_test.py +++ b/sources/shiboken6/tests/samplebinding/ownership_delete_child_in_cpp_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Tests for destroy a child object in C++''' @@ -57,5 +30,6 @@ class DeleteChildInCpp(unittest.TestCase): self.assertRaises(RuntimeError, child.objectName) self.assertEqual(parent.objectName(), 'parent') + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/ownership_delete_child_in_python_test.py b/sources/shiboken6/tests/samplebinding/ownership_delete_child_in_python_test.py index 10535f272..3ae186815 100644 --- a/sources/shiboken6/tests/samplebinding/ownership_delete_child_in_python_test.py +++ b/sources/shiboken6/tests/samplebinding/ownership_delete_child_in_python_test.py @@ -1,36 +1,10 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Tests for deleting a child object in python''' +import gc import os import random import string @@ -56,8 +30,11 @@ class DeleteChildInPython(unittest.TestCase): child.setObjectName(name) del child + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() new_child = parent.children()[0] self.assertEqual(new_child.objectName(), name) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/ownership_delete_parent_test.py b/sources/shiboken6/tests/samplebinding/ownership_delete_parent_test.py index 1f0d76cce..8f654639c 100644 --- a/sources/shiboken6/tests/samplebinding/ownership_delete_parent_test.py +++ b/sources/shiboken6/tests/samplebinding/ownership_delete_parent_test.py @@ -1,36 +1,10 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Tests for destroying the parent''' +import gc import os import sys import unittest @@ -46,6 +20,7 @@ from sample import ObjectType class DeleteParentTest(unittest.TestCase): '''Test case for deleting a parent object''' + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testParentDestructor(self): '''Delete parent object should invalidate child''' parent = ObjectType() @@ -55,9 +30,12 @@ class DeleteParentTest(unittest.TestCase): refcount_before = sys.getrefcount(child) del parent + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, child.objectName) - self.assertEqual(sys.getrefcount(child), refcount_before-1) + self.assertEqual(sys.getrefcount(child), refcount_before - 1) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testParentDestructorMultipleChildren(self): '''Delete parent object should invalidate all children''' parent = ObjectType() @@ -67,10 +45,13 @@ class DeleteParentTest(unittest.TestCase): child.setParent(parent) del parent + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() for i, child in enumerate(children): self.assertRaises(RuntimeError, child.objectName) self.assertEqual(sys.getrefcount(child), 4) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testRecursiveParentDelete(self): '''Delete parent should invalidate grandchildren''' parent = ObjectType() @@ -78,6 +59,8 @@ class DeleteParentTest(unittest.TestCase): grandchild = ObjectType(child) del parent + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, child.objectName) self.assertEqual(sys.getrefcount(child), 2) self.assertRaises(RuntimeError, grandchild.objectName) diff --git a/sources/shiboken6/tests/samplebinding/ownership_invalidate_after_use_test.py b/sources/shiboken6/tests/samplebinding/ownership_invalidate_after_use_test.py index e4a59426e..37b7591e4 100644 --- a/sources/shiboken6/tests/samplebinding/ownership_invalidate_after_use_test.py +++ b/sources/shiboken6/tests/samplebinding/ownership_invalidate_after_use_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Ownership tests for cases of invalidation of Python wrapper after use.''' @@ -48,11 +21,13 @@ class ExtObjectType(ObjectType): ObjectType.__init__(self) self.type_of_last_event = None self.last_event = None + def event(self, event): self.last_event = event self.type_of_last_event = event.eventType() return True + class MyObjectType (ObjectType): def __init__(self): super(MyObjectType, self).__init__() @@ -62,7 +37,7 @@ class MyObjectType (ObjectType): self.callInvalidateEvent(ev) try: ev.eventType() - except: + except: # noqa: E722 self.fail = True raise return True @@ -70,21 +45,25 @@ class MyObjectType (ObjectType): def invalidateEvent(self, ev): pass + class ExtObjectTypeDerived(ObjectTypeDerived): def __init__(self): ObjectTypeDerived.__init__(self) self.type_of_last_event = None self.last_event = None + def event(self, event): self.last_event = event self.type_of_last_event = event.eventType() return True + class OwnershipInvalidateAfterUseTest(unittest.TestCase): '''Ownership tests for cases of invalidation of Python wrapper after use.''' def testInvalidateAfterUse(self): - '''In ObjectType.event(Event*) the wrapper object created for Event must me marked as invalid after the method is called.''' + '''In ObjectType.event(Event*) the wrapper object created for Event + must me marked as invalid after the method is called.''' eot = ExtObjectType() eot.causeEvent(Event.SOME_EVENT) self.assertEqual(eot.type_of_last_event, Event.SOME_EVENT) @@ -111,6 +90,6 @@ class OwnershipInvalidateAfterUseTest(unittest.TestCase): self.assertEqual(eot.type_of_last_event, Event.SOME_EVENT) self.assertRaises(RuntimeError, eot.last_event.eventType) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/ownership_invalidate_child_test.py b/sources/shiboken6/tests/samplebinding/ownership_invalidate_child_test.py index 6ffa6629b..77b7c576c 100644 --- a/sources/shiboken6/tests/samplebinding/ownership_invalidate_child_test.py +++ b/sources/shiboken6/tests/samplebinding/ownership_invalidate_child_test.py @@ -1,36 +1,10 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Tests for invalidating a C++ created child that was already on the care of a parent.''' +import gc import os import sys import unittest @@ -67,10 +41,14 @@ class InvalidateChildTest(unittest.TestCase): self.assertEqual(parent.children(), []) del parent + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() + # PYSIDE-535: Why do I need to do it twice, here? + gc.collect() self.assertEqual(child1.objectName(), 'child1') self.assertRaises(RuntimeError, child2.objectName) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/ownership_invalidate_nonpolymorphic_test.py b/sources/shiboken6/tests/samplebinding/ownership_invalidate_nonpolymorphic_test.py index efc3afd38..8cbefc30c 100644 --- a/sources/shiboken6/tests/samplebinding/ownership_invalidate_nonpolymorphic_test.py +++ b/sources/shiboken6/tests/samplebinding/ownership_invalidate_nonpolymorphic_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''The BlackBox class has cases of ownership transference between Python and C++.''' @@ -42,6 +15,7 @@ init_paths() from sample import Point, BlackBox + class OwnershipInvalidateNonPolymorphicTest(unittest.TestCase): '''The BlackBox class has cases of ownership transference between Python and C++.''' @@ -54,6 +28,6 @@ class OwnershipInvalidateNonPolymorphicTest(unittest.TestCase): p1_ret = bb.retrievePoint(p1_ticket) self.assertEqual(p1_ret, Point(10, 20)) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/ownership_invalidate_parent_test.py b/sources/shiboken6/tests/samplebinding/ownership_invalidate_parent_test.py index d34eeedd2..c721a212c 100644 --- a/sources/shiboken6/tests/samplebinding/ownership_invalidate_parent_test.py +++ b/sources/shiboken6/tests/samplebinding/ownership_invalidate_parent_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Tests for invalidating a parent of other objects.''' @@ -61,7 +34,7 @@ class InvalidateParentTest(unittest.TestCase): grandchild2.setParent(child2) bbox = BlackBox() - bbox.keepObjectType(parent) # Should invalidate the parent + bbox.keepObjectType(parent) # Should invalidate the parent self.assertRaises(RuntimeError, parent.objectName) # some children still valid they are wrapper classes @@ -70,6 +43,6 @@ class InvalidateParentTest(unittest.TestCase): self.assertEqual(grandchild1.objectName(), "grandchild1") self.assertRaises(RuntimeError, grandchild2.objectName) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/ownership_reparenting_test.py b/sources/shiboken6/tests/samplebinding/ownership_reparenting_test.py index d0b363790..304223063 100644 --- a/sources/shiboken6/tests/samplebinding/ownership_reparenting_test.py +++ b/sources/shiboken6/tests/samplebinding/ownership_reparenting_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Tests for object reparenting.''' @@ -43,6 +16,7 @@ import sys from sample import ObjectType + class ExtObjectType(ObjectType): def __init__(self): ObjectType.__init__(self) @@ -65,6 +39,7 @@ class ReparentingTest(unittest.TestCase): for child in new_parent.children(): self.assertTrue(child in object_list) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testReparentWithTheSameParent(self): '''Set the same parent twice to check if the ref continue the same''' obj = ObjectType() @@ -134,4 +109,3 @@ class ReparentingTest(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/ownership_transference_test.py b/sources/shiboken6/tests/samplebinding/ownership_transference_test.py index 3cea6b3fb..0e9f08b72 100644 --- a/sources/shiboken6/tests/samplebinding/ownership_transference_test.py +++ b/sources/shiboken6/tests/samplebinding/ownership_transference_test.py @@ -1,36 +1,10 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''The BlackBox class has cases of ownership transference between C++ and Python.''' +import gc import os import sys import unittest @@ -42,9 +16,11 @@ init_paths() from sample import ObjectType, BlackBox + class BlackBoxTest(unittest.TestCase): '''The BlackBox class has cases of ownership transference between C++ and Python.''' + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testOwnershipTransference(self): '''Ownership transference from Python to C++ and back again.''' o1 = ObjectType() @@ -54,16 +30,19 @@ class BlackBoxTest(unittest.TestCase): o2.setObjectName('object2') o2_refcnt = sys.getrefcount(o2) bb = BlackBox() - o1_ticket = bb.keepObjectType(o1) + o1_ticket = bb.keepObjectType(o1) # noqa: F841 o2_ticket = bb.keepObjectType(o2) self.assertEqual(set(bb.objects()), set([o1, o2])) self.assertEqual(str(o1.objectName()), 'object1') self.assertEqual(str(o2.objectName()), 'object2') - self.assertEqual(sys.getrefcount(o1), o1_refcnt + 1) # PySide give +1 ref to object with c++ ownership + # PySide give +1 ref to object with c++ ownership + self.assertEqual(sys.getrefcount(o1), o1_refcnt + 1) self.assertEqual(sys.getrefcount(o2), o2_refcnt + 1) o2 = bb.retrieveObjectType(o2_ticket) self.assertEqual(sys.getrefcount(o2), o2_refcnt) del bb + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, o1.objectName) self.assertEqual(str(o2.objectName()), 'object2') self.assertEqual(sys.getrefcount(o2), o2_refcnt) @@ -71,21 +50,22 @@ class BlackBoxTest(unittest.TestCase): def testBlackBoxReleasingUnknownObjectType(self): '''Asks BlackBox to release an unknown ObjectType.''' o1 = ObjectType() - o2 = ObjectType() + o2 = ObjectType() # noqa: F841 bb = BlackBox() - o1_ticket = bb.keepObjectType(o1) + o1_ticket = bb.keepObjectType(o1) # noqa: F841 o3 = bb.retrieveObjectType(-5) self.assertEqual(o3, None) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testOwnershipTransferenceCppCreated(self): '''Ownership transference using a C++ created object.''' o1 = ObjectType.create() o1.setObjectName('object1') - o1_refcnt = sys.getrefcount(o1) + o1_refcnt = sys.getrefcount(o1) # noqa: F841 bb = BlackBox() - o1_ticket = bb.keepObjectType(o1) + o1_ticket = bb.keepObjectType(o1) # noqa: F841 self.assertRaises(RuntimeError, o1.objectName) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/pair_test.py b/sources/shiboken6/tests/samplebinding/pair_test.py index 559f15ba2..4bd5c697c 100644 --- a/sources/shiboken6/tests/samplebinding/pair_test.py +++ b/sources/shiboken6/tests/samplebinding/pair_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for std::pair container conversions''' @@ -42,6 +15,7 @@ init_paths() from sample import PairUser + class ExtendedPairUser(PairUser): def __init__(self): PairUser.__init__(self) @@ -51,6 +25,7 @@ class ExtendedPairUser(PairUser): self.create_pair_called = True return (7, 13) + class PairConversionTest(unittest.TestCase): '''Test case for std::pair container conversions''' @@ -75,14 +50,16 @@ class PairConversionTest(unittest.TestCase): self.assertEqual(cp, (cpx0, cpx1)) def testSumPair(self): - '''Test method that sums the items of a pair using values of the types expected by C++ (int and double)''' + '''Test method that sums the items of a pair using values of the types + expected by C++ (int and double)''' pu = PairUser() pair = (3, 7.13) result = pu.sumPair(pair) self.assertEqual(result, sum(pair)) def testSumPairDifferentTypes(self): - '''Test method that sums the items of a pair using values of types different from the ones expected by C++ (int and double)''' + '''Test method that sums the items of a pair using values of types different + from the ones expected by C++ (int and double)''' pu = PairUser() pair = (3.3, 7) result = pu.sumPair(pair) @@ -98,7 +75,8 @@ class PairConversionTest(unittest.TestCase): self.assertEqual(result, pair) def testConversionInBothDirectionsWithSimilarContainer(self): - '''Test converting a list, instead of the expected tuple, from Python to C++ and the other way around.''' + '''Test converting a list, instead of the expected tuple, from Python to C++ + and the other way around.''' pu = PairUser() pair = [3, 5] pu.setPair(pair) @@ -106,6 +84,6 @@ class PairConversionTest(unittest.TestCase): self.assertNotEqual(result, pair) self.assertEqual(result, tuple(pair)) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/pen_test.py b/sources/shiboken6/tests/samplebinding/pen_test.py index 9cd1be2f6..106f3bd61 100644 --- a/sources/shiboken6/tests/samplebinding/pen_test.py +++ b/sources/shiboken6/tests/samplebinding/pen_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for <add-function> with const char* as argument''' @@ -42,6 +15,7 @@ init_paths() from sample import Color, Pen, SampleNamespace + class TestPen(unittest.TestCase): '''Simple test case for Pen.''' diff --git a/sources/shiboken6/tests/samplebinding/point_test.py b/sources/shiboken6/tests/samplebinding/point_test.py index bffaba6df..f86c0f423 100644 --- a/sources/shiboken6/tests/samplebinding/point_test.py +++ b/sources/shiboken6/tests/samplebinding/point_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for Point class''' @@ -42,9 +15,15 @@ init_paths() from sample import Point + class PointTest(unittest.TestCase): '''Test case for Point class, including operator overloads.''' + def assertRaises(self, *args, **kwds): + if not hasattr(sys, "pypy_version_info"): + # PYSIDE-535: PyPy complains "Fatal RPython error: NotImplementedError" + return super().assertRaises(*args, **kwds) + def testConstructor(self): '''Test Point class constructor.''' pt = Point(5.0, 2.3) @@ -84,6 +63,7 @@ class PointTest(unittest.TestCase): pt2 += pt1 self.assertFalse(pt1 == pt2) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testReturnConstPointer(self): '''Point returns a const pointer for itself.''' pt1 = Point(5.0, 2.3) @@ -113,5 +93,6 @@ class PointTest(unittest.TestCase): expected = Point((pt1.x() + pt2.x()) / 2.0, (pt1.y() + pt2.y()) / 2.0) self.assertEqual(pt1.midpoint(pt2), expected) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/pointerholder_test.py b/sources/shiboken6/tests/samplebinding/pointerholder_test.py index 3468ceedc..633525a9c 100644 --- a/sources/shiboken6/tests/samplebinding/pointerholder_test.py +++ b/sources/shiboken6/tests/samplebinding/pointerholder_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for a class that holds an arbitraty pointer and is modified to hold an PyObject.''' @@ -42,8 +15,10 @@ init_paths() from sample import PointerHolder + class TestPointerHolder(unittest.TestCase): - '''Test cases for a class that holds an arbitraty pointer and is modified to hold an PyObject.''' + '''Test cases for a class that holds an arbitraty pointer and + is modified to hold an PyObject.''' def testStoringAndRetrievingPointer(self): ph = PointerHolder('Hello') @@ -52,14 +27,15 @@ class TestPointerHolder(unittest.TestCase): ph = PointerHolder(a) self.assertEqual(ph.pointer(), a) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testReferenceCounting(self): '''Test reference counting when retrieving data with PointerHolder.pointer().''' a = (1, 2, 3) refcnt = sys.getrefcount(a) ph = PointerHolder(a) - ptr = ph.pointer() + ptr = ph.pointer() # noqa: F841 self.assertEqual(sys.getrefcount(a), refcnt + 1) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/pointerprimitivetype_test.py b/sources/shiboken6/tests/samplebinding/pointerprimitivetype_test.py index 09362d05f..4da1a89c6 100644 --- a/sources/shiboken6/tests/samplebinding/pointerprimitivetype_test.py +++ b/sources/shiboken6/tests/samplebinding/pointerprimitivetype_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2019 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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 """ pointerprimitivetype_test.py @@ -54,9 +27,9 @@ from shiboken_paths import init_paths init_paths() from sample import IntArray2, VirtualMethods -import shiboken6 -_init_pyside_extension() # trigger init, which does not happen in tests -from shibokensupport.signature import typing +from shibokensupport.signature import get_signature + +import typing class PointerPrimitiveTypeTest(unittest.TestCase): @@ -64,7 +37,7 @@ class PointerPrimitiveTypeTest(unittest.TestCase): def testArraySignature(self): # signature="IntArray2(const int*)" found = False - for sig in IntArray2.__signature__: + for sig in get_signature(IntArray2): if "data" in sig.parameters: found = True break @@ -75,7 +48,7 @@ class PointerPrimitiveTypeTest(unittest.TestCase): def testReturnVarSignature(self): # signature="getMargins(int*,int*,int*,int*)const"> - ann = VirtualMethods.getMargins.__signature__.return_annotation + ann = get_signature(VirtualMethods.getMargins).return_annotation self.assertEqual(ann, typing.Tuple[int, int, int, int]) diff --git a/sources/shiboken6/tests/samplebinding/pointf_test.py b/sources/shiboken6/tests/samplebinding/pointf_test.py index 3b8285b0b..91c58eb1d 100644 --- a/sources/shiboken6/tests/samplebinding/pointf_test.py +++ b/sources/shiboken6/tests/samplebinding/pointf_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for PointF class''' @@ -42,6 +15,7 @@ init_paths() from sample import PointF + class PointFTest(unittest.TestCase): '''Test case for PointF class, including operator overloads.''' @@ -72,5 +46,6 @@ class PointFTest(unittest.TestCase): expected = PointF((pt1.x() + pt2.x()) / 2.0, (pt1.y() + pt2.y()) / 2.0) self.assertEqual(pt1.midpoint(pt2), expected) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/primitivereferenceargument_test.py b/sources/shiboken6/tests/samplebinding/primitivereferenceargument_test.py index 26dd3046b..0b9fe2249 100644 --- a/sources/shiboken6/tests/samplebinding/primitivereferenceargument_test.py +++ b/sources/shiboken6/tests/samplebinding/primitivereferenceargument_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -39,12 +12,17 @@ from shiboken_paths import init_paths init_paths() import sample + class PrimitiveReferenceArgumentTest(unittest.TestCase): def testIntReferenceArgument(self): '''C++ signature: int acceptIntReference(int&)''' self.assertEqual(sample.acceptIntReference(123), 123) + def testIntReturnPtr(self): + '''C++ signature: const int *acceptIntReturnPtr(int x)''' + self.assertEqual(sample.acceptIntReturnPtr(123), 123) + def testOddBoolReferenceArgument(self): '''C++ signature: OddBool acceptOddBoolReference(OddBool&)''' self.assertEqual(sample.acceptOddBoolReference(True), True) @@ -52,5 +30,6 @@ class PrimitiveReferenceArgumentTest(unittest.TestCase): self.assertNotEqual(sample.acceptOddBoolReference(True), False) self.assertNotEqual(sample.acceptOddBoolReference(False), True) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/privatector_test.py b/sources/shiboken6/tests/samplebinding/privatector_test.py index c5f7ee58a..63040388d 100644 --- a/sources/shiboken6/tests/samplebinding/privatector_test.py +++ b/sources/shiboken6/tests/samplebinding/privatector_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for a class with only a private constructor.''' @@ -47,6 +20,11 @@ from sample import PrivateCtor class PrivateCtorTest(unittest.TestCase): '''Test case for PrivateCtor class''' + def assertRaises(self, *args, **kwds): + if not hasattr(sys, "pypy_version_info"): + # PYSIDE-535: PyPy complains "Fatal RPython error: NotImplementedError" + return super().assertRaises(*args, **kwds) + def testPrivateCtorInstanciation(self): '''Test if instanciation of class with a private constructor raises an exception.''' self.assertRaises(TypeError, PrivateCtor) @@ -67,6 +45,7 @@ class PrivateCtorTest(unittest.TestCase): self.assertEqual(pd2, pd1) self.assertEqual(pd2.instanceCalls(), calls + 1) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testPrivateCtorRefCounting(self): '''Test refcounting of the singleton returned by PrivateCtor.instance().''' pd1 = PrivateCtor.instance() @@ -85,6 +64,6 @@ class PrivateCtorTest(unittest.TestCase): self.assertEqual(pd3.instanceCalls(), calls + 2) self.assertEqual(sys.getrefcount(pd3), refcnt) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/privatedtor_test.py b/sources/shiboken6/tests/samplebinding/privatedtor_test.py index f310ec51d..651f63b15 100644 --- a/sources/shiboken6/tests/samplebinding/privatedtor_test.py +++ b/sources/shiboken6/tests/samplebinding/privatedtor_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for a class with a private destructor.''' @@ -48,6 +21,11 @@ from sample import PrivateDtor class PrivateDtorTest(unittest.TestCase): '''Test case for PrivateDtor class''' + def assertRaises(self, *args, **kwds): + if not hasattr(sys, "pypy_version_info"): + # PYSIDE-535: PyPy complains "Fatal RPython error: NotImplementedError" + return super().assertRaises(*args, **kwds) + def testPrivateDtorInstanciation(self): '''Test if instanciation of class with a private destructor raises an exception.''' self.assertRaises(TypeError, PrivateDtor) @@ -68,6 +46,7 @@ class PrivateDtorTest(unittest.TestCase): self.assertEqual(pd2, pd1) self.assertEqual(pd2.instanceCalls(), calls + 1) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testPrivateDtorRefCounting(self): '''Test refcounting of the singleton returned by PrivateDtor.instance().''' pd1 = PrivateDtor.instance() @@ -86,6 +65,7 @@ class PrivateDtorTest(unittest.TestCase): self.assertEqual(pd3.instanceCalls(), calls + 2) self.assertEqual(sys.getrefcount(pd3), refcnt) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testClassDecref(self): # Bug was that class PyTypeObject wasn't decrefed when instance # was invalidated @@ -100,6 +80,6 @@ class PrivateDtorTest(unittest.TestCase): self.assertLess(abs(before - after), 5) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/protected_test.py b/sources/shiboken6/tests/samplebinding/protected_test.py index 096eb615d..e4ccf721d 100644 --- a/sources/shiboken6/tests/samplebinding/protected_test.py +++ b/sources/shiboken6/tests/samplebinding/protected_test.py @@ -1,36 +1,10 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for protected methods.''' +import gc import os import sys import unittest @@ -42,46 +16,57 @@ init_paths() from sample import cacheSize from sample import ProtectedNonPolymorphic, ProtectedVirtualDestructor -from sample import ProtectedPolymorphic, ProtectedPolymorphicDaughter, ProtectedPolymorphicGrandDaughter +from sample import (ProtectedPolymorphic, ProtectedPolymorphicDaughter, + ProtectedPolymorphicGrandDaughter) from sample import createProtectedProperty, ProtectedProperty, ProtectedEnumClass from sample import PrivateDtor from sample import Event, ObjectType, Point + class ExtendedProtectedPolymorphic(ProtectedPolymorphic): def __init__(self, name): ProtectedPolymorphic.__init__(self, name) self.protectedName_called = False + def protectedName(self): self.protectedName_called = True self._name = 'Extended' + ProtectedPolymorphic.protectedName(self) return self._name + class ExtendedProtectedPolymorphicDaughter(ProtectedPolymorphicDaughter): def __init__(self, name): self.protectedName_called = False ProtectedPolymorphicDaughter.__init__(self, name) + def protectedName(self): self.protectedName_called = True self._name = 'ExtendedDaughter' + ProtectedPolymorphicDaughter.protectedName(self) return self._name + class ExtendedProtectedPolymorphicGrandDaughter(ProtectedPolymorphicGrandDaughter): def __init__(self, name): self.protectedName_called = False ProtectedPolymorphicGrandDaughter.__init__(self, name) + def protectedName(self): self.protectedName_called = True self._name = 'ExtendedGrandDaughter' + ProtectedPolymorphicGrandDaughter.protectedName(self) return self._name + class ExtendedProtectedVirtualDestructor(ProtectedVirtualDestructor): def __init__(self): ProtectedVirtualDestructor.__init__(self) + class ProtectedNonPolymorphicTest(unittest.TestCase): '''Test cases for protected method in a class without virtual methods.''' def tearDown(self): + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(cacheSize(), 0) def testProtectedCall(self): @@ -105,10 +90,13 @@ class ProtectedNonPolymorphicTest(unittest.TestCase): self.assertEqual(p.dataTypeName(1), 'integer') self.assertEqual(p.dataTypeName(Point(1, 2)), 'pointer') + class ProtectedPolymorphicTest(unittest.TestCase): '''Test cases for protected method in a class with virtual methods.''' def tearDown(self): + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(cacheSize(), 0) def testProtectedCall(self): @@ -132,6 +120,8 @@ class ProtectedPolymorphicTest(unittest.TestCase): self.assertTrue(p.protectedName_called) self.assertEqual(p.protectedName(), name) self.assertEqual(ProtectedPolymorphic.protectedName(p), original_name) + + class ProtectedPolymorphicDaugherTest(unittest.TestCase): '''Test cases for protected method in a class inheriting for a class with virtual methods.''' @@ -156,6 +146,8 @@ class ProtectedPolymorphicGrandDaugherTest(unittest.TestCase): another with protected virtual methods.''' def tearDown(self): + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(cacheSize(), 0) def testProtectedCallWithInstanceCreatedOnCpp(self): @@ -173,6 +165,7 @@ class ProtectedPolymorphicGrandDaugherTest(unittest.TestCase): self.assertEqual(p.protectedName(), name) self.assertEqual(ProtectedPolymorphicGrandDaughter.protectedName(p), original_name) + class ProtectedVirtualDtorTest(unittest.TestCase): '''Test cases for protected virtual destructor.''' @@ -180,6 +173,8 @@ class ProtectedVirtualDtorTest(unittest.TestCase): ProtectedVirtualDestructor.resetDtorCounter() def tearDown(self): + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(cacheSize(), 0) def testVirtualProtectedDtor(self): @@ -187,7 +182,11 @@ class ProtectedVirtualDtorTest(unittest.TestCase): dtor_called = ProtectedVirtualDestructor.dtorCalled() for i in range(1, 10): pvd = ProtectedVirtualDestructor() + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() del pvd + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(ProtectedVirtualDestructor.dtorCalled(), dtor_called + i) def testVirtualProtectedDtorOnCppCreatedObject(self): @@ -196,6 +195,8 @@ class ProtectedVirtualDtorTest(unittest.TestCase): for i in range(1, 10): pvd = ProtectedVirtualDestructor.create() del pvd + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(ProtectedVirtualDestructor.dtorCalled(), dtor_called + i) def testProtectedDtorOnDerivedClass(self): @@ -204,25 +205,32 @@ class ProtectedVirtualDtorTest(unittest.TestCase): for i in range(1, 10): pvd = ExtendedProtectedVirtualDestructor() del pvd + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(ExtendedProtectedVirtualDestructor.dtorCalled(), dtor_called + i) class ExtendedProtectedEnumClass(ProtectedEnumClass): def __init__(self): ProtectedEnumClass.__init__(self) + def protectedEnumMethod(self, value): if value == ProtectedEnumClass.ProtectedItem0: return ProtectedEnumClass.ProtectedItem1 return ProtectedEnumClass.ProtectedItem0 + def publicEnumMethod(self, value): if value == ProtectedEnumClass.PublicItem0: return ProtectedEnumClass.PublicItem1 return ProtectedEnumClass.PublicItem0 + class ProtectedEnumTest(unittest.TestCase): '''Test cases for protected enum.''' def tearDown(self): + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(cacheSize(), 0) def testProtectedMethodWithProtectedEnumArgument(self): @@ -231,47 +239,66 @@ class ProtectedEnumTest(unittest.TestCase): self.assertEqual(type(ProtectedEnumClass.ProtectedItem0), ProtectedEnumClass.ProtectedEnum) - self.assertEqual(obj.protectedEnumMethod(ProtectedEnumClass.ProtectedItem0), ProtectedEnumClass.ProtectedItem0) - self.assertEqual(obj.protectedEnumMethod(ProtectedEnumClass.ProtectedItem1), ProtectedEnumClass.ProtectedItem1) - - self.assertEqual(obj.callProtectedEnumMethod(ProtectedEnumClass.ProtectedItem0), ProtectedEnumClass.ProtectedItem0) - self.assertEqual(obj.callProtectedEnumMethod(ProtectedEnumClass.ProtectedItem1), ProtectedEnumClass.ProtectedItem1) + self.assertEqual(obj.protectedEnumMethod(ProtectedEnumClass.ProtectedItem0), + ProtectedEnumClass.ProtectedItem0) + self.assertEqual(obj.protectedEnumMethod(ProtectedEnumClass.ProtectedItem1), + ProtectedEnumClass.ProtectedItem1) + self.assertEqual(obj.callProtectedEnumMethod(ProtectedEnumClass.ProtectedItem0), + ProtectedEnumClass.ProtectedItem0) + self.assertEqual(obj.callProtectedEnumMethod(ProtectedEnumClass.ProtectedItem1), + ProtectedEnumClass.ProtectedItem1) def testProtectedMethodWithPublicEnumArgument(self): '''Calls protected method with public enum argument.''' obj = ProtectedEnumClass() - self.assertEqual(obj.publicEnumMethod(ProtectedEnumClass.PublicItem0), ProtectedEnumClass.PublicItem0) - self.assertEqual(obj.publicEnumMethod(ProtectedEnumClass.PublicItem1), ProtectedEnumClass.PublicItem1) + self.assertEqual(obj.publicEnumMethod(ProtectedEnumClass.PublicItem0), + ProtectedEnumClass.PublicItem0) + self.assertEqual(obj.publicEnumMethod(ProtectedEnumClass.PublicItem1), + ProtectedEnumClass.PublicItem1) - self.assertEqual(obj.callPublicEnumMethod(ProtectedEnumClass.PublicItem0), ProtectedEnumClass.PublicItem0) - self.assertEqual(obj.callPublicEnumMethod(ProtectedEnumClass.PublicItem1), ProtectedEnumClass.PublicItem1) + self.assertEqual(obj.callPublicEnumMethod(ProtectedEnumClass.PublicItem0), + ProtectedEnumClass.PublicItem0) + self.assertEqual(obj.callPublicEnumMethod(ProtectedEnumClass.PublicItem1), + ProtectedEnumClass.PublicItem1) def testOverriddenProtectedMethodWithProtectedEnumArgument(self): '''Calls overridden protected method with protected enum argument.''' obj = ExtendedProtectedEnumClass() - self.assertEqual(obj.protectedEnumMethod(ProtectedEnumClass.ProtectedItem0), ProtectedEnumClass.ProtectedItem1) - self.assertEqual(obj.protectedEnumMethod(ProtectedEnumClass.ProtectedItem1), ProtectedEnumClass.ProtectedItem0) + self.assertEqual(obj.protectedEnumMethod(ProtectedEnumClass.ProtectedItem0), + ProtectedEnumClass.ProtectedItem1) + self.assertEqual(obj.protectedEnumMethod(ProtectedEnumClass.ProtectedItem1), + ProtectedEnumClass.ProtectedItem0) - self.assertEqual(ProtectedEnumClass.protectedEnumMethod(obj, ProtectedEnumClass.ProtectedItem0), ProtectedEnumClass.ProtectedItem0) - self.assertEqual(ProtectedEnumClass.protectedEnumMethod(obj, ProtectedEnumClass.ProtectedItem1), ProtectedEnumClass.ProtectedItem1) + self.assertEqual(ProtectedEnumClass.protectedEnumMethod(obj, ProtectedEnumClass.ProtectedItem0), # noqa: E501 + ProtectedEnumClass.ProtectedItem0) + self.assertEqual(ProtectedEnumClass.protectedEnumMethod(obj, + ProtectedEnumClass.ProtectedItem1), ProtectedEnumClass.ProtectedItem1) - self.assertEqual(obj.callProtectedEnumMethod(ProtectedEnumClass.ProtectedItem0), ProtectedEnumClass.ProtectedItem1) - self.assertEqual(obj.callProtectedEnumMethod(ProtectedEnumClass.ProtectedItem1), ProtectedEnumClass.ProtectedItem0) + self.assertEqual(obj.callProtectedEnumMethod(ProtectedEnumClass.ProtectedItem0), + ProtectedEnumClass.ProtectedItem1) + self.assertEqual(obj.callProtectedEnumMethod(ProtectedEnumClass.ProtectedItem1), + ProtectedEnumClass.ProtectedItem0) def testOverriddenProtectedMethodWithPublicEnumArgument(self): '''Calls overridden protected method with public enum argument.''' obj = ExtendedProtectedEnumClass() - self.assertEqual(obj.publicEnumMethod(ProtectedEnumClass.PublicItem0), ProtectedEnumClass.PublicItem1) - self.assertEqual(obj.publicEnumMethod(ProtectedEnumClass.PublicItem1), ProtectedEnumClass.PublicItem0) + self.assertEqual(obj.publicEnumMethod(ProtectedEnumClass.PublicItem0), + ProtectedEnumClass.PublicItem1) + self.assertEqual(obj.publicEnumMethod(ProtectedEnumClass.PublicItem1), + ProtectedEnumClass.PublicItem0) - self.assertEqual(ProtectedEnumClass.publicEnumMethod(obj, ProtectedEnumClass.PublicItem0), ProtectedEnumClass.PublicItem0) - self.assertEqual(ProtectedEnumClass.publicEnumMethod(obj, ProtectedEnumClass.PublicItem1), ProtectedEnumClass.PublicItem1) + self.assertEqual(ProtectedEnumClass.publicEnumMethod(obj, ProtectedEnumClass.PublicItem0), + ProtectedEnumClass.PublicItem0) + self.assertEqual(ProtectedEnumClass.publicEnumMethod(obj, ProtectedEnumClass.PublicItem1), + ProtectedEnumClass.PublicItem1) - self.assertEqual(obj.callPublicEnumMethod(ProtectedEnumClass.PublicItem0), ProtectedEnumClass.PublicItem1) - self.assertEqual(obj.callPublicEnumMethod(ProtectedEnumClass.PublicItem1), ProtectedEnumClass.PublicItem0) + self.assertEqual(obj.callPublicEnumMethod(ProtectedEnumClass.PublicItem0), + ProtectedEnumClass.PublicItem1) + self.assertEqual(obj.callPublicEnumMethod(ProtectedEnumClass.PublicItem1), + ProtectedEnumClass.PublicItem0) class ProtectedPropertyTest(unittest.TestCase): @@ -282,6 +309,8 @@ class ProtectedPropertyTest(unittest.TestCase): def tearDown(self): del self.obj + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(cacheSize(), 0) def testProtectedProperty(self): @@ -323,6 +352,8 @@ class ProtectedPropertyTest(unittest.TestCase): pointProperty = obj.protectedValueTypeProperty self.assertTrue(obj.protectedValueTypeProperty is pointProperty) del obj, point, pointProperty + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(cacheSize(), cache_size) def testProtectedValueTypePointerProperty(self): @@ -334,18 +365,24 @@ class ProtectedPropertyTest(unittest.TestCase): self.assertEqual(self.obj.protectedValueTypePointerProperty, pt2) self.assertTrue(self.obj.protectedValueTypePointerProperty is pt1) self.assertFalse(self.obj.protectedValueTypePointerProperty is pt2) + # PYSIDE-535: Need to assign None to break the cycle + self.obj.protectedValueTypePointerProperty = None def testProtectedObjectTypeProperty(self): '''Writes and reads a protected object type property.''' obj = ObjectType() self.obj.protectedObjectTypeProperty = obj self.assertEqual(self.obj.protectedObjectTypeProperty, obj) + # PYSIDE-535: Need to assign None to break the cycle + self.obj.protectedObjectTypeProperty = None class PrivateDtorProtectedMethodTest(unittest.TestCase): '''Test cases for classes with private destructors and protected methods.''' def tearDown(self): + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(cacheSize(), 0) def testProtectedMethod(self): @@ -359,6 +396,6 @@ class PrivateDtorProtectedMethodTest(unittest.TestCase): self.assertEqual(obj.instanceCalls(), 2) self.assertEqual(obj.instanceCalls(), obj.protectedInstanceCalls()) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/pstrlist_test.py b/sources/shiboken6/tests/samplebinding/pstrlist_test.py index 2d2ae5942..d60f9cf35 100644 --- a/sources/shiboken6/tests/samplebinding/pstrlist_test.py +++ b/sources/shiboken6/tests/samplebinding/pstrlist_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -39,6 +12,7 @@ from shiboken_paths import init_paths init_paths() import sample + class PStrListTest(unittest.TestCase): def testPStrList(self): @@ -53,5 +27,6 @@ class PStrListTest(unittest.TestCase): lst = sample.createListOfPStr(a, b) self.assertEqual(lst, [a, b]) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/pystr_test.py b/sources/shiboken6/tests/samplebinding/pystr_test.py index d19715e7c..ec64c1e31 100644 --- a/sources/shiboken6/tests/samplebinding/pystr_test.py +++ b/sources/shiboken6/tests/samplebinding/pystr_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for definition of __str__ method.''' @@ -42,6 +15,7 @@ init_paths() from sample import Point + class PyStrTest(unittest.TestCase): '''Test case for definition of __str__ method.''' @@ -50,6 +24,6 @@ class PyStrTest(unittest.TestCase): pt = Point(5, 2) self.assertEqual(str(pt), 'Point(5.0, 2.0)') + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/python_thread_test.py b/sources/shiboken6/tests/samplebinding/python_thread_test.py index ca0508182..65398b5c6 100644 --- a/sources/shiboken6/tests/samplebinding/python_thread_test.py +++ b/sources/shiboken6/tests/samplebinding/python_thread_test.py @@ -1,30 +1,5 @@ -############################################################################# -## -## 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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #!/usr/bin/env python @@ -61,10 +36,10 @@ class Producer(threading.Thread): def run(self): while self.runs < self.max_runs: - value = int(random()*10) % 10 + value = int(random() * 10) % 10 self.bucket.push(value) self.production_list.append(value) - logging.debug('PRODUCER - pushed %d' % value) + logging.debug(f'PRODUCER - pushed {value}') self.runs += 1 #self.msleep(5) time.sleep(0.01) @@ -85,12 +60,13 @@ class Consumer(threading.Thread): if not self.bucket.empty(): value = self.bucket.pop() self.consumption_list.append(value) - logging.debug('CONSUMER - got %d' % value) + logging.debug(f'CONSUMER - got {value}') self.runs += 1 else: logging.debug('CONSUMER - empty bucket') time.sleep(0.01) + class ProducerConsumer(unittest.TestCase): '''Basic test case for producer-consumer QThread''' @@ -116,8 +92,5 @@ class ProducerConsumer(unittest.TestCase): self.assertEqual(prod.production_list, cons.consumption_list) - - - if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/receive_null_cstring_test.py b/sources/shiboken6/tests/samplebinding/receive_null_cstring_test.py index f8519165b..1d19de941 100644 --- a/sources/shiboken6/tests/samplebinding/receive_null_cstring_test.py +++ b/sources/shiboken6/tests/samplebinding/receive_null_cstring_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test case for a function that could receive a NULL pointer in a '[const] char*' parameter.''' @@ -42,8 +15,10 @@ init_paths() from sample import countCharacters + class ReceiveNullCStringTest(unittest.TestCase): - '''Test case for a function that could receive a NULL pointer in a '[const] char*' parameter.''' + '''Test case for a function that could receive a NULL pointer in a '[const] char*' + parameter.''' def testBasic(self): '''The test function should be working for the basic cases.''' @@ -56,6 +31,6 @@ class ReceiveNullCStringTest(unittest.TestCase): '''The test function returns '-1' when receives a None value instead of a string.''' self.assertEqual(countCharacters(None), -1) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/reference_test.py b/sources/shiboken6/tests/samplebinding/reference_test.py index 4255f1921..1b6dd3a7a 100644 --- a/sources/shiboken6/tests/samplebinding/reference_test.py +++ b/sources/shiboken6/tests/samplebinding/reference_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for methods that receive references to objects.''' @@ -40,7 +13,8 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import Reference, Str + class ExtendedReference(Reference): def __init__(self): @@ -75,7 +49,7 @@ class ReferenceTest(unittest.TestCase): def testCantSegFaultWhenReceiveNone(self): '''do not segfault when receiving None as argument.''' s = Str() - self.assertTrue(None == s) + self.assertFalse(bool(s)) def testMethodThatReceivesConstReference(self): '''Test a method that receives a const reference to an object as argument.''' @@ -84,29 +58,33 @@ class ReferenceTest(unittest.TestCase): self.assertEqual(Reference.usesConstReference(r), objId) def testModificationOfReference(self): - '''Tests if the identity of a reference argument is preserved when passing it to be altered in C++.''' + '''Tests if the identity of a reference argument is preserved when passing + it to be altered in C++.''' objId = 123 r1 = Reference(objId) r1.alterReferenceIdVirtual(r1) self.assertEqual(r1.objId(), objId * Reference.multiplier()) def testModificationOfReferenceCallingAVirtualIndirectly(self): - '''Tests if the identity of a reference argument is preserved when passing it to be altered in C++ through a method that calls a virtual method.''' + '''Tests if the identity of a reference argument is preserved when passing it + to be altered in C++ through a method that calls a virtual method.''' objId = 123 r1 = Reference(objId) r1.callAlterReferenceIdVirtual(r1) self.assertEqual(r1.objId(), objId * Reference.multiplier()) def testModificationOfReferenceCallingAReimplementedVirtualIndirectly(self): - '''Test if a Python override of a virtual method with a reference parameter called from C++ alters the argument properly.''' + '''Test if a Python override of a virtual method with a reference parameter + called from C++ alters the argument properly.''' objId = 123 r = Reference(objId) er = ExtendedReference() - result = er.callAlterReferenceIdVirtual(r) + result = er.callAlterReferenceIdVirtual(r) # noqa: F841 self.assertEqual(r.objId(), objId * er.multiplier) def testReimplementedVirtualMethodCallWithReferenceParameter(self): - '''Test if a Python override of a virtual method with a reference parameter is correctly called from C++.''' + '''Test if a Python override of a virtual method with a reference parameter + is correctly called from C++.''' inc = 9 objId = 123 r = Reference(objId) @@ -115,7 +93,8 @@ class ReferenceTest(unittest.TestCase): self.assertEqual(result, objId + inc + er.reference_inc) def testReimplementedVirtualMethodCallWithConstReferenceParameter(self): - '''Test if a Python override of a virtual method with a const reference parameter is correctly called from C++.''' + '''Test if a Python override of a virtual method with a const reference + parameter is correctly called from C++.''' inc = 9 objId = 123 r = Reference(objId) @@ -123,6 +102,6 @@ class ReferenceTest(unittest.TestCase): result = er.callUsesConstReferenceVirtual(r, inc) self.assertEqual(result, objId + inc + er.const_reference_inc) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/referencetopointer_test.py b/sources/shiboken6/tests/samplebinding/referencetopointer_test.py index 48893173b..942c7ea29 100644 --- a/sources/shiboken6/tests/samplebinding/referencetopointer_test.py +++ b/sources/shiboken6/tests/samplebinding/referencetopointer_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for a reference to pointer argument type.''' @@ -42,6 +15,7 @@ init_paths() from sample import VirtualMethods, Str + class ExtendedVirtualMethods(VirtualMethods): def __init__(self): VirtualMethods.__init__(self) @@ -99,6 +73,6 @@ class ReferenceToPointerTest(unittest.TestCase): self.assertTrue(ok) self.assertEqual(string, Str(obj.prefix + 'foo')) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/renaming_test.py b/sources/shiboken6/tests/samplebinding/renaming_test.py index a31dceb35..b08438ef3 100644 --- a/sources/shiboken6/tests/samplebinding/renaming_test.py +++ b/sources/shiboken6/tests/samplebinding/renaming_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2019 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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for renaming using target-lang-name attribute.''' @@ -43,6 +16,9 @@ init_paths() from sample import RenamedValue, RenamedUser +from shibokensupport.signature import get_signature + + class RenamingTest(unittest.TestCase): def test(self): '''Tests whether the C++ class ToBeRenamedValue renamed via attribute @@ -54,11 +30,10 @@ class RenamingTest(unittest.TestCase): "<class 'sample.RenamedValue'>") rename_user = RenamedUser() rename_user.useRenamedValue(renamed_value) - actual_signature = str(rename_user.useRenamedValue.__signature__) + actual_signature = str(get_signature(rename_user.useRenamedValue)) self.assertTrue(re.match(r"^\(self,\s*?v:\s*?sample.RenamedValue\)\s*?->\s*?None$", actual_signature)) - if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/return_null_test.py b/sources/shiboken6/tests/samplebinding/return_null_test.py index 3ca3f2731..2c4f07c65 100644 --- a/sources/shiboken6/tests/samplebinding/return_null_test.py +++ b/sources/shiboken6/tests/samplebinding/return_null_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test case for functions that could return a NULL pointer.''' @@ -40,7 +13,9 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import returnNullPrimitivePointer, returnNullValueTypePointer, returnNullObjectTypePointer +from sample import (returnNullPrimitivePointer, returnNullValueTypePointer, + returnNullObjectTypePointer) + class ReturnNullTest(unittest.TestCase): '''Test case for functions that could return a NULL pointer.''' @@ -60,6 +35,6 @@ class ReturnNullTest(unittest.TestCase): o = returnNullValueTypePointer() self.assertEqual(o, None) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/richcompare_test.py b/sources/shiboken6/tests/samplebinding/richcompare_test.py index 5a5fab646..3146d0faf 100644 --- a/sources/shiboken6/tests/samplebinding/richcompare_test.py +++ b/sources/shiboken6/tests/samplebinding/richcompare_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -38,7 +11,8 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import Expression + class TestRichCompare(unittest.TestCase): @@ -49,5 +23,6 @@ class TestRichCompare(unittest.TestCase): d = a + c < b + a self.assertEqual(d.toString(), "((2+(2+3))<(3+2))") + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/sample-binding.txt.in b/sources/shiboken6/tests/samplebinding/sample-binding.txt.in index 317f76f09..bcf9de90f 100644 --- a/sources/shiboken6/tests/samplebinding/sample-binding.txt.in +++ b/sources/shiboken6/tests/samplebinding/sample-binding.txt.in @@ -13,3 +13,4 @@ typesystem-path = @CMAKE_CURRENT_SOURCE_DIR@ enable-parent-ctor-heuristic use-isnull-as-nb_nonzero +lean-headers diff --git a/sources/shiboken6/tests/samplebinding/sample_test.py b/sources/shiboken6/tests/samplebinding/sample_test.py index a0d762c4a..19b2f708d 100644 --- a/sources/shiboken6/tests/samplebinding/sample_test.py +++ b/sources/shiboken6/tests/samplebinding/sample_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for libsample bindings module''' @@ -42,32 +15,10 @@ init_paths() import sample + class ModuleTest(unittest.TestCase): '''Test case for module and global functions''' - def testModuleMembers(self): - '''Test availability of classes, global functions and other members on binding''' - expected_members = set(['Abstract', 'Derived', 'Point', - 'ListUser', 'PairUser', 'MapUser', - 'gimmeComplexList', 'gimmeDouble', 'gimmeInt', - 'makeCString', 'multiplyPair', 'returnCString', - 'SampleNamespace', 'transmuteComplexIntoPoint', - 'transmutePointIntoComplex', 'sumComplexPair', - 'FirstThing', 'SecondThing', 'ThirdThing', - 'GlobalEnum', 'NoThing']) - self.assertTrue(expected_members.issubset(dir(sample))) - - def testAbstractPrintFormatEnum(self): - '''Test availability of PrintFormat enum from Abstract class''' - enum_members = set(['PrintFormat', 'Short', 'Verbose', - 'OnlyId', 'ClassNameAndId']) - self.assertTrue(enum_members.issubset(dir(sample.Abstract))) - - def testSampleNamespaceOptionEnum(self): - '''Test availability of Option enum from SampleNamespace namespace''' - enum_members = set(['Option', 'None_', 'RandomNumber', 'UnixTime']) - self.assertTrue(enum_members.issubset(dir(sample.SampleNamespace))) - def testAddedFunctionAtModuleLevel(self): '''Calls function added to module from type system description.''' str1 = 'Foo' @@ -80,6 +31,46 @@ class ModuleTest(unittest.TestCase): self.assertEqual(sample.countVarargs(1, 2), 1) self.assertEqual(sample.countVarargs(1, 2, 3, 'a', 'b', 4, (5, 6)), 6) + def testSampleComparisonOpInNamespace(self): + s1 = sample.sample.sample(10) + s2 = sample.sample.sample(10) + self.assertEqual(s1, s2) + + def testConstant(self): + self.assertEqual(sample.sample.INT_CONSTANT, 42) + + def testStringFunctions(self): + # Test plain ASCII, UCS1 and UCS4 encoding which have different + # representations in the PyUnicode objects. + for t1 in ["ascii", "Ümläut", "😀"]: + expected = t1 + t1 + self.assertEqual(sample.addStdStrings(t1, t1), expected) + self.assertEqual(sample.addStdWStrings(t1, t1), expected) + + def testNullPtrT(self): + sample.testNullPtrT(None) + self.assertRaises(TypeError, sample.testNullPtrT, 42) + + def testRValueRefsWithValueTypes(self): + """Passing value types by rvalue refs: For value types, nothing should + happen since the argument is copied in the call and the copy is + moved from.""" + polygon = sample.Polygon() + polygon.addPoint(sample.Point(1, 2)) + polygon.addPoint(sample.Point(3, 4)) + point_count = len(polygon.points()) + self.assertEqual(point_count, sample.takePolygon(polygon)) + + def testRValueRefsWithObjectTypes(self): + """Passing object types by rvalue refs: The underlying object should + be moved from.""" + o = sample.ObjectType() + object_name = "Name" + o.setObjectName(object_name) + self.assertEqual(len(object_name), sample.takeObjectType(o)) + # o should be moved from, name is now empty + self.assertEqual(len(o.objectName()), 0) + + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/samplebinding.pyproject b/sources/shiboken6/tests/samplebinding/samplebinding.pyproject new file mode 100644 index 000000000..ba6ba6f8f --- /dev/null +++ b/sources/shiboken6/tests/samplebinding/samplebinding.pyproject @@ -0,0 +1,131 @@ +{ + "files": ["__del___test.py", + "abstract_test.py", + "addedfunction_test.py", + "addedfunction_with_container_args_test.py", + "argumentmodifications_test.py", + "array_numpy_test.py", + "array_sequence_test.py", + "bug_554_test.py", + "bug_704_test.py", + "bytearray_test.py", + "child_return_test.py", + "class_fields_test.py", + "collector_test.py", + "complex_test.py", + "conversion_operator_test.py", + "copy_test.py", + "ctorconvrule_test.py", + "cyclic_test.py", + "date_test.py", + "decisor_test.py", + "delete_test.py", + "deprecated_test.py", + "derived_test.py", + "duck_punching_test.py", + "echo_test.py", + "enum_test.py", + "enumfromremovednamespace_test.py", + "event_loop_call_virtual_test.py", + "event_loop_thread_test.py", + "exception_test.py", + "filter_test.py", + "handleholder_test.py", + "hashabletype_test.py", + "ignorederefop_test.py", + "implicitconv_numerical_test.py", + "implicitconv_test.py", + "inheritanceandscope_test.py", + "injectcode_test.py", + "innerclass_test.py", + "intlist_test.py", + "intwrapper_test.py", + "invalid_virtual_return_test.py", + "keep_reference_test.py", + "list_test.py", + "lock_test.py", + "map_test.py", + "metaclass_test.py", + "mi_virtual_methods_test.py", + "mixed_mi_test.py", + "modelindex_test.py", + "modelview_test.py", + "modifications_test.py", + "modified_constructor_test.py", + "modifiedvirtualmethods_test.py", + "multi_cpp_inheritance_test.py", + "multiple_derived_test.py", + "namespace_test.py", + "newdivision_test.py", + "nondefaultctor_test.py", + "nontypetemplate_test.py", + "nonzero_test.py", + "numericaltypedef_test.py", + "numpy_test.py", + "objecttype_test.py", + "objecttype_with_named_args_test.py", + "objecttypebyvalue_test.py", + "objecttypelayout_test.py", + "objecttypeoperators_test.py", + "objecttypereferenceasvirtualmethodargument_test.py", + "oddbool_test.py", + "onlycopyclass_test.py", + "overflow_test.py", + "overload_sorting_test.py", + "overload_test.py", + "overloadwithdefault_test.py", + "ownership_argument_invalidation_test.py", + "ownership_delete_child_in_cpp_test.py", + "ownership_delete_child_in_python_test.py", + "ownership_delete_parent_test.py", + "ownership_invalidate_after_use_test.py", + "ownership_invalidate_child_test.py", + "ownership_invalidate_nonpolymorphic_test.py", + "ownership_invalidate_parent_test.py", + "ownership_reparenting_test.py", + "ownership_transference_test.py", + "pair_test.py", + "pen_test.py", + "point_test.py", + "pointerholder_test.py", + "pointerprimitivetype_test.py", + "pointf_test.py", + "primitivereferenceargument_test.py", + "privatector_test.py", + "privatedtor_test.py", + "protected_test.py", + "pstrlist_test.py", + "pystr_test.py", + "python_thread_test.py", + "receive_null_cstring_test.py", + "reference_test.py", + "referencetopointer_test.py", + "renaming_test.py", + "return_null_test.py", + "richcompare_test.py", + "sample_test.py", + "samplesnippets.cpp", + "simplefile_glue.cpp", + "simplefile_test.py", + "size_test.py", + "snakecase_test.py", + "static_nonstatic_methods_test.py", + "str_test.py", + "strlist_test.py", + "templateinheritingclass_test.py", + "time_test.py", + "transform_test.py", + "typeconverters_test.py", + "typedealloc_test.py", + "typedtordoublefree_test.py", + "typesystypedef_test.py", + "unsafe_parent_test.py", + "useraddedctor_test.py", + "virtualdtor_test.py", + "virtualmethods_test.py", + "visibilitychange_test.py", + "voidholder_test.py", + "weakref_test.py", + "writableclassdict_test.py", + "typesystem_sample.xml"] +} diff --git a/sources/shiboken6/tests/samplebinding/samplesnippets.cpp b/sources/shiboken6/tests/samplebinding/samplesnippets.cpp new file mode 100644 index 000000000..43e6b08de --- /dev/null +++ b/sources/shiboken6/tests/samplebinding/samplesnippets.cpp @@ -0,0 +1,54 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +// @snippet intwrapper_add_ints +extern "C" { +static PyObject *Sbk_IntWrapper_add_ints(PyObject * /* self */, PyObject *args) +{ + PyObject *result = nullptr; + if (PyTuple_Check(args) != 0 && PyTuple_Size(args) == 2) { + PyObject *arg1 = PyTuple_GetItem(args, 0); + PyObject *arg2 = PyTuple_GetItem(args, 1); + if (PyLong_Check(arg1) != 0 && PyLong_Check(arg2) != 0) + result = PyLong_FromLong(PyLong_AsLong(arg1) + PyLong_AsLong(arg2)); + } + if (result == nullptr) + PyErr_SetString(PyExc_TypeError, "expecting 2 ints"); + return result; +} +} +// @snippet intwrapper_add_ints + +// @snippet stdcomplex_floor +%PYARG_0 = PyFloat_FromDouble(std::floor(%CPPSELF.abs_value())); +// @snippet stdcomplex_floor + +// @snippet stdcomplex_ceil +%PYARG_0 = PyFloat_FromDouble(std::ceil(%CPPSELF.abs_value())); +// @snippet stdcomplex_ceil + +// @snippet stdcomplex_abs +%PYARG_0 = PyFloat_FromDouble(%CPPSELF.abs_value()); +// @snippet stdcomplex_abs + +// @snippet stdcomplex_pow +%RETURN_TYPE %0 = %CPPSELF.pow(%1); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); +// @snippet stdcomplex_pow + +// @snippet size_char_ct +// Convert a string "{width}x{height}" specification +{ + double width = -1; + double height = -1; + const std::string s = %1; + const auto pos = s.find('x'); + if (pos != std::string::npos) { + std::istringstream wstr(s.substr(0, pos)); + wstr >> width; + std::istringstream hstr(s.substr(pos + 1, s.size() - pos - 1)); + hstr >> height; + } + %0 = new %TYPE(width, height); +} +// @snippet size_char_ct diff --git a/sources/shiboken6/tests/samplebinding/simplefile_glue.cpp b/sources/shiboken6/tests/samplebinding/simplefile_glue.cpp index bccd51534..76c0cfaf2 100644 --- a/sources/shiboken6/tests/samplebinding/simplefile_glue.cpp +++ b/sources/shiboken6/tests/samplebinding/simplefile_glue.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 if (!%CPPSELF.%FUNCTION_NAME()) { PyObject* error_msg = PyBytes_FromFormat( diff --git a/sources/shiboken6/tests/samplebinding/simplefile_test.py b/sources/shiboken6/tests/samplebinding/simplefile_test.py index 1f5561f77..55c894a35 100644 --- a/sources/shiboken6/tests/samplebinding/simplefile_test.py +++ b/sources/shiboken6/tests/samplebinding/simplefile_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for SimpleFile class''' @@ -42,6 +15,7 @@ init_paths() from sample import SimpleFile + class SimpleFileTest(unittest.TestCase): '''Test cases for SimpleFile class.''' @@ -81,6 +55,6 @@ class SimpleFileTest(unittest.TestCase): self.assertRaises(IOError, f.open) self.assertEqual(f.size(), 0) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/size_test.py b/sources/shiboken6/tests/samplebinding/size_test.py index 4df438e2b..069ce59b3 100644 --- a/sources/shiboken6/tests/samplebinding/size_test.py +++ b/sources/shiboken6/tests/samplebinding/size_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for operator overloads on Size class''' @@ -42,6 +15,7 @@ init_paths() from sample import Size + class PointTest(unittest.TestCase): '''Test case for Size class, including operator overloads.''' @@ -121,6 +95,6 @@ class PointTest(unittest.TestCase): self.assertTrue(s1 > s2) self.assertFalse(s2 > s1) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/snakecase_test.py b/sources/shiboken6/tests/samplebinding/snakecase_test.py index 2147b2c5b..a1538796a 100644 --- a/sources/shiboken6/tests/samplebinding/snakecase_test.py +++ b/sources/shiboken6/tests/samplebinding/snakecase_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- 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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for snake case generation''' diff --git a/sources/shiboken6/tests/samplebinding/static_nonstatic_methods_test.py b/sources/shiboken6/tests/samplebinding/static_nonstatic_methods_test.py index 200b0e4c0..cf0889299 100644 --- a/sources/shiboken6/tests/samplebinding/static_nonstatic_methods_test.py +++ b/sources/shiboken6/tests/samplebinding/static_nonstatic_methods_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for overloads involving static and non-static versions of a method.''' @@ -42,16 +15,20 @@ init_paths() from sample import SimpleFile + class SimpleFile2 (SimpleFile): def exists(self): return "Mooo" + class SimpleFile3 (SimpleFile): pass + class SimpleFile4 (SimpleFile): exists = 5 + class StaticNonStaticMethodsTest(unittest.TestCase): '''Test cases for overloads involving static and non-static versions of a method.''' @@ -106,9 +83,9 @@ class StaticNonStaticMethodsTest(unittest.TestCase): def testDuckPunchingStaticNonStaticMethod(self): f = SimpleFile(os.fspath(self.existing_filename)) - f.exists = lambda : "Meee" + f.exists = lambda: "Meee" self.assertEqual(f.exists(), "Meee") + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/stdcomplex_test.py b/sources/shiboken6/tests/samplebinding/stdcomplex_test.py new file mode 100644 index 000000000..0caa9764d --- /dev/null +++ b/sources/shiboken6/tests/samplebinding/stdcomplex_test.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +'''Test cases for StdComplex class''' + +import os +import math +import sys +import unittest + +from pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from shiboken_paths import init_paths +init_paths() + +from sample import StdComplex + + +REAL = 5.0 +IMAG = 2.3 + + +class StdComplexTest(unittest.TestCase): + '''Test case for StdComplex class, exercising esoteric number + protocols (Py_nb_). For standard number protocols, see Point.''' + + def testConversion(self): + pt = StdComplex(REAL, IMAG) + self.assertEqual(int(pt), int(round(pt.abs_value()))) + self.assertEqual(float(pt), pt.abs_value()) + + def testAbs(self): + pt = StdComplex(REAL, IMAG) + self.assertEqual(abs(pt), pt.abs_value()) + + def testPow(self): + '''Compare pow() function to builtin Python type.''' + pt = StdComplex(REAL, IMAG) + result = pow(pt, StdComplex(2.0, 0)) + py_pt = complex(REAL, IMAG) + py_result = pow(py_pt, complex(2.0, 0)) + self.assertAlmostEqual(result.real(), py_result.real) + self.assertAlmostEqual(result.imag(), py_result.imag) + + def testFloor(self): + pt = StdComplex(REAL, IMAG) + self.assertEqual(math.floor(pt), math.floor(pt.abs_value())) + + def testCeil(self): + pt = StdComplex(REAL, IMAG) + self.assertEqual(math.ceil(pt), math.ceil(pt.abs_value())) + + def testPlusOperator(self): + '''Test StdComplex class + operator.''' + pt1 = StdComplex(REAL, IMAG) + pt2 = StdComplex(0.5, 3.2) + self.assertEqual(pt1 + pt2, StdComplex(REAL + 0.5, IMAG + 3.2)) + + def testEqualOperator(self): + '''Test StdComplex class == operator.''' + pt1 = StdComplex(REAL, IMAG) + pt2 = StdComplex(REAL, IMAG) + pt3 = StdComplex(0.5, 3.2) + self.assertTrue(pt1 == pt1) + self.assertTrue(pt1 == pt2) + self.assertFalse(pt1 == pt3) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/str_test.py b/sources/shiboken6/tests/samplebinding/str_test.py index a2c092bb8..c06fd6428 100644 --- a/sources/shiboken6/tests/samplebinding/str_test.py +++ b/sources/shiboken6/tests/samplebinding/str_test.py @@ -1,35 +1,9 @@ #!/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$ -## -############################################################################# - -'''Test cases for a method that receives a reference to class that is implicitly convertible from a Python native type.''' +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +'''Test cases for a method that receives a reference to class that is implicitly + convertible from a Python native type.''' import os import sys @@ -42,6 +16,7 @@ init_paths() from sample import Str + class StrTest(unittest.TestCase): '''Test cases for thr Str class.''' @@ -58,39 +33,39 @@ class StrTest(unittest.TestCase): self.assertEqual(str(s1), 'This is Sparta!') def testPassPythonTypeImplictlyConvertibleToAClassUsedAsReference(self): - '''Test passing a Python class implicitly convertible to a wrapped class that is expected to be passed as reference.''' + '''Test passing a Python class implicitly convertible to a wrapped class + that is expected to be passed as reference.''' s1 = Str('This is %VAR!').arg('Athens') self.assertEqual(str(s1), 'This is Athens!') def testSequenceOperators(self): s1 = Str("abcdef") - self.assertEqual(len(s1), 6); - self.assertEqual(len(Str()), 0); + self.assertEqual(len(s1), 6) + self.assertEqual(len(Str()), 0) # getitem - self.assertEqual(s1[0], "a"); - self.assertEqual(s1[1], "b"); - self.assertEqual(s1[2], "c"); - self.assertEqual(s1[3], "d"); - self.assertEqual(s1[4], "e"); - self.assertEqual(s1[5], "f"); - self.assertEqual(s1[-1], "f"); - self.assertEqual(s1[-2], "e"); + self.assertEqual(s1[0], "a") + self.assertEqual(s1[1], "b") + self.assertEqual(s1[2], "c") + self.assertEqual(s1[3], "d") + self.assertEqual(s1[4], "e") + self.assertEqual(s1[5], "f") + self.assertEqual(s1[-1], "f") + self.assertEqual(s1[-2], "e") self.assertRaises(TypeError, s1.__getitem__, 6) # setitem s1[0] = 'A' s1[1] = 'B' - self.assertEqual(s1[0], 'A'); - self.assertEqual(s1[1], 'B'); + self.assertEqual(s1[0], 'A') + self.assertEqual(s1[1], 'B') self.assertRaises(TypeError, s1.__setitem__(6, 67)) def testReverseOperator(self): s1 = Str("hello") - n1 = 2 - self.assertEqual(s1+2, "hello2") - self.assertEqual(2+s1, "2hello") + self.assertEqual(s1 + 2, "hello2") + self.assertEqual(2 + s1, "2hello") def testToIntError(self): self.assertEqual(Str('Z').toInt(), (0, False)) @@ -117,6 +92,6 @@ class StrTest(unittest.TestCase): self.assertEqual(val, int(str(hexa), 16)) self.assertEqual(hexa.toInt(), (0, False)) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/strlist_test.py b/sources/shiboken6/tests/samplebinding/strlist_test.py index c3eb02b8e..2bfb80b67 100644 --- a/sources/shiboken6/tests/samplebinding/strlist_test.py +++ b/sources/shiboken6/tests/samplebinding/strlist_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for StrList class that inherits from std::list<Str>.''' @@ -42,6 +15,7 @@ init_paths() from sample import Str, StrList + class StrListTest(unittest.TestCase): '''Test cases for StrList class that inherits from std::list<Str>.''' @@ -115,5 +89,6 @@ class StrListTest(unittest.TestCase): self.assertEqual(len(sl), 2) self.assertEqual(sl, (Str('Foo'), 'Bar')) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/templateinheritingclass_test.py b/sources/shiboken6/tests/samplebinding/templateinheritingclass_test.py index f0bb1f762..11279c7ec 100644 --- a/sources/shiboken6/tests/samplebinding/templateinheritingclass_test.py +++ b/sources/shiboken6/tests/samplebinding/templateinheritingclass_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -41,7 +14,8 @@ init_paths() from sample import Photon '''This tests classes that inherit from template classes, -simulating a situation found in Qt's phonon module.''' + simulating a situation found in Qt's phonon module.''' + class TemplateInheritingClassTest(unittest.TestCase): def testClassBasics(self): @@ -84,5 +58,6 @@ class TemplateInheritingClassTest(unittest.TestCase): self.assertEqual(obj2, obj2.passPointerThrough(obj2)) self.assertRaises(TypeError, obj1.passPointerThrough, obj2) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/time_test.py b/sources/shiboken6/tests/samplebinding/time_test.py index 5552457ab..6283a6744 100644 --- a/sources/shiboken6/tests/samplebinding/time_test.py +++ b/sources/shiboken6/tests/samplebinding/time_test.py @@ -1,37 +1,9 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for constructor and method signature decisor on Time class.''' -import sys import os import sys import unittest @@ -44,6 +16,7 @@ import datetime from sample import Time, ImplicitConv, ObjectType + class TimeTest(unittest.TestCase): '''Test cases for constructor and method signature decisor on Time class. The constructor and one method have these signatures: CTORMETHOD() and @@ -131,6 +104,7 @@ class TimeTest(unittest.TestCase): result = time.somethingCompletelyDifferent(1, 2, ImplicitConv.CtorOne) self.assertEqual(result, Time.ThreeArgs) + # PYSIDE-1436: These tests crash at shutdown due to `assert(Not)?Equal`. def testCompareWithPythonTime(self): time = Time(12, 32, 5) py = datetime.time(12, 32, 5) @@ -141,6 +115,6 @@ class TimeTest(unittest.TestCase): py = datetime.time(12, 32, 5) self.assertNotEqual(time, py) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/transform_test.py b/sources/shiboken6/tests/samplebinding/transform_test.py index 5d55d9d77..7dfd18a4a 100644 --- a/sources/shiboken6/tests/samplebinding/transform_test.py +++ b/sources/shiboken6/tests/samplebinding/transform_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for argument modification with more than nine arguments.''' @@ -42,6 +15,7 @@ init_paths() from sample import Point, applyHomogeneousTransform + class TransformTest(unittest.TestCase): '''Test cases for modifying a function with > 9 arguments.''' @@ -59,5 +33,6 @@ class TransformTest(unittest.TestCase): r = applyHomogeneousTransform(p, 1, 0, 0, 0, 1, 0, 0, 0, 0) self.assertTrue(r is None) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/typeconverters_test.py b/sources/shiboken6/tests/samplebinding/typeconverters_test.py index 141da0860..987ba6dfd 100644 --- a/sources/shiboken6/tests/samplebinding/typeconverters_test.py +++ b/sources/shiboken6/tests/samplebinding/typeconverters_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Tests various usages of the type converters.''' @@ -42,6 +15,7 @@ init_paths() import sample + class GetPythonTypeByNameTest(unittest.TestCase): '''Uses an added function with inject code that uses the libshiboken @@ -186,12 +160,31 @@ class StringBasedConversionTest(unittest.TestCase): self.assertTrue(len(result), 1) self.assertTrue(lst, result[0]) + +class PrimitiveConversionTest(unittest.TestCase): + def testCppPrimitiveType(self): integers = (12, 34) result = sample.convertIntegersToCppAndThenToPython(integers[0], integers[1]) for orig, new in zip(integers, result): self.assertEqual(orig, new) + def testLargeIntAsFloat(self): + """PYSIDE-2417: When passing an int to a function taking float, + a 64bit conversion should be done.""" + point = sample.PointF(1, 2) + large_int = 2**31 + 2 + point.setX(large_int) + self.assertEqual(round(point.x()), large_int) + + def testUnsignedLongLongAsFloat(self): + """PYSIDE-2652: When passing an unsigned long long to a function taking float, + an unsigned 64bit conversion should be done.""" + point = sample.PointF(1, 2) + large_int = 2**63 + point.setX(large_int) + self.assertEqual(round(point.x()), large_int) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/typedealloc_test.py b/sources/shiboken6/tests/samplebinding/typedealloc_test.py index 32a15e300..ce881e802 100644 --- a/sources/shiboken6/tests/samplebinding/typedealloc_test.py +++ b/sources/shiboken6/tests/samplebinding/typedealloc_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test deallocation of type extended in Python.''' @@ -52,18 +25,24 @@ class TypeDeallocTest(unittest.TestCase): def tearDown(self): del self.called + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() def callback(self, *args): self.called = True def testScopeEnd(self): ref = None + def scope(): + class Ext(Point): pass - o = Ext() + + o = Ext() # noqa: F841 global ref ref = weakref.ref(Ext, self.callback) + scope() gc.collect() self.assertTrue(self.called) @@ -71,7 +50,7 @@ class TypeDeallocTest(unittest.TestCase): def testDeleteType(self): class Ext(Point): pass - ref = weakref.ref(Ext, self.callback) + ref = weakref.ref(Ext, self.callback) # noqa: F841 del Ext gc.collect() self.assertTrue(self.called) @@ -79,4 +58,3 @@ class TypeDeallocTest(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/typedtordoublefree_test.py b/sources/shiboken6/tests/samplebinding/typedtordoublefree_test.py index 983633a7f..ab8e535b5 100644 --- a/sources/shiboken6/tests/samplebinding/typedtordoublefree_test.py +++ b/sources/shiboken6/tests/samplebinding/typedtordoublefree_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -39,6 +12,7 @@ from shiboken_paths import init_paths init_paths() from sample import ObjectType + class TestTypeDestructorDoubleFree(unittest.TestCase): def testTypeDestructorDoubleFree(self): '''Causes the type destructors of two derived classes to be called.''' @@ -49,13 +23,16 @@ class TestTypeDestructorDoubleFree(unittest.TestCase): obj = ExtObj1() child = ObjectType(parent=obj) self.assertEqual(obj.takeChild(child), child) + class ExtObj2(ObjectType): def __init__(self): ObjectType.__init__(self) + obj = ExtObj2() child = ObjectType(parent=obj) self.assertEqual(obj.takeChild(child), child) scope() + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/typesystem_sample.xml b/sources/shiboken6/tests/samplebinding/typesystem_sample.xml index a8b7b3b11..e315e599e 100644 --- a/sources/shiboken6/tests/samplebinding/typesystem_sample.xml +++ b/sources/shiboken6/tests/samplebinding/typesystem_sample.xml @@ -1,34 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <typesystem package="sample"> - <suppress-warning text="Duplicate type entry: 'sample'" /> - <suppress-warning text="Duplicate type entry: 'SampleNamespace'" /> - - <custom-type name="str"/> - <custom-type name="PyBytes"/> - <custom-type name="PyDate"/> - <custom-type name="PyObject"/> - <custom-type name="PyUnicode"/> - - <primitive-type name="bool"/> - <primitive-type name="double"/> - <primitive-type name="real"/> - <primitive-type name="int"/> - <primitive-type name="short"/> - <primitive-type name="unsigned short"/> - <primitive-type name="ushort"/> - <primitive-type name="unsigned int" /> - <primitive-type name="signed int" /> - <primitive-type name="char"/> - <primitive-type name="unsigned char"/> - <primitive-type name="long"/> - <primitive-type name="unsigned long"/> - <primitive-type name="long long"/> - <primitive-type name="unsigned long long"/> - <primitive-type name="std::string"/> - <primitive-type name="std::string_view" view-on="std::string"/> <primitive-type name="ObjectType::Identifier"/> + <primitive-type name="std::nullptr_t"/> - <primitive-type name="Foo::HANDLE" target-lang-api-name="PyLong"/> + <primitive-type name="Foo::SAMPLE_HANDLE" target-lang-api-name="PyLong"/> <primitive-type name="std::size_t" target-lang-api-name="PyLong"> <conversion-rule> @@ -48,10 +23,10 @@ if (!PySequence_Check(pyIn) || !(PySequence_Size(pyIn) == 2)) return false; Shiboken::AutoDecRef pyReal(PySequence_GetItem(pyIn, 0)); - if (!SbkNumber_Check(pyReal)) + if (!PyNumber_Check(pyReal)) return false; Shiboken::AutoDecRef pyImag(PySequence_GetItem(pyIn, 1)); - if (!SbkNumber_Check(pyImag)) + if (!PyNumber_Check(pyImag)) return false; return true; } @@ -96,7 +71,7 @@ </conversion-rule> </primitive-type> - <primitive-type name="HANDLE" target-lang-api-name="PyComplex"> + <primitive-type name="SAMPLE_HANDLE" target-lang-api-name="PyComplex"> <include file-name="handle.h" location="local"/> <conversion-rule> <native-to-target> @@ -106,6 +81,7 @@ </native-to-target> <target-to-native> <add-conversion type="PyNone"> + SBK_UNUSED(%in) %out = 0; </add-conversion> <add-conversion check="checkPyCapsuleOrPyCObject(%in)" type="PyObject"> @@ -132,7 +108,7 @@ <target-to-native> <add-conversion check="checkPyCapsuleOrPyCObject(%in)" type="PyObject"> void *ptr = PyCapsule_GetPointer(%in, nullptr); - %out = *((%OUTTYPE*)ptr); + %out = *reinterpret_cast<%OUTTYPE*>(ptr); </add-conversion> </target-to-native> </conversion-rule> @@ -174,6 +150,9 @@ <add-function signature="operator==(const ComparisonTester&)" return-type="bool"/> <add-function signature="operator!=(const ComparisonTester&)" return-type="bool"/> </value-type> + <value-type name="SpaceshipComparisonTester"> + <enum-type name="Enabled"/> + </value-type> <primitive-type name="PStr"> <include file-name="str.h" location="global"/> @@ -187,6 +166,7 @@ %out = %OUTTYPE(str); </add-conversion> <add-conversion type="Py_None"> + SBK_UNUSED(%in) %out = %OUTTYPE(); </add-conversion> </target-to-native> @@ -234,11 +214,11 @@ <include file-name="strlist.h" location="global"/> <conversion-rule> <native-to-target> - PyObject* %out = PyList_New((int) %in.size()); - PStrList::const_iterator it = %in.begin(); - for (int idx = 0; it != %in.end(); ++it, ++idx) { - PStr cppItem(*it); - PyList_SET_ITEM(%out, idx, %CONVERTTOPYTHON[PStr](cppItem)); + PyObject *%out = PyList_New(Py_ssize_t(%in.size())); + Py_ssize_t idx = 0; + for (const auto &s : %in) { + PStr cppItem(s); + PyList_SET_ITEM(%out, idx++, %CONVERTTOPYTHON[PStr](cppItem)); } return %out; </native-to-target> @@ -275,6 +255,7 @@ <add-function signature="getPythonType(const char*)" return-type="PyObject"> <inject-code class="target" position="beginning"> + SBK_UNUSED(self) %PYARG_0 = (PyObject*) Shiboken::Conversions::getPythonTypeObject(%1); if (!%PYARG_0) %PYARG_0 = Py_None; @@ -370,24 +351,7 @@ </inject-code> </add-function> - <container-type name="std::pair" type="pair"> - <include file-name="utility" location="global"/> - <conversion-rule> - <native-to-target> - PyObject* %out = PyTuple_New(2); - PyTuple_SET_ITEM(%out, 0, %CONVERTTOPYTHON[%INTYPE_0](%in.first)); - PyTuple_SET_ITEM(%out, 1, %CONVERTTOPYTHON[%INTYPE_1](%in.second)); - return %out; - </native-to-target> - <target-to-native> - <add-conversion type="PySequence"> - %out.first = %CONVERTTOCPP[%OUTTYPE_0](PySequence_Fast_GET_ITEM(%in, 0)); - %out.second = %CONVERTTOCPP[%OUTTYPE_1](PySequence_Fast_GET_ITEM(%in, 1)); - </add-conversion> - </target-to-native> - </conversion-rule> - </container-type> - <template name="cpplist_to_pylist_convertion"> + <template name="cpp_indexed_list_to_pylist_conversion"> PyObject *%out = PyList_New(Py_ssize_t(%in.size())); Py_ssize_t idx = 0; for (auto it = %in.cbegin(), end = %in.cend(); it != end; ++it, ++idx) { @@ -396,70 +360,19 @@ } return %out; </template> - <template name="pyseq_to_cpplist_convertion"> - Shiboken::AutoDecRef seq(PySequence_Fast(%in, 0)); - const Py_ssize_t size = PySequence_Fast_GET_SIZE(seq.object()); - for (Py_ssize_t i = 0; i < size; ++i) { - PyObject* pyItem = PySequence_Fast_GET_ITEM(seq.object(), i); - %OUTTYPE_0 cppItem = %CONVERTTOCPP[%OUTTYPE_0](pyItem); - %out.push_back(cppItem); - } - </template> - <container-type name="std::list" type="list"> - <include file-name="list" location="global"/> - <conversion-rule> - <native-to-target> - <insert-template name="cpplist_to_pylist_convertion"/> - </native-to-target> - <target-to-native> - <add-conversion type="PySequence"> - <insert-template name="pyseq_to_cpplist_convertion"/> - </add-conversion> - </target-to-native> - </conversion-rule> - </container-type> <container-type name="List" type="list"> <include file-name="list" location="global"/> <conversion-rule> <native-to-target> - <insert-template name="cpplist_to_pylist_convertion"/> + <insert-template name="cpp_indexed_list_to_pylist_conversion"/> </native-to-target> <target-to-native> <add-conversion type="PySequence"> - <insert-template name="pyseq_to_cpplist_convertion"/> + <insert-template name="shiboken_conversion_pyiterable_to_cppsequentialcontainer"/> </add-conversion> </target-to-native> </conversion-rule> </container-type> - <container-type name="std::map" type="map"> - <include file-name="map" location="global"/> - <conversion-rule> - <native-to-target> - PyObject* %out = PyDict_New(); - for (auto it = %in.cbegin(), end = %in.cend(); it != end; ++it) { - %INTYPE_0 key = it->first; - %INTYPE_1 value = it->second; - PyDict_SetItem(%out, - %CONVERTTOPYTHON[%INTYPE_0](key), - %CONVERTTOPYTHON[%INTYPE_1](value)); - } - return %out; - </native-to-target> - <target-to-native> - <add-conversion type="PyDict"> - PyObject* key; - PyObject* value; - Py_ssize_t pos = 0; - while (PyDict_Next(%in, &pos, &key, &value)) { - %OUTTYPE_0 cppKey = %CONVERTTOCPP[%OUTTYPE_0](key); - %OUTTYPE_1 cppValue = %CONVERTTOCPP[%OUTTYPE_1](value); - %out.insert({cppKey, cppValue}); - } - </add-conversion> - </target-to-native> - </conversion-rule> - </container-type> - <add-function signature="cacheSize()" return-type="int"> <inject-code class="target"> %RETURN_TYPE %0 = Shiboken::BindingManager::instance().getAllPyObjects().size(); @@ -484,6 +397,7 @@ <function signature="returnNullValueTypePointer()" /> <function signature="returnNullObjectTypePointer()" /> <function signature="acceptInt(int)" /> + <function signature="acceptIntReturnPtr(int)"/> <function signature="acceptUInt(unsigned int)" /> <function signature="acceptLong(long)" /> <function signature="acceptULong(unsigned long)" /> @@ -502,6 +416,11 @@ <function signature="returnCString()" /> <function signature="overloadedFunc(double)" /> <function signature="overloadedFunc(int)" /> + <function signature="addStdStrings(const std::string&, const std::string&)"/> + <function signature="addStdWStrings(const std::wstring&, const std::wstring&)"/> + <function signature="testNullPtrT(std::nullptr_t)"/> + <function signature="takePolygon(Polygon&&)"/> + <function signature="takeObjectType(ObjectType&&)"/> <value-type name="ArrayModifyTest"> <modify-function signature="sumIntArray(int, int*)"> @@ -510,7 +429,7 @@ </value-type> <value-type name="ClassWithFunctionPointer"> - <suppress-warning text="skipping function 'ClassWithFunctionPointer::callFunctionPointer', unmatched parameter type 'void (*)(void*)'" /> + <suppress-warning text="^skipping public function 'void ClassWithFunctionPointer::callFunctionPointer.*$" /> </value-type> <value-type name="IntArray" generate="no"/> @@ -538,6 +457,10 @@ <enum-type identified-by-value="AnonymousGlobalEnum_Value0"/> <namespace-type name="SampleNamespace"> + <namespace-type name="InlineNamespace"> + <value-type name="ClassWithinInlineNamespace"/> + <enum-type name="EnumWithinInlineNamespace"/> + </namespace-type> <enum-type name="Option"/> <enum-type name="InValue"/> <enum-type name="OutValue"/> @@ -562,8 +485,12 @@ <modify-function signature="doSomethingWithArray(const unsigned char*, unsigned int, const char*)"> <modify-argument index="1"> <replace-type modified-type="const char*"/> - <conversion-rule class="native"> - const unsigned char* %out = reinterpret_cast<const unsigned char*>(Shiboken::String::toCString(%PYARG_1)); + <conversion-rule> + <target-to-native> + <add-conversion> + const unsigned char* %out = reinterpret_cast<const unsigned char*>(Shiboken::String::toCString(%PYARG_1)); + </add-conversion> + </target-to-native> </conversion-rule> </modify-argument> <modify-argument index="2"> @@ -644,6 +571,14 @@ <modify-function signature="hideFunction(HideType*)" remove="all"/> <modify-field name="toBeRenamedField" rename="renamedField"/> <modify-field name="readOnlyField" write="false"/> + <modify-function signature="virtualWithOutParameter(int&)const"> + <inject-code class="shell" position="override"> + x = virtualWithOutParameterPyOverride(gil, pyOverride.object()); + return; + </inject-code> + </modify-function> + <add-function signature="virtualWithOutParameterPyOverride()" + return-type="int" python-override="true"/> </object-type> <object-type name="Derived" polymorphic-id-expression="%1->type() == Derived::TpDerived"> @@ -665,7 +600,7 @@ </modify-function> </object-type> - <object-type name="ObjectType" hash-function="objectTypeHash"> + <object-type name="ObjectType" hash-function="objectTypeHash" parent-management="yes"> <modify-function signature="deprecatedFunction()" deprecated="yes" /> <!-- rename function to avoid Python signature conflit --> <modify-function signature="setObject(const Null&)" rename="setNullObject" /> @@ -706,8 +641,8 @@ // CHECKTYPE and ISCONVERTIBLE are used here for test purposes, don't change them. if (!%CHECKTYPE[ObjectTypeLayout*](layout) && !%ISCONVERTIBLE[ObjectTypeLayout*](layout)) return; - // %CHECKTYPE[ObjectTypeLayout*](layout) - // %ISCONVERTIBLE[ObjectTypeLayout*](layout) + /* %CHECKTYPE[ObjectTypeLayout*](layout) */ + /* %ISCONVERTIBLE[ObjectTypeLayout*](layout) */ ObjectTypeLayout* var; var = %CONVERTTOCPP[ObjectTypeLayout*](layout); // TODO-CONVERTER: erase this @@ -794,7 +729,7 @@ </modify-function> </object-type> - <value-type name="ObjectTypeHolder"/> + <object-type name="ObjectTypeHolder"/> <value-type name="OnlyCopy"/> <value-type name="FriendOfOnlyCopy"/> @@ -1187,14 +1122,14 @@ <modify-argument index="1"> <remove-argument/> <conversion-rule class="native"> - int %out = PySequence_Size(%PYARG_1); + const auto %out = PySequence_Size(%PYARG_1); </conversion-rule> </modify-argument> <modify-argument index="2"> <replace-type modified-type="PySequence" /> <conversion-rule class="native"> Shiboken::AutoArrayPointer<Point> %out(%1); - for (int i = 0; i < %1; ++i) + for (Py_ssize_t i = 0; i < %1; ++i) %out[i] = %CONVERTTOCPP[Point](PySequence_Fast_GET_ITEM(%PYARG_1, i)); </conversion-rule> </modify-argument> @@ -1237,14 +1172,18 @@ </modify-argument> <modify-argument index="return"> <replace-type modified-type="PySequence"/> - <conversion-rule class="native"> - Shiboken::AutoDecRef _py_ok_(PySequence_GetItem(%PYARG_0, 0)); - Shiboken::AutoDecRef _py_ret_(PySequence_GetItem(%PYARG_0, 1)); - *%2 = %CONVERTTOCPP[bool](_py_ok_); - %RETURN_TYPE %out = %CONVERTTOCPP[%RETURN_TYPE](_py_ret_); - </conversion-rule> - <conversion-rule class="target"> - <insert-template name="differenceOfPointCoordinates_returnTarget"/> + <conversion-rule> + <target-to-native> + <add-conversion> + Shiboken::AutoDecRef _py_ok_(PySequence_GetItem(%PYARG_0, 0)); + Shiboken::AutoDecRef _py_ret_(PySequence_GetItem(%PYARG_0, 1)); + *%2 = %CONVERTTOCPP[bool](_py_ok_); + %RETURN_TYPE %out = %CONVERTTOCPP[%RETURN_TYPE](_py_ret_); + </add-conversion> + </target-to-native> + <native-to-target> + <insert-template name="differenceOfPointCoordinates_returnTarget"/> + </native-to-target> </conversion-rule> </modify-argument> </modify-function> @@ -1374,7 +1313,7 @@ <replace-default-expression with="3000"/> </modify-argument> <inject-code class="native" position="beginning"> - PyObject* new_arg0 = PyInt_FromLong(PyInt_AS_LONG(%PYARG_1) - %2); + PyObject* new_arg0 = PyLong_FromLong(PyLong_AS_LONG(%PYARG_1) - %2); Py_DECREF(%PYARG_1); %PYARG_1 = new_arg0; </inject-code> @@ -1445,13 +1384,13 @@ PyTuple_SET_ITEM(%PYARG_0, 3, %CONVERTTOPYTHON[int](a3)); </template> <template name="fix_native_return_int*,int*,int*,int*"> - PyObject* _obj = %PYARG_0.object(); + PyObject* _obj = %PYARG_0; if (!PySequence_Check(_obj) || PySequence_Fast_GET_SIZE(_obj) != 4 - || !SbkNumber_Check(PySequence_Fast_GET_ITEM(_obj, 0)) - || !SbkNumber_Check(PySequence_Fast_GET_ITEM(_obj, 1)) - || !SbkNumber_Check(PySequence_Fast_GET_ITEM(_obj, 2)) - || !SbkNumber_Check(PySequence_Fast_GET_ITEM(_obj, 3))) { + || !PyNumber_Check(PySequence_Fast_GET_ITEM(_obj, 0)) + || !PyNumber_Check(PySequence_Fast_GET_ITEM(_obj, 1)) + || !PyNumber_Check(PySequence_Fast_GET_ITEM(_obj, 2)) + || !PyNumber_Check(PySequence_Fast_GET_ITEM(_obj, 3))) { PyErr_SetString(PyExc_TypeError, "Sequence of 4 numbers expected"); } else { *%1 = %CONVERTTOCPP[int](PySequence_Fast_GET_ITEM(_obj, 0)); @@ -1461,7 +1400,7 @@ } </template> <modify-function signature="getMargins(int*,int*,int*,int*)const"> - <modify-argument index="0"> + <modify-argument index="return" pyi-type="Tuple[int, int, int, int]"> <replace-type modified-type="PyObject" /> </modify-argument> <modify-argument index="1"> @@ -1638,15 +1577,15 @@ <modify-argument index="1"> <remove-argument/> <conversion-rule class="native"> - int %out = PySequence_Size(%PYARG_1); + const auto %out = PySequence_Size(%PYARG_1); </conversion-rule> </modify-argument> <modify-argument index="2"> <replace-type modified-type="PySequence"/> <conversion-rule class="native"> - int numItems = PySequence_Size(%PYARG_1); + const auto numItems = PySequence_Size(%PYARG_1); Shiboken::AutoArrayPointer<int> %out(numItems); - for (int i = 0; i < numItems; ++i) { + for (Py_ssize_t i = 0; i < numItems; ++i) { if (%CHECKTYPE[int](PySequence_Fast_GET_ITEM(%PYARG_1, i))) %out[i] = %CONVERTTOCPP[int](PySequence_Fast_GET_ITEM(%PYARG_1, i)); else if (%ISCONVERTIBLE[int](PySequence_Fast_GET_ITEM(%PYARG_1, i))) @@ -1938,6 +1877,7 @@ %PYARG_0 = Py_False; else %PYARG_0 = Py_True; + Py_INCREF(%PYARG_0); } </inject-code> </add-function> @@ -1955,19 +1895,20 @@ %PYARG_0 = Py_True; else %PYARG_0 = Py_False; + Py_INCREF(%PYARG_0); } </inject-code> </add-function> </value-type> <value-type name="Size"> + <extra-includes> + <include file-name="string" location="global"/> + <include file-name="sstream" location="global"/> + </extra-includes> <add-function signature="Size(const char*)"> - <inject-code class="target" position="beginning"> - %0 = new %TYPE(); - </inject-code> - <inject-code class="target" position="end"> - Shiboken::AutoDecRef result(PyObject_CallMethod(%PYSELF, const_cast<char*>("setHeight"), const_cast<char*>("i"), 2)); - </inject-code> + <inject-code class="target" position="beginning" + file="samplesnippets.cpp" snippet="size_char_ct"/> </add-function> </value-type> <value-type name="SizeF"/> @@ -2018,6 +1959,9 @@ } } } + // PySIDE-1735: Enums are now implemented in Python, so we need to avoid asserts. + if (PyErr_Occurred()) + break; const char** %out = 0; </conversion-rule> </modify-argument> @@ -2066,7 +2010,12 @@ <object-type name="Collector" stream="yes"/> - <value-type name="IntWrapper" /> + <value-type name="IntWrapper"> + <inject-code class="native" position="beginning" + file="samplesnippets.cpp" snippet="intwrapper_add_ints"/> + <add-pymethoddef name="add_ints" function="Sbk_IntWrapper_add_ints" + flags="METH_VARARGS"/> + </value-type> <value-type name="Str" hash-function="strHash"> <add-function signature="__str__" return-type="PyObject*"> @@ -2124,6 +2073,7 @@ <conversion-rule> <target-to-native> <add-conversion type="Py_None"> + SBK_UNUSED(%in) %out = %OUTTYPE(); </add-conversion> <add-conversion type="PyObject" check="Shiboken::String::check(%in) || PyBytes_Check(%in)"> @@ -2275,19 +2225,20 @@ </add-function> </value-type> - <value-type name="SimpleFile"> + <object-type name="SimpleFile"> <modify-function signature="open()"> <modify-argument index="return"> <remove-argument/> </modify-argument> <inject-code class="target" position="end" file="simplefile_glue.cpp"/> </modify-function> - </value-type> + </object-type> <value-type name="VoidHolder" /> <object-type name="PrivateCtor" /> <object-type name="PrivateDtor" /> + <value-type name="DeletedDefaultCtor"/> <object-type name="Base1"/> <object-type name="Base2"/> @@ -2302,7 +2253,7 @@ <object-type name="MDerived5"/> <object-type name="SonOfMDerived1"/> - <object-type name="Bucket"> + <object-type name="Bucket" private="true"> <modify-function signature="lock()" allow-thread="yes" /> <modify-function signature="virtualBlockerMethod()" allow-thread="yes"/> <modify-function signature="callVirtualBlockerMethodButYouDontKnowThis()" allow-thread="yes"/> @@ -2324,20 +2275,23 @@ </value-type> <value-type name="Color" /> + <value-type name="Brush" operator-bool="true"> + <enum-type name="Style"/> + </value-type> <value-type name="Pen"> <enum-type identified-by-value="EnumCtor"/> <enum-type name="RenderHints"/> <property type="RenderHints" name="renderHints" get="getRenderHints" set="setRenderHints"/> </value-type> - <value-type name="CtorConvRule"> + <value-type name="CtorConvRule" private="true"> <modify-function signature="CtorConvRule(long)"> <modify-argument index="1"> <!--<replace-type modified-type="long"/>--> <conversion-rule class="native"> // Does nothing really, just test the code generation // of constructors whose arguments where - long %out = PyInt_AS_LONG(%PYARG_1) + 1; + long %out = PyLong_AS_LONG(%PYARG_1) + 1; </conversion-rule> </modify-argument> </modify-function> @@ -2425,15 +2379,24 @@ <value-type name="Expression" /> - <object-type name="ExceptionTest" exception-handling="auto-on"/> - - <value-type name="ModelIndex" /> - <value-type name="ReferentModelIndex"> - <modify-function signature="operator const ModelIndex&()const"> + <object-type name="ExceptionTest" exception-handling="auto-on"> + <modify-function signature="create(bool)"> <modify-argument index="return"> <define-ownership owner="c++"/> </modify-argument> + <inject-code class="target" position="end"> + // Test comment + </inject-code> </modify-function> + </object-type> + + <value-type name="ModelIndex" /> + <value-type name="ReferentModelIndex"> + <modify-function signature="operator const ModelIndex&()const"> + <modify-argument index="return"> + <define-ownership owner="c++"/> + </modify-argument> + </modify-function> </value-type> <value-type name="PersistentModelIndex" /> @@ -2446,6 +2409,31 @@ <object-type name="ObjectTypeByValue" /> + <value-type name="StdComplex"> + <extra-includes> + <include file-name="cmath" location="global"/> + </extra-includes> + <!-- PYSIDE-2446: number protocols without a Py_nb_ constant. --> + <add-function signature="__floor__()" return-type="double"> + <inject-code class="target" position="end" + file="samplesnippets.cpp" snippet="stdcomplex_floor"/> + </add-function> + <add-function signature="__ceil__()" return-type="double"> + <inject-code class="target" position="end" + file="samplesnippets.cpp" snippet="stdcomplex_ceil"/> + </add-function> + <!-- PYSIDE-2446: number protocols with Py_nb_ constants. --> + <add-function signature="__abs__()" return-type="double"> + <inject-code class="target" position="end" + file="samplesnippets.cpp" snippet="stdcomplex_abs"/> + </add-function> + <add-function signature="__pow__(StdComplex@exp@)" return-type="StdComplex"> + <inject-code class="target" position="end" + file="samplesnippets.cpp" snippet="stdcomplex_pow"/> + </add-function> + + </value-type> + <object-type name="TemplatePtr"> <modify-function signature="dummy(std::list<std::pair<BlackBox *, BlackBox *> > &)" rename="dummy_method" /> </object-type> @@ -2461,20 +2449,9 @@ <suppress-warning text="horribly broken type '__off64_t'" /> <suppress-warning text="enum '__codecvt_result' does not have a type entry or is not an enum" /> - <suppress-warning text="Pure virtual method "Abstract::hideFunction(HideType*)" must be implement but was completely removed on typesystem." /> - <suppress-warning text="hiding of function 'takeChild' in class 'ObjectType'" /> + <suppress-warning text="Pure virtual method 'Abstract::hideFunction(HideType*)' must be implemented but was completely removed on type system." /> <suppress-warning text="Shadowing: MDerived2::castToBase3() and MDerived3::castToBase3()" /> - <suppress-warning text="hiding of function 'takeChild' in class 'Bucket'" /> - <suppress-warning text="visibility of function 'publicMethod' modified in class 'MDerived1'" /> - <suppress-warning text="hiding of function 'doNothingInPublic3' in class 'Overload2'" /> - <suppress-warning text="hiding of function 'takeChild' in class 'ObjectModel'" /> - <suppress-warning text="hiding of function 'takeChild' in class 'ObjectView'" /> - <suppress-warning text="visibility of function 'publicMethod' modified in class 'MDerived3'" /> - <suppress-warning text="skipping function 'InjectCode::toStr', unmatched parameter type 'T const&'" /> - - <suppress-warning text="^skipping function 'std::enable_if.*ComparisonTester::operator[!=]=.*ComparisonTester.*$"/> - - <!-- Do not fix this warning, the generator should be able to handle this situation for Object Types. --> - <suppress-warning text="Argument in position 1 of added function 'SampleNamespace::passReferenceToObjectType(ObjectType * arg__1)', has a type that is not a reference, while the argument in the corresponding position in C++ function 'SampleNamespace::passReferenceToObjectType(const ObjectType & obj, int multiplier)' is a reference." /> + <suppress-warning text="Visibility of function 'publicMethod' modified in class 'MDerived1'" /> + <suppress-warning text="^skipping public function 'std::enable_if.*ComparisonTester::operator[!=]=.*ComparisonTester.*$"/> </typesystem> diff --git a/sources/shiboken6/tests/samplebinding/typesystypedef_test.py b/sources/shiboken6/tests/samplebinding/typesystypedef_test.py index 70c22f657..f7f5342ee 100644 --- a/sources/shiboken6/tests/samplebinding/typesystypedef_test.py +++ b/sources/shiboken6/tests/samplebinding/typesystypedef_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- 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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test case for a class that holds a void pointer.''' @@ -40,8 +13,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import (ValueWithUnitUser, ValueWithUnitDoubleInch, - ValueWithUnitDoubleMillimeter) +from sample import ValueWithUnitUser, ValueWithUnitDoubleInch class TypeSysTypeDefTest(unittest.TestCase): diff --git a/sources/shiboken6/tests/samplebinding/unsafe_parent_test.py b/sources/shiboken6/tests/samplebinding/unsafe_parent_test.py index ab9895f1f..2a7e5cac7 100644 --- a/sources/shiboken6/tests/samplebinding/unsafe_parent_test.py +++ b/sources/shiboken6/tests/samplebinding/unsafe_parent_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for ...''' @@ -42,6 +15,7 @@ init_paths() from sample import ObjectType + class DerivedObjectType(ObjectType): def isPython(self): return True @@ -49,12 +23,13 @@ class DerivedObjectType(ObjectType): def createChild(self, parent): return DerivedObjectType(parent) + class ParentTest(unittest.TestCase): def testUunsafeParent(self): o = DerivedObjectType() o.callVirtualCreateChild() + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/useraddedctor_test.py b/sources/shiboken6/tests/samplebinding/useraddedctor_test.py index 910037cd5..45d4095b6 100644 --- a/sources/shiboken6/tests/samplebinding/useraddedctor_test.py +++ b/sources/shiboken6/tests/samplebinding/useraddedctor_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for user added constructors''' @@ -39,14 +12,15 @@ from pathlib import Path sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import Size + class PointTest(unittest.TestCase): def testUsingSelfOnCtor(self): # This is a user added ctor and no errors should happen! - s = Size("oi") + s = Size("3x2") self.assertEqual(s.height(), 2) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/virtualdtor_test.py b/sources/shiboken6/tests/samplebinding/virtualdtor_test.py index 8f29eca3c..6be870269 100644 --- a/sources/shiboken6/tests/samplebinding/virtualdtor_test.py +++ b/sources/shiboken6/tests/samplebinding/virtualdtor_test.py @@ -1,36 +1,10 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for virtual destructor.''' +import gc import os import sys import unittest @@ -42,10 +16,12 @@ init_paths() from sample import VirtualDtor + class ExtendedVirtualDtor(VirtualDtor): def __init__(self): VirtualDtor.__init__(self) + class VirtualDtorTest(unittest.TestCase): '''Test case for virtual destructor.''' @@ -58,6 +34,8 @@ class VirtualDtorTest(unittest.TestCase): for i in range(1, 10): vd = VirtualDtor() del vd + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(VirtualDtor.dtorCalled(), dtor_called + i) def testVirtualDtorOnCppCreatedObject(self): @@ -66,6 +44,8 @@ class VirtualDtorTest(unittest.TestCase): for i in range(1, 10): vd = VirtualDtor.create() del vd + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(VirtualDtor.dtorCalled(), dtor_called + i) def testDtorOnDerivedClass(self): @@ -74,9 +54,10 @@ class VirtualDtorTest(unittest.TestCase): for i in range(1, 10): evd = ExtendedVirtualDtor() del evd + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(ExtendedVirtualDtor.dtorCalled(), dtor_called + i) if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/virtualmethods_test.py b/sources/shiboken6/tests/samplebinding/virtualmethods_test.py index 1c842993c..52dc66c90 100644 --- a/sources/shiboken6/tests/samplebinding/virtualmethods_test.py +++ b/sources/shiboken6/tests/samplebinding/virtualmethods_test.py @@ -1,36 +1,10 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for virtual methods.''' +import gc import os import sys import unittest @@ -40,10 +14,11 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import Point, Str, StrList, VirtualDaughter, VirtualMethods import warnings + class ExtendedVirtualMethods(VirtualMethods): def __init__(self): VirtualMethods.__init__(self) @@ -62,6 +37,7 @@ class ExtendedVirtualMethods(VirtualMethods): # check if recursion is caused by injected code that calls C++. return VirtualMethods.recursionOnModifiedVirtual(self, arg) + 10 + class ExtendedVirtualDaughter(VirtualDaughter): def __init__(self, name): VirtualDaughter.__init__(self, name) @@ -71,6 +47,7 @@ class ExtendedVirtualDaughter(VirtualDaughter): self.grand_daughter_name_called = True return VirtualDaughter.name(self).prepend('Extended') + class ExtendedExtendedVirtualDaughter(ExtendedVirtualDaughter): def __init__(self, name): ExtendedVirtualDaughter.__init__(self, name) @@ -80,6 +57,7 @@ class ExtendedExtendedVirtualDaughter(ExtendedVirtualDaughter): self.grand_grand_daughter_name_called = True return ExtendedVirtualDaughter.name(self).prepend('Extended') + class VirtualMethodsTest(unittest.TestCase): '''Test case for virtual methods''' @@ -88,9 +66,12 @@ class VirtualMethodsTest(unittest.TestCase): def tearDown(self): del self.prefix_from_codeinjection + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() def testReimplementedVirtualMethod0(self): - '''Test Python override of a virtual method with various different parameters is correctly called from C++.''' + '''Test Python override of a virtual method with various different parameters + is correctly called from C++.''' vm = VirtualMethods() evm = ExtendedVirtualMethods() pt = Point(1.1, 2.2) @@ -144,6 +125,6 @@ class PrettyErrorMessageTest(unittest.TestCase): obj = ExtendedVirtualMethods() self.assertRaises(RuntimeWarning, obj.callStrListToStdList, StrList()) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/visibilitychange_test.py b/sources/shiboken6/tests/samplebinding/visibilitychange_test.py index 918d957b2..becdf7423 100644 --- a/sources/shiboken6/tests/samplebinding/visibilitychange_test.py +++ b/sources/shiboken6/tests/samplebinding/visibilitychange_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -38,17 +11,17 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import Base1, MDerived1 + class VisibilityChangeTest(unittest.TestCase): def testVisibilityChange(self): b1 = Base1() - b1.publicMethod() # ok... + b1.publicMethod() # ok... d1 = MDerived1() - self.assertRaises(TypeError, d1.publicMethod); + self.assertRaises(TypeError, d1.publicMethod) + if __name__ == '__main__': unittest.main() - - diff --git a/sources/shiboken6/tests/samplebinding/voidholder_test.py b/sources/shiboken6/tests/samplebinding/voidholder_test.py index da4042a98..186cb473e 100644 --- a/sources/shiboken6/tests/samplebinding/voidholder_test.py +++ b/sources/shiboken6/tests/samplebinding/voidholder_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test case for a class that holds a void pointer.''' @@ -43,6 +16,7 @@ init_paths() from sample import VoidHolder, Point from shiboken6 import Shiboken + class VoidHolderTest(unittest.TestCase): '''Test case for void pointer manipulation.''' @@ -71,6 +45,6 @@ class VoidHolderTest(unittest.TestCase): voidholder = VoidHolder() self.assertEqual(voidholder.voidPointer(), None) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/weakref_test.py b/sources/shiboken6/tests/samplebinding/weakref_test.py index 6ca031c0d..01c6d58d5 100644 --- a/sources/shiboken6/tests/samplebinding/weakref_test.py +++ b/sources/shiboken6/tests/samplebinding/weakref_test.py @@ -1,36 +1,10 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test weakref support''' +import gc import os import sys import unittest @@ -56,15 +30,19 @@ class WeakrefBasicTest(unittest.TestCase): def testBasic(self): '''ObjectType weakref''' obj = ObjectType() - ref = weakref.ref(obj, self.cb) + ref = weakref.ref(obj, self.cb) # noqa: F841 del obj + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertTrue(self.called) def testPrivateDtor(self): '''PrivateDtor weakref''' obj = PrivateDtor.instance() - ref = weakref.ref(obj, self.cb) + ref = weakref.ref(obj, self.cb) # noqa: F841 del obj + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertTrue(self.called) diff --git a/sources/shiboken6/tests/samplebinding/writableclassdict_test.py b/sources/shiboken6/tests/samplebinding/writableclassdict_test.py index b7668e497..dfc962db9 100644 --- a/sources/shiboken6/tests/samplebinding/writableclassdict_test.py +++ b/sources/shiboken6/tests/samplebinding/writableclassdict_test.py @@ -1,33 +1,6 @@ #!/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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -40,7 +13,10 @@ init_paths() from sample import Point -class ExtPoint(Point): pass + +class ExtPoint(Point): + pass + class TestWritableClassDict(unittest.TestCase): def testSetattrOnClass(self): @@ -56,5 +32,6 @@ class TestWritableClassDict(unittest.TestCase): pt = ExtPoint() self.assertEqual(pt.bar, 321) + if __name__ == '__main__': unittest.main() |