diff options
Diffstat (limited to 'sources/shiboken6/tests/otherbinding')
20 files changed, 257 insertions, 488 deletions
diff --git a/sources/shiboken6/tests/otherbinding/CMakeLists.txt b/sources/shiboken6/tests/otherbinding/CMakeLists.txt index 7c8562abc..2172593d3 100644 --- a/sources/shiboken6/tests/otherbinding/CMakeLists.txt +++ b/sources/shiboken6/tests/otherbinding/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + project(other) set(other_TYPESYSTEM @@ -22,13 +25,19 @@ ${CMAKE_CURRENT_BINARY_DIR}/other/valuewithunitintmillimeter_wrapper.cpp configure_file("${CMAKE_CURRENT_SOURCE_DIR}/other-binding.txt.in" "${CMAKE_CURRENT_BINARY_DIR}/other-binding.txt" @ONLY) +shiboken_get_tool_shell_wrapper(shiboken tool_wrapper) + add_custom_command( -OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" -BYPRODUCTS ${other_SRC} -COMMAND shiboken6 --project-file=${CMAKE_CURRENT_BINARY_DIR}/other-binding.txt ${GENERATOR_EXTRA_FLAGS} -DEPENDS ${other_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h shiboken6 -WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -COMMENT "Running generator for 'other' test binding..." + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" + BYPRODUCTS ${other_SRC} + COMMAND + ${tool_wrapper} + $<TARGET_FILE:Shiboken6::shiboken6> + --project-file=${CMAKE_CURRENT_BINARY_DIR}/other-binding.txt + ${GENERATOR_EXTRA_FLAGS} + DEPENDS ${other_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h Shiboken6::shiboken6 + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Running generator for 'other' test binding..." ) add_library(other MODULE ${other_SRC}) diff --git a/sources/shiboken6/tests/otherbinding/collector_external_operator_test.py b/sources/shiboken6/tests/otherbinding/collector_external_operator_test.py index b059335de..2ba21653d 100644 --- a/sources/shiboken6/tests/otherbinding/collector_external_operator_test.py +++ b/sources/shiboken6/tests/otherbinding/collector_external_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 Collector shift operators defined in other modules.''' @@ -43,6 +16,7 @@ init_paths() from sample import Collector, ObjectType from other import OtherObjectType + class CollectorOtherObjectType(unittest.TestCase): '''Test cases for Collector << OtherObjectType''' @@ -60,6 +34,6 @@ class CollectorOtherObjectType(unittest.TestCase): collector << obj self.assertEqual(collector.items()[0], obj.identifier() * 2) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/otherbinding/conversion_operator_for_class_without_implicit_conversions_test.py b/sources/shiboken6/tests/otherbinding/conversion_operator_for_class_without_implicit_conversions_test.py index 79ae9de18..bd00b5892 100644 --- a/sources/shiboken6/tests/otherbinding/conversion_operator_for_class_without_implicit_conversions_test.py +++ b/sources/shiboken6/tests/otherbinding/conversion_operator_for_class_without_implicit_conversions_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 calling NoImplicitConversion using a ExtendsNoImplicitConversion parameter, being that the latter defines a new conversion operator for the former, and this one @@ -45,8 +18,10 @@ init_paths() from sample import NoImplicitConversion from other import ExtendsNoImplicitConversion + class ConversionOperatorForClassWithoutImplicitConversionsTest(unittest.TestCase): - '''Tests calling NoImplicitConversion constructor using a ExtendsNoImplicitConversion parameter.''' + '''Tests calling NoImplicitConversion constructor using a + ExtendsNoImplicitConversion parameter.''' def testNoImplicitConversion(self): '''Basic test to see if the NoImplicitConversion is Ok.''' @@ -54,27 +29,33 @@ class ConversionOperatorForClassWithoutImplicitConversionsTest(unittest.TestCase # NoImplicitConversion.receivesNoImplicitConversionByValue(NoImplicitConversion) self.assertEqual(obj.objId(), NoImplicitConversion.receivesNoImplicitConversionByValue(obj)) # NoImplicitConversion.receivesNoImplicitConversionByPointer(NoImplicitConversion*) - self.assertEqual(obj.objId(), NoImplicitConversion.receivesNoImplicitConversionByPointer(obj)) + self.assertEqual(obj.objId(), + NoImplicitConversion.receivesNoImplicitConversionByPointer(obj)) # NoImplicitConversion.receivesNoImplicitConversionByReference(NoImplicitConversion&) - self.assertEqual(obj.objId(), NoImplicitConversion.receivesNoImplicitConversionByReference(obj)) + self.assertEqual(obj.objId(), + NoImplicitConversion.receivesNoImplicitConversionByReference(obj)) def testPassingExtendsNoImplicitConversionAsNoImplicitConversionByValue(self): - '''Gives an ExtendsNoImplicitConversion object to a function expecting a NoImplicitConversion, passing by value.''' + '''Gives an ExtendsNoImplicitConversion object to a function expecting a + NoImplicitConversion, passing by value.''' obj = ExtendsNoImplicitConversion(123) self.assertEqual(obj.objId(), NoImplicitConversion.receivesNoImplicitConversionByValue(obj)) def testPassingExtendsNoImplicitConversionAsNoImplicitConversionByReference(self): - '''Gives an ExtendsNoImplicitConversion object to a function expecting a NoImplicitConversion, passing by reference.''' + '''Gives an ExtendsNoImplicitConversion object to a function expecting a + NoImplicitConversion, passing by reference.''' obj = ExtendsNoImplicitConversion(123) - self.assertEqual(obj.objId(), NoImplicitConversion.receivesNoImplicitConversionByReference(obj)) + self.assertEqual(obj.objId(), + NoImplicitConversion.receivesNoImplicitConversionByReference(obj)) def testPassingExtendsNoImplicitConversionAsNoImplicitConversionByPointer(self): - '''Gives an ExtendsNoImplicitConversion object to a function expecting a NoImplicitConversion, passing by pointer. - This should not be accepted, since pointers should not be converted.''' + '''Gives an ExtendsNoImplicitConversion object to a function expecting + a NoImplicitConversion, passing by pointer. This should not be + accepted, since pointers should not be converted.''' obj = ExtendsNoImplicitConversion(123) - self.assertRaises(TypeError, NoImplicitConversion.receivesNoImplicitConversionByPointer, obj) + self.assertRaises(TypeError, + NoImplicitConversion.receivesNoImplicitConversionByPointer, obj) if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/otherbinding/extended_multiply_operator_test.py b/sources/shiboken6/tests/otherbinding/extended_multiply_operator_test.py index e54e38e77..abbef6231 100644 --- a/sources/shiboken6/tests/otherbinding/extended_multiply_operator_test.py +++ b/sources/shiboken6/tests/otherbinding/extended_multiply_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 libsample's Point multiply operator defined in libother module.''' @@ -43,6 +16,7 @@ init_paths() from sample import Point from other import Number + class PointOperationsWithNumber(unittest.TestCase): '''Test cases for libsample's Point multiply operator defined in libother module.''' @@ -66,6 +40,6 @@ class PointOperationsWithNumber(unittest.TestCase): num = Number(11) self.assertEqual(pt * num.value(), pt * 11) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/otherbinding/global.h b/sources/shiboken6/tests/otherbinding/global.h index 702fb9287..af796734a 100644 --- a/sources/shiboken6/tests/otherbinding/global.h +++ b/sources/shiboken6/tests/otherbinding/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 "../samplebinding/global.h" #include "extendsnoimplicitconversion.h" diff --git a/sources/shiboken6/tests/otherbinding/module_reload_test.py b/sources/shiboken6/tests/otherbinding/module_reload_test.py index fe3a83533..bde2f5236 100644 --- a/sources/shiboken6/tests/otherbinding/module_reload_test.py +++ b/sources/shiboken6/tests/otherbinding/module_reload_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 from importlib import reload import os @@ -48,6 +21,7 @@ dst = workdir / 'test_module.py' shutil.copyfile(src, dst) sys.path.append(os.fspath(workdir)) + class TestModuleReloading(unittest.TestCase): def testModuleReloading(self): @@ -59,5 +33,6 @@ class TestModuleReloading(unittest.TestCase): reload(test_module) self.assertFalse(oldObject is test_module.obj) + if __name__ == "__main__": unittest.main() diff --git a/sources/shiboken6/tests/otherbinding/new_ctor_operator_test.py b/sources/shiboken6/tests/otherbinding/new_ctor_operator_test.py index c3a12d7ad..d6c356436 100644 --- a/sources/shiboken6/tests/otherbinding/new_ctor_operator_test.py +++ b/sources/shiboken6/tests/otherbinding/new_ctor_operator_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$ -## -############################################################################# - -'''Tests calling Str constructor using a Number parameter, being that number defines a cast operator to Str.''' +# 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 calling Str constructor using a Number parameter, being that number defines + a cast operator to Str.''' import os import sys @@ -43,8 +17,10 @@ init_paths() from sample import Str from other import Number + class NewCtorOperatorTest(unittest.TestCase): - '''Tests calling Str constructor using a Number parameter, being that number defines a cast operator to Str.''' + '''Tests calling Str constructor using a Number parameter, being that number + defines a cast operator to Str.''' def testNumber(self): '''Basic test to see if the Number class is Ok.''' @@ -56,8 +32,8 @@ class NewCtorOperatorTest(unittest.TestCase): '''Try to build a Str from 'sample' module with a Number argument from 'other' module.''' value = 123 num = Number(value) - string = Str(num) + string = Str(num) # noqa: F841 + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/otherbinding/objtypehashes_test.py b/sources/shiboken6/tests/otherbinding/objtypehashes_test.py index 36c27b35d..d2cd7de5b 100644 --- a/sources/shiboken6/tests/otherbinding/objtypehashes_test.py +++ b/sources/shiboken6/tests/otherbinding/objtypehashes_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,10 +9,10 @@ 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 other import * +from sample import HandleHolder from shiboken6 import Shiboken + class TestHashFuncs (unittest.TestCase): def testIt(self): @@ -55,6 +30,5 @@ class TestHashFuncs (unittest.TestCase): self.assertEqual(hash1_2, hash1) - if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/otherbinding/other-binding.txt.in b/sources/shiboken6/tests/otherbinding/other-binding.txt.in index dbe935a9f..d85f6030a 100644 --- a/sources/shiboken6/tests/otherbinding/other-binding.txt.in +++ b/sources/shiboken6/tests/otherbinding/other-binding.txt.in @@ -17,4 +17,4 @@ typesystem-path = @sample_SOURCE_DIR@ typesystem-path = @smart_SOURCE_DIR@ enable-parent-ctor-heuristic - +lean-headers diff --git a/sources/shiboken6/tests/otherbinding/otherbinding.pyproject b/sources/shiboken6/tests/otherbinding/otherbinding.pyproject new file mode 100644 index 000000000..d1bbee11e --- /dev/null +++ b/sources/shiboken6/tests/otherbinding/otherbinding.pyproject @@ -0,0 +1,17 @@ +{ + "files": ["collector_external_operator_test.py", + "conversion_operator_for_class_without_implicit_conversions_test.py", + "extended_multiply_operator_test.py", + "module_reload_test.py", + "new_ctor_operator_test.py", + "objtypehashes_test.py", + "otherderived_test.py", + "othertypesystypedef_test.py", + "signature_test.py", + "smartptr_test.py", + "test_module_template.py", + "typediscovery_test.py", + "usersprimitivefromothermodule_test.py", + "wrongctor_test.py", + "typesystem_other.xml"] +} diff --git a/sources/shiboken6/tests/otherbinding/otherderived_test.py b/sources/shiboken6/tests/otherbinding/otherderived_test.py index 9a68e2ad4..459f474f1 100644 --- a/sources/shiboken6/tests/otherbinding/otherderived_test.py +++ b/sources/shiboken6/tests/otherbinding/otherderived_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 OtherDerived class''' +import gc import os import sys import unittest @@ -43,6 +17,7 @@ init_paths() from sample import Abstract, Derived from other import OtherDerived, Number + class Multiple(Derived, Number): def __init__(self): Derived.__init__(self, 42) @@ -51,6 +26,7 @@ class Multiple(Derived, Number): def testCall(self): return True + class OtherDeviant(OtherDerived): def __init__(self): OtherDerived.__init__(self) @@ -66,6 +42,7 @@ class OtherDeviant(OtherDerived): def className(self): return 'OtherDeviant' + class MultipleTest(unittest.TestCase): '''Test case for Multiple derived class''' @@ -75,6 +52,8 @@ class MultipleTest(unittest.TestCase): self.assertTrue(isinstance(o, Number)) self.assertTrue(isinstance(o, Derived)) del o + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() def testMethodCall(self): o = Multiple() @@ -82,6 +61,7 @@ class MultipleTest(unittest.TestCase): self.assertTrue(o.value(), 42) self.assertTrue(o.testCall()) + class OtherDerivedTest(unittest.TestCase): '''Test case for OtherDerived class''' @@ -92,13 +72,15 @@ class OtherDerivedTest(unittest.TestCase): self.assertTrue(inherited_methods.issubset(dir(OtherDerived))) 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 = OtherDeviant() 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 = OtherDeviant() d.callUnpureVirtual() self.assertTrue(d.unpure_virtual_called) @@ -110,7 +92,8 @@ class OtherDerivedTest(unittest.TestCase): self.assertEqual(d.getClassName(), 'OtherDerived') 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 = OtherDeviant() self.assertEqual(d.className(), 'OtherDeviant') self.assertEqual(d.getClassName(), 'OtherDeviant') @@ -121,6 +104,6 @@ class OtherDerivedTest(unittest.TestCase): d = OtherDerived(objId) self.assertEqual(Abstract.getObjectId(d), objId) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/otherbinding/othertypesystypedef_test.py b/sources/shiboken6/tests/otherbinding/othertypesystypedef_test.py index 05ac50c89..198c71693 100644 --- a/sources/shiboken6/tests/otherbinding/othertypesystypedef_test.py +++ b/sources/shiboken6/tests/otherbinding/othertypesystypedef_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 other import (OtherValueWithUnitUser, ValueWithUnitIntInch, - ValueWithUnitIntMillimeter) +from other import (OtherValueWithUnitUser, ValueWithUnitIntMillimeter) from sample import (ValueWithUnitDoubleMillimeter) diff --git a/sources/shiboken6/tests/otherbinding/signature_test.py b/sources/shiboken6/tests/otherbinding/signature_test.py index 9f94edd34..8db3e566b 100644 --- a/sources/shiboken6/tests/otherbinding/signature_test.py +++ b/sources/shiboken6/tests/otherbinding/signature_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 functions signature''' @@ -43,13 +16,19 @@ init_paths() from other import OtherObjectType from shiboken_test_helper import objectFullname +from shibokensupport.signature import get_signature + + class SignatureTest(unittest.TestCase): - # Check if the argument of 'OtherObjectType::enumAsInt(SampleNamespace::SomeClass::PublicScopedEnum value)' + # Check if the argument of + # 'OtherObjectType::enumAsInt(SampleNamespace::SomeClass::PublicScopedEnum value)' # has the correct representation def testNamespaceFromOtherModule(self): - argType = OtherObjectType.enumAsInt.__signature__.parameters['value'].annotation - self.assertEqual(objectFullname(argType), 'sample.SampleNamespace.SomeClass.PublicScopedEnum') + argType = get_signature(OtherObjectType.enumAsInt).parameters["value"].annotation + self.assertEqual(objectFullname(argType), + "sample.SampleNamespace.SomeClass.PublicScopedEnum") + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/otherbinding/smartptr_test.py b/sources/shiboken6/tests/otherbinding/smartptr_test.py index a3a764629..fd5c7fa09 100644 --- a/sources/shiboken6/tests/otherbinding/smartptr_test.py +++ b/sources/shiboken6/tests/otherbinding/smartptr_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 the SmartPtrTester class''' @@ -40,8 +13,6 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from smart import Integer -from sample import Str from other import SmartPtrTester diff --git a/sources/shiboken6/tests/otherbinding/star_import_test.py b/sources/shiboken6/tests/otherbinding/star_import_test.py new file mode 100644 index 000000000..4b5f1d270 --- /dev/null +++ b/sources/shiboken6/tests/otherbinding/star_import_test.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +"""PYSIDE-2404: Test whether star imports work as they require special handling + by the lazy initialization.""" + +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() + +SHIBOKEN_NAME = "shiboken6.Shiboken" +MINIMAL_NAME = "minimal" +OTHER_NAME = "other" + +shiboken_loaded = 1 if sys.modules.get(SHIBOKEN_NAME) else 0 +minimal_loaded = 1 if sys.modules.get(MINIMAL_NAME) else 0 +other_loaded = 1 if sys.modules.get(OTHER_NAME) else 0 + +from minimal import * # noqa: F403 + +shiboken_loaded += 2 if sys.modules.get(SHIBOKEN_NAME) else 0 +minimal_loaded += 2 if sys.modules.get(MINIMAL_NAME) else 0 +other_loaded += 2 if sys.modules.get(OTHER_NAME) else 0 + +from other import Number # noqa: F403 +from other import * # noqa: F403 + +shiboken_loaded += 4 if sys.modules.get(SHIBOKEN_NAME) else 0 +minimal_loaded += 4 if sys.modules.get(MINIMAL_NAME) else 0 +other_loaded = +4 if sys.modules.get(OTHER_NAME) else 0 + +import shiboken6.Shiboken # noqa: F401 F403 + +shiboken_loaded += 8 if sys.modules.get(SHIBOKEN_NAME) else 0 + + +class ValTest(unittest.TestCase): + + def test(self): + val_id = 123 + val = Val(val_id) # noqa: F405 + self.assertEqual(val.valId(), val_id) + + +class Simple(Number): + + def __init__(self): + Number.__init__(self, 42) + + +class OtherTest(unittest.TestCase): + + def testConstructor(self): + o = Simple() + self.assertTrue(isinstance(o, Number)) + + +class StarImportTest(unittest.TestCase): + """ + This test is meant for Lazy Init. + We explicitly choose modules which are able to lazy load. + + The ValTest: + ------------ + We load something with `import *`. + There is no module from our known ones imported. + This means we need stack introspection to find out that this was + a star import and we must disable lazyness. + + The OtherTest: + -------------- + We load something normally that should be lazy. + After that, we follow with a star import. + Now the stack introspection does not work, because the loading is + cached. The first import did a lazy load. The following star import + needs to undo the lazyness. But now we have a redirected import. + + All tests simply check if the objects are real and not just names. + The <module>_loaded tests prevend upcoming internal dependencies. + + To make sure that Shiboken is really not involved, it is checked + and really imported afterwards (ensuring nothing is misspelled). + """ + + def testStar(self): + self.assertEqual(other_loaded, 4) + self.assertEqual(minimal_loaded, 6) + self.assertEqual(shiboken_loaded, 14) + # Interesting effect: Did not expect that shiboken is loaded at all. + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/shiboken6/tests/otherbinding/test_module_template.py b/sources/shiboken6/tests/otherbinding/test_module_template.py index 5d08944f3..36ab43ae3 100644 --- a/sources/shiboken6/tests/otherbinding/test_module_template.py +++ b/sources/shiboken6/tests/otherbinding/test_module_template.py @@ -1,38 +1,22 @@ -############################################################################# -## -## 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$ -## -############################################################################# - -from other import * -from sample import * +# 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 pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from shiboken_paths import init_paths +init_paths() + +from other import OtherObjectType +from sample import ObjectType class MyObjectType(ObjectType): pass + class MyOtherObjectType(OtherObjectType): value = 10 diff --git a/sources/shiboken6/tests/otherbinding/typediscovery_test.py b/sources/shiboken6/tests/otherbinding/typediscovery_test.py index fee4734ae..39dc5cf0f 100644 --- a/sources/shiboken6/tests/otherbinding/typediscovery_test.py +++ b/sources/shiboken6/tests/otherbinding/typediscovery_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 type discovery''' @@ -40,9 +13,11 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import Abstract, Base1, Derived, MDerived1, MDerived3, SonOfMDerived1 +from sample import (Abstract, Base1, Derived, + MDerived1, SonOfMDerived1, MDerived3) from other import OtherMultipleDerived + class TypeDiscoveryTest(unittest.TestCase): def testPureVirtualsOfImpossibleTypeDiscovery(self): @@ -56,18 +31,23 @@ class TypeDiscoveryTest(unittest.TestCase): self.assertEqual(type(a), Derived) def testMultipleInheritance(self): - obj = OtherMultipleDerived.createObject("Base1"); + obj = OtherMultipleDerived.createObject("Base1") self.assertEqual(type(obj), Base1) - # PYSIDE-868: In case of multiple inheritance, a factory + # PYSIDE-868: In case of single line direct inheritance, + # a factory function will return the class wrapper + # of the derived class. + obj = OtherMultipleDerived.createObject("MDerived1") + self.assertEqual(type(obj), MDerived1) + obj = OtherMultipleDerived.createObject("SonOfMDerived1") + self.assertEqual(type(obj), SonOfMDerived1) + obj = OtherMultipleDerived.createObject("MDerived3") + self.assertEqual(type(obj), MDerived3) + # PYSIDE-868: OtherMultipleDerived inherits + # OtherBase, Base1. In this case, a factory # function will return the base class wrapper. - obj = OtherMultipleDerived.createObject("MDerived1"); - self.assertEqual(type(obj), Base1) - obj = OtherMultipleDerived.createObject("SonOfMDerived1"); - self.assertEqual(type(obj), Base1) - obj = OtherMultipleDerived.createObject("MDerived3"); - self.assertEqual(type(obj), Base1) - obj = OtherMultipleDerived.createObject("OtherMultipleDerived"); + obj = OtherMultipleDerived.createObject("OtherMultipleDerived") self.assertEqual(type(obj), Base1) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/otherbinding/typesystem_other.xml b/sources/shiboken6/tests/otherbinding/typesystem_other.xml index 4081548fc..ade1c8bad 100644 --- a/sources/shiboken6/tests/otherbinding/typesystem_other.xml +++ b/sources/shiboken6/tests/otherbinding/typesystem_other.xml @@ -17,8 +17,4 @@ <typedef-type name="ValueWithUnitIntInch" source="ValueWithUnit<int,LengthUnit::Inch>"/> <typedef-type name="ValueWithUnitIntMillimeter" source="ValueWithUnit<int,LengthUnit::Millimeter>"/> <value-type name="OtherValueWithUnitUser"/> - - <suppress-warning text="signature 'operator!=(ByteArray,const char*)' for function modification in 'ByteArray' not found." /> - <suppress-warning text="signature 'operator+(ByteArray,const char*)' for function modification in 'ByteArray' not found." /> - <suppress-warning text="signature 'operator==(ByteArray,const char*)' for function modification in 'ByteArray' not found." /> </typesystem> diff --git a/sources/shiboken6/tests/otherbinding/usersprimitivefromothermodule_test.py b/sources/shiboken6/tests/otherbinding/usersprimitivefromothermodule_test.py index ec9e81080..15a988326 100644 --- a/sources/shiboken6/tests/otherbinding/usersprimitivefromothermodule_test.py +++ b/sources/shiboken6/tests/otherbinding/usersprimitivefromothermodule_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 user defined primitive type from a required module.''' @@ -41,6 +14,7 @@ from shiboken_paths import init_paths init_paths() from other import Number + class UserDefinedPrimitiveTypeFromRequiredModuleTest(unittest.TestCase): def testUsersPrimitiveFromRequiredModuleAsArgument(self): @@ -55,5 +29,6 @@ class UserDefinedPrimitiveTypeFromRequiredModuleTest(unittest.TestCase): cpx = number.toComplex() self.assertEqual(number.value(), int(cpx.real)) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/otherbinding/wrongctor_test.py b/sources/shiboken6/tests/otherbinding/wrongctor_test.py index 1813671d7..b9251b428 100644 --- a/sources/shiboken6/tests/otherbinding/wrongctor_test.py +++ b/sources/shiboken6/tests/otherbinding/wrongctor_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,17 +10,19 @@ 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 other import * +from sample import Abstract, ObjectType +from other import OtherDerived + class Foo(OtherDerived): def __init__(self): - Abstract.__init__(self, 2) # this should raise an exception + Abstract.__init__(self, 2) # this should raise an exception + class Foo2(ObjectType, OtherDerived): def __init__(self): ObjectType.__init__(self) - Abstract.__init__(self, 2) # this should raise an exception + Abstract.__init__(self, 2) # this should raise an exception class WrongCtorTest(unittest.TestCase): |