aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/tests/samplebinding
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken6/tests/samplebinding')
-rw-r--r--sources/shiboken6/tests/samplebinding/CMakeLists.txt24
-rw-r--r--sources/shiboken6/tests/samplebinding/__del___test.py4
-rw-r--r--sources/shiboken6/tests/samplebinding/abstract_test.py11
-rw-r--r--sources/shiboken6/tests/samplebinding/addedfunction_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/addedfunction_with_container_args_test.py6
-rw-r--r--sources/shiboken6/tests/samplebinding/argumentmodifications_test.py15
-rw-r--r--sources/shiboken6/tests/samplebinding/array_numpy_test.py10
-rw-r--r--sources/shiboken6/tests/samplebinding/array_sequence_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/bug_554_test.py6
-rw-r--r--sources/shiboken6/tests/samplebinding/bug_704_test.py5
-rw-r--r--sources/shiboken6/tests/samplebinding/bytearray_test.py6
-rw-r--r--sources/shiboken6/tests/samplebinding/child_return_test.py5
-rw-r--r--sources/shiboken6/tests/samplebinding/class_fields_test.py15
-rw-r--r--sources/shiboken6/tests/samplebinding/collector_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/complex_test.py11
-rw-r--r--sources/shiboken6/tests/samplebinding/conversion_operator_test.py6
-rw-r--r--sources/shiboken6/tests/samplebinding/copy_test.py1
-rw-r--r--sources/shiboken6/tests/samplebinding/ctorconvrule_test.py3
-rw-r--r--sources/shiboken6/tests/samplebinding/cyclic_test.py7
-rw-r--r--sources/shiboken6/tests/samplebinding/date_test.py3
-rw-r--r--sources/shiboken6/tests/samplebinding/decisor_test.py15
-rw-r--r--sources/shiboken6/tests/samplebinding/delete_test.py6
-rw-r--r--sources/shiboken6/tests/samplebinding/deprecated_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/derived_test.py54
-rw-r--r--sources/shiboken6/tests/samplebinding/duck_punching_test.py13
-rw-r--r--sources/shiboken6/tests/samplebinding/echo_test.py6
-rw-r--r--sources/shiboken6/tests/samplebinding/enum_test.py67
-rw-r--r--sources/shiboken6/tests/samplebinding/enumfromremovednamespace_test.py15
-rw-r--r--sources/shiboken6/tests/samplebinding/event_loop_call_virtual_test.py4
-rw-r--r--sources/shiboken6/tests/samplebinding/event_loop_thread_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/exception_test.py28
-rw-r--r--sources/shiboken6/tests/samplebinding/filter_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/global.h1
-rw-r--r--sources/shiboken6/tests/samplebinding/handleholder_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/hashabletype_test.py5
-rw-r--r--sources/shiboken6/tests/samplebinding/ignorederefop_test.py4
-rw-r--r--sources/shiboken6/tests/samplebinding/implicitconv_numerical_test.py1
-rw-r--r--sources/shiboken6/tests/samplebinding/implicitconv_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/inheritanceandscope_test.py6
-rw-r--r--sources/shiboken6/tests/samplebinding/injectcode_test.py19
-rw-r--r--sources/shiboken6/tests/samplebinding/innerclass_test.py5
-rw-r--r--sources/shiboken6/tests/samplebinding/intlist_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/intwrapper_test.py4
-rw-r--r--sources/shiboken6/tests/samplebinding/invalid_virtual_return_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/keep_reference_test.py13
-rw-r--r--sources/shiboken6/tests/samplebinding/list_test.py7
-rw-r--r--sources/shiboken6/tests/samplebinding/lock_test.py4
-rw-r--r--sources/shiboken6/tests/samplebinding/map_test.py15
-rw-r--r--sources/shiboken6/tests/samplebinding/metaclass_test.py14
-rw-r--r--sources/shiboken6/tests/samplebinding/mixed_mi_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/modelindex_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/modelview_test.py7
-rw-r--r--sources/shiboken6/tests/samplebinding/modifications_test.py40
-rw-r--r--sources/shiboken6/tests/samplebinding/modified_constructor_test.py5
-rw-r--r--sources/shiboken6/tests/samplebinding/modifiedvirtualmethods_test.py12
-rw-r--r--sources/shiboken6/tests/samplebinding/multi_cpp_inheritance_test.py39
-rw-r--r--sources/shiboken6/tests/samplebinding/multiple_derived_test.py43
-rw-r--r--sources/shiboken6/tests/samplebinding/namespace_test.py55
-rw-r--r--sources/shiboken6/tests/samplebinding/newdivision_test.py6
-rw-r--r--sources/shiboken6/tests/samplebinding/nondefaultctor_test.py9
-rw-r--r--sources/shiboken6/tests/samplebinding/nontypetemplate_test.py3
-rw-r--r--sources/shiboken6/tests/samplebinding/nonzero_test.py1
-rw-r--r--sources/shiboken6/tests/samplebinding/numericaltypedef_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/numpy_test.py5
-rw-r--r--sources/shiboken6/tests/samplebinding/objecttype_test.py3
-rw-r--r--sources/shiboken6/tests/samplebinding/objecttype_with_named_args_test.py8
-rw-r--r--sources/shiboken6/tests/samplebinding/objecttypebyvalue_test.py3
-rw-r--r--sources/shiboken6/tests/samplebinding/objecttypelayout_test.py28
-rw-r--r--sources/shiboken6/tests/samplebinding/objecttypeoperators_test.py6
-rw-r--r--sources/shiboken6/tests/samplebinding/objecttypereferenceasvirtualmethodargument_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/oddbool_test.py14
-rw-r--r--sources/shiboken6/tests/samplebinding/onlycopyclass_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/overflow_test.py16
-rw-r--r--sources/shiboken6/tests/samplebinding/overload_sorting_test.py6
-rw-r--r--sources/shiboken6/tests/samplebinding/overload_test.py12
-rw-r--r--sources/shiboken6/tests/samplebinding/overloadwithdefault_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/ownership_argument_invalidation_test.py9
-rw-r--r--sources/shiboken6/tests/samplebinding/ownership_delete_child_in_cpp_test.py1
-rw-r--r--sources/shiboken6/tests/samplebinding/ownership_delete_child_in_python_test.py1
-rw-r--r--sources/shiboken6/tests/samplebinding/ownership_delete_parent_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/ownership_invalidate_after_use_test.py12
-rw-r--r--sources/shiboken6/tests/samplebinding/ownership_invalidate_child_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/ownership_invalidate_nonpolymorphic_test.py3
-rw-r--r--sources/shiboken6/tests/samplebinding/ownership_invalidate_parent_test.py4
-rw-r--r--sources/shiboken6/tests/samplebinding/ownership_reparenting_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/ownership_transference_test.py16
-rw-r--r--sources/shiboken6/tests/samplebinding/pair_test.py13
-rw-r--r--sources/shiboken6/tests/samplebinding/pen_test.py1
-rw-r--r--sources/shiboken6/tests/samplebinding/point_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/pointerholder_test.py8
-rw-r--r--sources/shiboken6/tests/samplebinding/pointerprimitivetype_test.py4
-rw-r--r--sources/shiboken6/tests/samplebinding/pointf_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/primitivereferenceargument_test.py6
-rw-r--r--sources/shiboken6/tests/samplebinding/privatector_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/privatedtor_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/protected_test.py81
-rw-r--r--sources/shiboken6/tests/samplebinding/pstrlist_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/pystr_test.py3
-rw-r--r--sources/shiboken6/tests/samplebinding/python_thread_test.py6
-rw-r--r--sources/shiboken6/tests/samplebinding/receive_null_cstring_test.py6
-rw-r--r--sources/shiboken6/tests/samplebinding/reference_test.py24
-rw-r--r--sources/shiboken6/tests/samplebinding/referencetopointer_test.py3
-rw-r--r--sources/shiboken6/tests/samplebinding/renaming_test.py4
-rw-r--r--sources/shiboken6/tests/samplebinding/return_null_test.py6
-rw-r--r--sources/shiboken6/tests/samplebinding/richcompare_test.py4
-rw-r--r--sources/shiboken6/tests/samplebinding/sample-binding.txt.in1
-rw-r--r--sources/shiboken6/tests/samplebinding/sample_test.py48
-rw-r--r--sources/shiboken6/tests/samplebinding/samplebinding.pyproject131
-rw-r--r--sources/shiboken6/tests/samplebinding/samplesnippets.cpp36
-rw-r--r--sources/shiboken6/tests/samplebinding/simplefile_test.py3
-rw-r--r--sources/shiboken6/tests/samplebinding/size_test.py3
-rw-r--r--sources/shiboken6/tests/samplebinding/static_nonstatic_methods_test.py8
-rw-r--r--sources/shiboken6/tests/samplebinding/stdcomplex_test.py71
-rw-r--r--sources/shiboken6/tests/samplebinding/str_test.py38
-rw-r--r--sources/shiboken6/tests/samplebinding/strlist_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/templateinheritingclass_test.py4
-rw-r--r--sources/shiboken6/tests/samplebinding/time_test.py4
-rw-r--r--sources/shiboken6/tests/samplebinding/transform_test.py2
-rw-r--r--sources/shiboken6/tests/samplebinding/typeconverters_test.py20
-rw-r--r--sources/shiboken6/tests/samplebinding/typedealloc_test.py9
-rw-r--r--sources/shiboken6/tests/samplebinding/typedtordoublefree_test.py4
-rw-r--r--sources/shiboken6/tests/samplebinding/typesystem_sample.xml114
-rw-r--r--sources/shiboken6/tests/samplebinding/typesystypedef_test.py3
-rw-r--r--sources/shiboken6/tests/samplebinding/unsafe_parent_test.py4
-rw-r--r--sources/shiboken6/tests/samplebinding/useraddedctor_test.py7
-rw-r--r--sources/shiboken6/tests/samplebinding/virtualdtor_test.py3
-rw-r--r--sources/shiboken6/tests/samplebinding/virtualmethods_test.py11
-rw-r--r--sources/shiboken6/tests/samplebinding/visibilitychange_test.py10
-rw-r--r--sources/shiboken6/tests/samplebinding/voidholder_test.py3
-rw-r--r--sources/shiboken6/tests/samplebinding/weakref_test.py4
-rw-r--r--sources/shiboken6/tests/samplebinding/writableclassdict_test.py6
131 files changed, 1031 insertions, 546 deletions
diff --git a/sources/shiboken6/tests/samplebinding/CMakeLists.txt b/sources/shiboken6/tests/samplebinding/CMakeLists.txt
index 7576f6734..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
@@ -27,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
@@ -106,11 +110,13 @@ ${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
@@ -142,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::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..."
+ 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 2d38b24d7..456886614 100644
--- a/sources/shiboken6/tests/samplebinding/__del___test.py
+++ b/sources/shiboken6/tests/samplebinding/__del___test.py
@@ -16,11 +16,13 @@ import sample
delCalled = False
+
class MyObject(sample.ObjectType):
def __del__(self):
global delCalled
delCalled = True
+
class TestDel(unittest.TestCase):
def testIt(self):
a = MyObject()
@@ -29,6 +31,6 @@ class TestDel(unittest.TestCase):
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 252541af1..89e87be1d 100644
--- a/sources/shiboken6/tests/samplebinding/abstract_test.py
+++ b/sources/shiboken6/tests/samplebinding/abstract_test.py
@@ -15,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)
@@ -60,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++.'''
@@ -85,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 879bba7f2..0b5680143 100644
--- a/sources/shiboken6/tests/samplebinding/addedfunction_test.py
+++ b/sources/shiboken6/tests/samplebinding/addedfunction_test.py
@@ -14,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.'''
@@ -38,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 3a570ccfd..2a739033b 100644
--- a/sources/shiboken6/tests/samplebinding/addedfunction_with_container_args_test.py
+++ b/sources/shiboken6/tests/samplebinding/addedfunction_with_container_args_test.py
@@ -14,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 8158f89d2..b0ca56a6d 100644
--- a/sources/shiboken6/tests/samplebinding/argumentmodifications_test.py
+++ b/sources/shiboken6/tests/samplebinding/argumentmodifications_test.py
@@ -16,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.'''
@@ -40,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))
@@ -51,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))
@@ -59,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))
@@ -68,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)
@@ -88,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 ba9194122..0d73bca1c 100644
--- a/sources/shiboken6/tests/samplebinding/array_numpy_test.py
+++ b/sources/shiboken6/tests/samplebinding/array_numpy_test.py
@@ -22,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 cb5cbc49d..ad65d58db 100644
--- a/sources/shiboken6/tests/samplebinding/array_sequence_test.py
+++ b/sources/shiboken6/tests/samplebinding/array_sequence_test.py
@@ -14,6 +14,7 @@ from shiboken_paths import init_paths
init_paths()
import sample
+
class ArrayTester(unittest.TestCase):
'''Test case for arrays.'''
@@ -30,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 6c4df6399..a7e7a7210 100644
--- a/sources/shiboken6/tests/samplebinding/bug_554_test.py
+++ b/sources/shiboken6/tests/samplebinding/bug_554_test.py
@@ -11,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 6de8fa3ea..c470fe723 100644
--- a/sources/shiboken6/tests/samplebinding/bug_704_test.py
+++ b/sources/shiboken6/tests/samplebinding/bug_704_test.py
@@ -25,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 e7c421b96..e51a899fa 100644
--- a/sources/shiboken6/tests/samplebinding/bytearray_test.py
+++ b/sources/shiboken6/tests/samplebinding/bytearray_test.py
@@ -34,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)
@@ -80,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 97525bcb8..f0ac70626 100644
--- a/sources/shiboken6/tests/samplebinding/child_return_test.py
+++ b/sources/shiboken6/tests/samplebinding/child_return_test.py
@@ -14,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.'''
@@ -37,6 +38,6 @@ class ReturnOfChildTest(unittest.TestCase):
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 9da25e137..1eeb3d446 100644
--- a/sources/shiboken6/tests/samplebinding/class_fields_test.py
+++ b/sources/shiboken6/tests/samplebinding/class_fields_test.py
@@ -15,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.'''
@@ -36,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.'''
@@ -72,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.'''
@@ -80,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)
@@ -92,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.'''
@@ -111,7 +112,7 @@ 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):
@@ -155,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)
@@ -165,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 376f91f1c..4caebc62a 100644
--- a/sources/shiboken6/tests/samplebinding/collector_test.py
+++ b/sources/shiboken6/tests/samplebinding/collector_test.py
@@ -33,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'''
@@ -57,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 6f0b23b2a..454aff100 100644
--- a/sources/shiboken6/tests/samplebinding/complex_test.py
+++ b/sources/shiboken6/tests/samplebinding/complex_test.py
@@ -16,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'''
@@ -47,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')
@@ -60,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 f349ae82b..7e76245b1 100644
--- a/sources/shiboken6/tests/samplebinding/conversion_operator_test.py
+++ b/sources/shiboken6/tests/samplebinding/conversion_operator_test.py
@@ -15,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()
@@ -30,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 0a0533a41..db539d1b9 100644
--- a/sources/shiboken6/tests/samplebinding/copy_test.py
+++ b/sources/shiboken6/tests/samplebinding/copy_test.py
@@ -63,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 0ad21e35c..5e2695d72 100644
--- a/sources/shiboken6/tests/samplebinding/ctorconvrule_test.py
+++ b/sources/shiboken6/tests/samplebinding/ctorconvrule_test.py
@@ -15,6 +15,7 @@ init_paths()
from sample import CtorConvRule
+
class TestCtorConvRule(unittest.TestCase):
'''Simple test case for CtorConvRule'''
@@ -24,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 b72e41b19..4e4ae2603 100644
--- a/sources/shiboken6/tests/samplebinding/cyclic_test.py
+++ b/sources/shiboken6/tests/samplebinding/cyclic_test.py
@@ -16,7 +16,6 @@ from sample import ObjectView
from sample import ObjectModel
-
class ObjTest(unittest.TestCase):
def test_cyclic_dependency_withParent(self):
@@ -37,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
@@ -70,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
@@ -85,6 +84,6 @@ class ObjTest(unittest.TestCase):
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 a35861c8c..2b6efcf18 100644
--- a/sources/shiboken6/tests/samplebinding/date_test.py
+++ b/sources/shiboken6/tests/samplebinding/date_test.py
@@ -16,6 +16,7 @@ from datetime import date
from sample import SbkDate
+
class DateConversionTest(unittest.TestCase):
def testConstructorWithDateObject(self):
@@ -32,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 6c7b4482d..0d39c5f96 100644
--- a/sources/shiboken6/tests/samplebinding/decisor_test.py
+++ b/sources/shiboken6/tests/samplebinding/decisor_test.py
@@ -15,6 +15,7 @@ init_paths()
from sample import SampleNamespace, Point, ObjectType, ObjectModel
+
class DecisorTest(unittest.TestCase):
'''Test cases for the method overload decisor.'''
@@ -37,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 5a4ee090e..57a792ae2 100644
--- a/sources/shiboken6/tests/samplebinding/delete_test.py
+++ b/sources/shiboken6/tests/samplebinding/delete_test.py
@@ -14,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 95b07f838..c371df94f 100644
--- a/sources/shiboken6/tests/samplebinding/deprecated_test.py
+++ b/sources/shiboken6/tests/samplebinding/deprecated_test.py
@@ -14,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 2d5eb4293..346f29136 100644
--- a/sources/shiboken6/tests/samplebinding/derived_test.py
+++ b/sources/shiboken6/tests/samplebinding/derived_test.py
@@ -16,6 +16,7 @@ init_paths()
import sample
from sample import Abstract, Derived, DerivedUsingCt, OverloadedFuncEnum
+
class Deviant(Derived):
def __init__(self):
Derived.__init__(self)
@@ -31,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'''
@@ -40,24 +51,6 @@ class DerivedTest(unittest.TestCase):
'id_', 'pureVirtual', 'unpureVirtual'])
self.assertTrue(inherited_methods.issubset(dir(Derived)))
- @unittest.skipIf(sys.pyside63_option_python_enum, "Makes no sense with strict Enums")
- 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)
-
- @unittest.skipIf(sys.pyside63_option_python_enum, "Makes no sense with strict Enums")
def testOtherOverloadedMethodCall(self):
'''Another test to check overloaded method calling, just to double check.'''
derived = Derived()
@@ -70,27 +63,28 @@ class DerivedTest(unittest.TestCase):
self.assertEqual(type(result), Derived.OtherOverloadedFuncEnum)
self.assertEqual(result, Derived.OtherOverloadedFunc_id)
- @unittest.skipIf(sys.pyside63_option_python_enum, "Makes no sense with strict Enums")
def testOverloadedMethodCallWithDifferentNumericTypes(self):
'''Test if the correct overloaded method accepts a different numeric type as argument.'''
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)
@@ -102,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')
@@ -126,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)
@@ -135,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 e1d89e2c0..aa21a0f7e 100644
--- a/sources/shiboken6/tests/samplebinding/duck_punching_test.py
+++ b/sources/shiboken6/tests/samplebinding/duck_punching_test.py
@@ -16,6 +16,7 @@ init_paths()
from sample import VirtualMethods, SimpleFile, Point
+
def MethodTypeCompat(func, instance):
return types.MethodType(func, instance)
@@ -24,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").'''
@@ -56,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
@@ -66,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
@@ -85,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
@@ -150,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 567d1452a..f1859260e 100644
--- a/sources/shiboken6/tests/samplebinding/echo_test.py
+++ b/sources/shiboken6/tests/samplebinding/echo_test.py
@@ -15,6 +15,7 @@ init_paths()
from sample import Echo
+
class TestEcho(unittest.TestCase):
'''Simple test case for Echo.echo'''
@@ -26,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 9284257f0..276b8d894 100644
--- a/sources/shiboken6/tests/samplebinding/enum_test.py
+++ b/sources/shiboken6/tests/samplebinding/enum_test.py
@@ -13,35 +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.'''
- @unittest.skipIf(sys.pyside63_option_python_enum, "test not suitable for Python enum")
- 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.__members__ if sys.pyside63_option_python_enum
- else 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)
@@ -54,13 +46,11 @@ class EnumTest(unittest.TestCase):
'''Tries to build the proper enum using an integer.'''
SampleNamespace.getNumber(SampleNamespace.Option(1))
- @unittest.skipIf(sys.pyside63_option_python_enum, "test not suitable for Python enum")
def testBuildingEnumWithDefaultValue(self):
'''Enum constructor with default value'''
enum = SampleNamespace.Option()
self.assertEqual(enum, SampleNamespace.None_)
- @unittest.skipIf(sys.pyside63_option_python_enum, "test not suitable for Python enum")
def testEnumConversionToAndFromPython(self):
'''Conversion of enum objects from Python to C++ back again.'''
enumout = SampleNamespace.enumInEnumOut(SampleNamespace.TwoIn)
@@ -69,7 +59,7 @@ 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.'''
@@ -77,8 +67,10 @@ class EnumTest(unittest.TestCase):
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):
@@ -103,55 +95,25 @@ class EnumTest(unittest.TestCase):
self.assertEqual(event.eventType(), Event.BASIC_EVENT)
event.setEventTypeByConstRef(Event.SOME_EVENT)
self.assertEqual(event.eventType(), Event.SOME_EVENT)
-
- @unittest.skipIf(sys.pyside63_option_python_enum, "test not suitable for Python enum")
- 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)
-
- @unittest.skipIf(sys.pyside63_option_python_enum, "test not suitable for Python enum")
- 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(3 if sys.pyside63_option_python_enum else 999))
+ Event.__init__(self, Event.EventType(3))
class OutOfBoundsTest(unittest.TestCase):
def testValue(self):
e = MyEvent()
- self.assertEqual(repr(e.eventType()), "<EventType.ANY_EVENT: 3>"
- if sys.pyside63_option_python_enum else 'sample.Event.EventType(999)')
-
- @unittest.skipIf(sys.pyside63_option_python_enum, "test not suitable for Python enum")
- def testNoneName(self):
- e = MyEvent()
- t = e.eventType()
- self.assertEqual(t.name, None)
+ self.assertEqual(repr(e.eventType()), "<EventType.ANY_EVENT: 3>")
class EnumOverloadTest(unittest.TestCase):
@@ -174,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 f70621c59..42ae23961 100644
--- a/sources/shiboken6/tests/samplebinding/enumfromremovednamespace_test.py
+++ b/sources/shiboken6/tests/samplebinding/enumfromremovednamespace_test.py
@@ -14,23 +14,11 @@ init_paths()
import sample
from shiboken_test_helper import objectFullname
-from shiboken6 import Shiboken
-_init_pyside_extension() # trigger bootstrap
-
from shibokensupport.signature import get_signature
class TestEnumFromRemovedNamespace(unittest.TestCase):
- @unittest.skipIf(sys.pyside63_option_python_enum, "Makes no sense with strict Enums")
- 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
self.assertEqual(objectFullname(sample.RemovedNamespace1_Enum),
@@ -56,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 e61656400..8e13d5d46 100644
--- a/sources/shiboken6/tests/samplebinding/event_loop_call_virtual_test.py
+++ b/sources/shiboken6/tests/samplebinding/event_loop_call_virtual_test.py
@@ -6,14 +6,12 @@
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
@@ -41,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 2cd1c8d0a..8b854fca6 100644
--- a/sources/shiboken6/tests/samplebinding/event_loop_thread_test.py
+++ b/sources/shiboken6/tests/samplebinding/event_loop_thread_test.py
@@ -64,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 d502609bf..d9e6b377f 100644
--- a/sources/shiboken6/tests/samplebinding/exception_test.py
+++ b/sources/shiboken6/tests/samplebinding/exception_test.py
@@ -13,6 +13,7 @@ init_paths()
from sample import ExceptionTest
+
class CppExceptionTest(unittest.TestCase):
def testVoid(self):
@@ -23,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)
@@ -39,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 86c5fba2a..df805093f 100644
--- a/sources/shiboken6/tests/samplebinding/filter_test.py
+++ b/sources/shiboken6/tests/samplebinding/filter_test.py
@@ -12,6 +12,7 @@ init_paths()
from sample import Data, Intersection, Union
+
class TestFilters(unittest.TestCase):
def testAnd(self):
@@ -23,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 f73fdd503..64806417a 100644
--- a/sources/shiboken6/tests/samplebinding/global.h
+++ b/sources/shiboken6/tests/samplebinding/global.h
@@ -56,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 273915719..af22328c5 100644
--- a/sources/shiboken6/tests/samplebinding/handleholder_test.py
+++ b/sources/shiboken6/tests/samplebinding/handleholder_test.py
@@ -17,6 +17,7 @@ init_paths()
from sample import HandleHolder
+
class HandleHolderTest(unittest.TestCase):
def testCreation(self):
holder = HandleHolder(HandleHolder.createHandle())
@@ -33,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 20d3d2edd..c41f5cc06 100644
--- a/sources/shiboken6/tests/samplebinding/hashabletype_test.py
+++ b/sources/shiboken6/tests/samplebinding/hashabletype_test.py
@@ -13,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):
@@ -29,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 89df035a3..feb78d045 100644
--- a/sources/shiboken6/tests/samplebinding/ignorederefop_test.py
+++ b/sources/shiboken6/tests/samplebinding/ignorederefop_test.py
@@ -9,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 c5c7bc0d1..081666281 100644
--- a/sources/shiboken6/tests/samplebinding/implicitconv_numerical_test.py
+++ b/sources/shiboken6/tests/samplebinding/implicitconv_numerical_test.py
@@ -27,6 +27,7 @@ if is64bitArchitecture and sys.platform != 'win32':
cLongMin = -9223372036854775808
cLongMax = 9223372036854775807
+
class NumericTester(unittest.TestCase):
'''Helper class for numeric comparison testing'''
diff --git a/sources/shiboken6/tests/samplebinding/implicitconv_test.py b/sources/shiboken6/tests/samplebinding/implicitconv_test.py
index 96cad9c69..ebafe0c52 100644
--- a/sources/shiboken6/tests/samplebinding/implicitconv_test.py
+++ b/sources/shiboken6/tests/samplebinding/implicitconv_test.py
@@ -15,6 +15,7 @@ init_paths()
from sample import ImplicitConv, ObjectType
+
class ImplicitConvTest(unittest.TestCase):
'''Test case for implicit conversions'''
@@ -43,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 7ae676102..28d62486a 100644
--- a/sources/shiboken6/tests/samplebinding/inheritanceandscope_test.py
+++ b/sources/shiboken6/tests/samplebinding/inheritanceandscope_test.py
@@ -15,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 90225a039..f673a7807 100644
--- a/sources/shiboken6/tests/samplebinding/injectcode_test.py
+++ b/sources/shiboken6/tests/samplebinding/injectcode_test.py
@@ -14,6 +14,7 @@ from shiboken_paths import init_paths
init_paths()
from sample import InjectCode
+
class MyInjectCode(InjectCode):
def __init__(self):
InjectCode.__init__(self)
@@ -22,10 +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")
+ "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.")
@@ -71,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):
@@ -110,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 f94c57750..721f33483 100644
--- a/sources/shiboken6/tests/samplebinding/innerclass_test.py
+++ b/sources/shiboken6/tests/samplebinding/innerclass_test.py
@@ -13,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 41d2b659a..defa9ca71 100644
--- a/sources/shiboken6/tests/samplebinding/intlist_test.py
+++ b/sources/shiboken6/tests/samplebinding/intlist_test.py
@@ -13,6 +13,7 @@ init_paths()
from sample import IntList
+
class IntListTest(unittest.TestCase):
def testAutoFunctionsToBaseList(self):
@@ -74,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
index 21cab6b35..d883adf47 100644
--- a/sources/shiboken6/tests/samplebinding/intwrapper_test.py
+++ b/sources/shiboken6/tests/samplebinding/intwrapper_test.py
@@ -16,8 +16,8 @@ from sample import IntWrapper
class IntWrapperTest(unittest.TestCase):
def testOperators(self):
- ten1 = IntWrapper(10)
- ten2 = IntWrapper(10)
+ ten1 = IntWrapper(10)
+ ten2 = IntWrapper(10)
twenty = IntWrapper(20)
self.assertTrue(ten1 == ten2)
self.assertTrue(ten1 != twenty)
diff --git a/sources/shiboken6/tests/samplebinding/invalid_virtual_return_test.py b/sources/shiboken6/tests/samplebinding/invalid_virtual_return_test.py
index e3d060430..bb35b2bb1 100644
--- a/sources/shiboken6/tests/samplebinding/invalid_virtual_return_test.py
+++ b/sources/shiboken6/tests/samplebinding/invalid_virtual_return_test.py
@@ -38,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 6cf416fc4..10591fec6 100644
--- a/sources/shiboken6/tests/samplebinding/keep_reference_test.py
+++ b/sources/shiboken6/tests/samplebinding/keep_reference_test.py
@@ -2,8 +2,6 @@
# 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
import unittest
@@ -15,8 +13,10 @@ 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):
@@ -48,15 +48,16 @@ class TestKeepReference(unittest.TestCase):
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 6eb975b9f..b668bfd90 100644
--- a/sources/shiboken6/tests/samplebinding/list_test.py
+++ b/sources/shiboken6/tests/samplebinding/list_test.py
@@ -15,6 +15,7 @@ init_paths()
from sample import ListUser, Point, PointF
+
class ExtendedListUser(ListUser):
def __init__(self):
ListUser.__init__(self)
@@ -24,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'''
@@ -69,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)
@@ -96,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 0657d41b9..acd47634a 100644
--- a/sources/shiboken6/tests/samplebinding/lock_test.py
+++ b/sources/shiboken6/tests/samplebinding/lock_test.py
@@ -63,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)
@@ -72,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 5ffed5ede..fa99ad2e7 100644
--- a/sources/shiboken6/tests/samplebinding/map_test.py
+++ b/sources/shiboken6/tests/samplebinding/map_test.py
@@ -15,6 +15,7 @@ init_paths()
from sample import MapUser
+
class ExtendedMapUser(MapUser):
def __init__(self):
MapUser.__init__(self)
@@ -22,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'''
@@ -44,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_)
@@ -52,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 787bace70..4d7eeda96 100644
--- a/sources/shiboken6/tests/samplebinding/metaclass_test.py
+++ b/sources/shiboken6/tests/samplebinding/metaclass_test.py
@@ -10,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/mixed_mi_test.py b/sources/shiboken6/tests/samplebinding/mixed_mi_test.py
index 776605a4d..fa8481600 100644
--- a/sources/shiboken6/tests/samplebinding/mixed_mi_test.py
+++ b/sources/shiboken6/tests/samplebinding/mixed_mi_test.py
@@ -52,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 725105a9c..e23503eff 100644
--- a/sources/shiboken6/tests/samplebinding/modelindex_test.py
+++ b/sources/shiboken6/tests/samplebinding/modelindex_test.py
@@ -13,6 +13,7 @@ init_paths()
from sample import ModelIndex, ReferentModelIndex, PersistentModelIndex
+
class TestCastOperator(unittest.TestCase):
def testCastOperatorReturningValue(self):
@@ -30,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 0b5c657d9..b5663a04e 100644
--- a/sources/shiboken6/tests/samplebinding/modelview_test.py
+++ b/sources/shiboken6/tests/samplebinding/modelview_test.py
@@ -2,7 +2,8 @@
# 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).'''
+'''Test case for objects that keep references to other object without owning them
+ (e.g. model/view relationships).'''
import os
import sys
@@ -17,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)
@@ -29,6 +32,7 @@ class ListModelKeepsReference(ObjectModel):
def data(self):
return self.obj
+
class ListModelDoesntKeepsReference(ObjectModel):
def data(self):
obj = MyObject()
@@ -55,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 d1e70004f..dced14396 100644
--- a/sources/shiboken6/tests/samplebinding/modifications_test.py
+++ b/sources/shiboken6/tests/samplebinding/modifications_test.py
@@ -16,6 +16,7 @@ init_paths()
from sample import Modifications, Point, ByteArray
+
class ExtModifications(Modifications):
def __init__(self):
Modifications.__init__(self)
@@ -41,25 +42,15 @@ class ModificationsTest(unittest.TestCase):
# PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
gc.collect()
- @unittest.skipIf(sys.pyside63_option_python_enum, "Makes no sense with strict Enums")
- 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)))
-
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')
@@ -80,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);
@@ -94,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)
@@ -110,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)
@@ -124,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 d4b65a88a..9791a3491 100644
--- a/sources/shiboken6/tests/samplebinding/modified_constructor_test.py
+++ b/sources/shiboken6/tests/samplebinding/modified_constructor_test.py
@@ -4,7 +4,6 @@
'''Tests cases for ConstructorWithModifiedArgument class.'''
-import sys
import os
import sys
import unittest
@@ -14,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):
@@ -24,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 ae090f8e3..dcb487f1a 100644
--- a/sources/shiboken6/tests/samplebinding/modifiedvirtualmethods_test.py
+++ b/sources/shiboken6/tests/samplebinding/modifiedvirtualmethods_test.py
@@ -16,6 +16,7 @@ init_paths()
from sample import VirtualMethods, Str
+
class ExtendedVirtualMethods(VirtualMethods):
def __init__(self):
VirtualMethods.__init__(self)
@@ -61,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):
@@ -185,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):
@@ -217,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 e655b8051..fc6b26c3f 100644
--- a/sources/shiboken6/tests/samplebinding/multi_cpp_inheritance_test.py
+++ b/sources/shiboken6/tests/samplebinding/multi_cpp_inheritance_test.py
@@ -13,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 46e44601d..7497714a8 100644
--- a/sources/shiboken6/tests/samplebinding/multiple_derived_test.py
+++ b/sources/shiboken6/tests/samplebinding/multiple_derived_test.py
@@ -13,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'''
@@ -40,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))
@@ -60,14 +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()
@@ -80,7 +88,8 @@ class MultipleDerivedTest(unittest.TestCase):
@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()
@@ -95,7 +104,8 @@ class MultipleDerivedTest(unittest.TestCase):
@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()
@@ -116,7 +126,8 @@ class MultipleDerivedTest(unittest.TestCase):
@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()
@@ -135,7 +146,8 @@ class MultipleDerivedTest(unittest.TestCase):
@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()
@@ -166,7 +178,8 @@ class MultipleDerivedTest(unittest.TestCase):
@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()
@@ -179,7 +192,8 @@ class MultipleDerivedTest(unittest.TestCase):
@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()
@@ -192,7 +206,8 @@ class MultipleDerivedTest(unittest.TestCase):
@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()
@@ -203,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 a7833c921..64a6792ac 100644
--- a/sources/shiboken6/tests/samplebinding/namespace_test.py
+++ b/sources/shiboken6/tests/samplebinding/namespace_test.py
@@ -13,12 +13,9 @@ 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 shiboken6 import Shiboken
-_init_pyside_extension() # trigger bootstrap
-
from shibokensupport.signature import get_signature
# For tests of invisible namespaces, see
@@ -27,25 +24,17 @@ from shibokensupport.signature import get_signature
class TestVariablesUnderNamespace(unittest.TestCase):
def testIt(self):
- self.assertEqual(SampleNamespace.variableInNamespace, 42)
+ self.assertEqual(SampleNamespace.variableInNamespace, 42)
class TestClassesUnderNamespace(unittest.TestCase):
def testIt(self):
- if sys.pyside63_option_python_enum:
- c1 = SampleNamespace.SomeClass()
- e1 = SampleNamespace.SomeClass.ProtectedEnum(0)
- c2 = SampleNamespace.SomeClass.SomeInnerClass()
- e2 = SampleNamespace.SomeClass.SomeInnerClass.ProtectedEnum(0)
- c3 = SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough()
- e3 = SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough.NiceEnum(0)
- else:
- 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)
@@ -53,24 +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),
- "<enum 'ProtectedEnum'>" if sys.pyside63_option_python_enum else
- "<class 'sample.SampleNamespace.SomeClass.ProtectedEnum'>")
+ "<enum 'ProtectedEnum'>")
self.assertEqual(str(SampleNamespace.SomeClass.SomeInnerClass.ProtectedEnum),
- "<enum 'ProtectedEnum'>" if sys.pyside63_option_python_enum else
- "<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),
- "<enum 'NiceEnum'>" if sys.pyside63_option_python_enum else
- "<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(get_signature(SampleNamespace.enumInEnumOut).parameters['in_'].annotation),
- "sample.SampleNamespace.InValue")
- self.assertEqual(objectFullname(get_signature(SampleNamespace.enumAsInt).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 6286dcfc9..0e7dfbee1 100644
--- a/sources/shiboken6/tests/samplebinding/newdivision_test.py
+++ b/sources/shiboken6/tests/samplebinding/newdivision_test.py
@@ -10,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 3892508ae..bc8d29e50 100644
--- a/sources/shiboken6/tests/samplebinding/nondefaultctor_test.py
+++ b/sources/shiboken6/tests/samplebinding/nondefaultctor_test.py
@@ -15,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):
@@ -43,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 fa28abc6d..a10547728 100644
--- a/sources/shiboken6/tests/samplebinding/nontypetemplate_test.py
+++ b/sources/shiboken6/tests/samplebinding/nontypetemplate_test.py
@@ -21,6 +21,7 @@ init_paths()
from sample import IntArray2, IntArray3
+
class NonTypeTemplateTest(unittest.TestCase):
def testNonTypeTemplate(self):
@@ -32,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 d2a30c7ef..7be239fc4 100644
--- a/sources/shiboken6/tests/samplebinding/nonzero_test.py
+++ b/sources/shiboken6/tests/samplebinding/nonzero_test.py
@@ -13,6 +13,7 @@ init_paths()
from sample import Color, Brush
+
class TestNonZeroOperator(unittest.TestCase):
def testColor(self):
"""Color has a Qt-style isNull()"""
diff --git a/sources/shiboken6/tests/samplebinding/numericaltypedef_test.py b/sources/shiboken6/tests/samplebinding/numericaltypedef_test.py
index 9539469a1..f714a4fc8 100644
--- a/sources/shiboken6/tests/samplebinding/numericaltypedef_test.py
+++ b/sources/shiboken6/tests/samplebinding/numericaltypedef_test.py
@@ -13,6 +13,7 @@ init_paths()
from sample import SizeF
+
class NumericalTypedefTest(unittest.TestCase):
def testNumericalTypedefExact(self):
@@ -32,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 af1e6d1bf..42094a463 100644
--- a/sources/shiboken6/tests/samplebinding/numpy_test.py
+++ b/sources/shiboken6/tests/samplebinding/numpy_test.py
@@ -8,7 +8,7 @@ try:
if bool(sysconfig.get_config_var('Py_DEBUG')):
sys.exit(0)
import numpy
-except:
+except: # noqa: E722
sys.exit(0)
import os
@@ -21,6 +21,7 @@ from shiboken_paths import init_paths
init_paths()
from sample import PointF
+
class TestNumpyTypes(unittest.TestCase):
def testNumpyConverted(self):
@@ -35,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 6e90bfb35..ead68ba13 100644
--- a/sources/shiboken6/tests/samplebinding/objecttype_test.py
+++ b/sources/shiboken6/tests/samplebinding/objecttype_test.py
@@ -68,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)
@@ -105,5 +105,6 @@ class ObjectTypeTest(unittest.TestCase):
with self.assertRaises(AttributeError):
o.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 4e552e887..285e2313b 100644
--- a/sources/shiboken6/tests/samplebinding/objecttype_with_named_args_test.py
+++ b/sources/shiboken6/tests/samplebinding/objecttype_with_named_args_test.py
@@ -13,6 +13,7 @@ init_paths()
from sample import ObjectType
+
class NamedArgsTest(unittest.TestCase):
def testOneArgument(self):
@@ -35,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 9dd3baf63..8f74af3ab 100644
--- a/sources/shiboken6/tests/samplebinding/objecttypebyvalue_test.py
+++ b/sources/shiboken6/tests/samplebinding/objecttypebyvalue_test.py
@@ -10,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):
@@ -22,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 ea30f103e..677b89281 100644
--- a/sources/shiboken6/tests/samplebinding/objecttypelayout_test.py
+++ b/sources/shiboken6/tests/samplebinding/objecttypelayout_test.py
@@ -14,7 +14,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 ObjectType, ObjectTypeLayout
class ObjectTypeLayoutTest(unittest.TestCase):
@@ -22,16 +22,15 @@ class ObjectTypeLayoutTest(unittest.TestCase):
@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()
@@ -57,7 +56,7 @@ 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()
@@ -81,7 +80,7 @@ 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()
@@ -91,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()
@@ -154,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()
@@ -192,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()
@@ -243,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()
@@ -294,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 ae5936635..ceeee6c8d 100644
--- a/sources/shiboken6/tests/samplebinding/objecttypeoperators_test.py
+++ b/sources/shiboken6/tests/samplebinding/objecttypeoperators_test.py
@@ -10,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):
@@ -26,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)
@@ -36,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 68e5edecc..5fa6f824e 100644
--- a/sources/shiboken6/tests/samplebinding/objecttypereferenceasvirtualmethodargument_test.py
+++ b/sources/shiboken6/tests/samplebinding/objecttypereferenceasvirtualmethodargument_test.py
@@ -12,6 +12,7 @@ from shiboken_paths import init_paths
init_paths()
from sample import ObjectTypeHolder
+
class TestObjectTypeReferenceAsVirtualMethodArgument(unittest.TestCase):
def testBasic(self):
@@ -25,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 466ddba82..87a8cdb1f 100644
--- a/sources/shiboken6/tests/samplebinding/oddbool_test.py
+++ b/sources/shiboken6/tests/samplebinding/oddbool_test.py
@@ -15,11 +15,13 @@ init_paths()
from sample import OddBoolUser, ComparisonTester, SpaceshipComparisonTester
+
class DerivedOddBoolUser (OddBoolUser):
def returnMyselfVirtual(self):
return OddBoolUser()
pass
+
class OddBoolTest(unittest.TestCase):
def testOddBoolUser(self):
@@ -30,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()
diff --git a/sources/shiboken6/tests/samplebinding/onlycopyclass_test.py b/sources/shiboken6/tests/samplebinding/onlycopyclass_test.py
index 3bdf431ad..bcb154c52 100644
--- a/sources/shiboken6/tests/samplebinding/onlycopyclass_test.py
+++ b/sources/shiboken6/tests/samplebinding/onlycopyclass_test.py
@@ -13,6 +13,7 @@ init_paths()
from sample import OnlyCopy, FriendOfOnlyCopy
+
class ClassWithOnlyCopyCtorTest(unittest.TestCase):
def testGetOne(self):
obj = FriendOfOnlyCopy.createOnlyCopy(123)
@@ -34,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 bb98f313d..84442306a 100644
--- a/sources/shiboken6/tests/samplebinding/overflow_test.py
+++ b/sources/shiboken6/tests/samplebinding/overflow_test.py
@@ -13,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 (Point, doubleLongLong, doubleShort, doubleUnsignedInt,
+ doubleUnsignedLongLong)
class OverflowTest(unittest.TestCase):
@@ -25,14 +26,16 @@ class OverflowTest(unittest.TestCase):
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)
@@ -41,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)
@@ -59,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 03da96581..060d91510 100644
--- a/sources/shiboken6/tests/samplebinding/overload_sorting_test.py
+++ b/sources/shiboken6/tests/samplebinding/overload_sorting_test.py
@@ -13,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):
@@ -63,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 d6bd90877..62fa8d8d2 100644
--- a/sources/shiboken6/tests/samplebinding/overload_test.py
+++ b/sources/shiboken6/tests/samplebinding/overload_test.py
@@ -21,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
@@ -178,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 199297415..269b97299 100644
--- a/sources/shiboken6/tests/samplebinding/overloadwithdefault_test.py
+++ b/sources/shiboken6/tests/samplebinding/overloadwithdefault_test.py
@@ -39,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 8a3cdf490..8a55d3ab8 100644
--- a/sources/shiboken6/tests/samplebinding/ownership_argument_invalidation_test.py
+++ b/sources/shiboken6/tests/samplebinding/ownership_argument_invalidation_test.py
@@ -15,6 +15,7 @@ init_paths()
from sample import Polygon, Point
+
class WrapperValidityOfArgumentsTest(unittest.TestCase):
'''Wrapper validity tests for arguments.'''
@@ -25,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 2c789a72a..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
@@ -30,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 b6f5ce235..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
@@ -35,5 +35,6 @@ class DeleteChildInPython(unittest.TestCase):
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 044ef9af6..8f654639c 100644
--- a/sources/shiboken6/tests/samplebinding/ownership_delete_parent_test.py
+++ b/sources/shiboken6/tests/samplebinding/ownership_delete_parent_test.py
@@ -33,7 +33,7 @@ class DeleteParentTest(unittest.TestCase):
# 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):
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 e51b5555f..37b7591e4 100644
--- a/sources/shiboken6/tests/samplebinding/ownership_invalidate_after_use_test.py
+++ b/sources/shiboken6/tests/samplebinding/ownership_invalidate_after_use_test.py
@@ -21,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__()
@@ -35,7 +37,7 @@ class MyObjectType (ObjectType):
self.callInvalidateEvent(ev)
try:
ev.eventType()
- except:
+ except: # noqa: E722
self.fail = True
raise
return True
@@ -43,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)
@@ -84,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 868c85931..77b7c576c 100644
--- a/sources/shiboken6/tests/samplebinding/ownership_invalidate_child_test.py
+++ b/sources/shiboken6/tests/samplebinding/ownership_invalidate_child_test.py
@@ -49,6 +49,6 @@ class InvalidateChildTest(unittest.TestCase):
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 66d6ed5d2..8cbefc30c 100644
--- a/sources/shiboken6/tests/samplebinding/ownership_invalidate_nonpolymorphic_test.py
+++ b/sources/shiboken6/tests/samplebinding/ownership_invalidate_nonpolymorphic_test.py
@@ -15,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++.'''
@@ -27,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 82ecafa7d..c721a212c 100644
--- a/sources/shiboken6/tests/samplebinding/ownership_invalidate_parent_test.py
+++ b/sources/shiboken6/tests/samplebinding/ownership_invalidate_parent_test.py
@@ -34,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
@@ -43,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 acacbf461..304223063 100644
--- a/sources/shiboken6/tests/samplebinding/ownership_reparenting_test.py
+++ b/sources/shiboken6/tests/samplebinding/ownership_reparenting_test.py
@@ -16,6 +16,7 @@ import sys
from sample import ObjectType
+
class ExtObjectType(ObjectType):
def __init__(self):
ObjectType.__init__(self)
@@ -108,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 d1eccb4f6..0e9f08b72 100644
--- a/sources/shiboken6/tests/samplebinding/ownership_transference_test.py
+++ b/sources/shiboken6/tests/samplebinding/ownership_transference_test.py
@@ -16,6 +16,7 @@ init_paths()
from sample import ObjectType, BlackBox
+
class BlackBoxTest(unittest.TestCase):
'''The BlackBox class has cases of ownership transference between C++ and Python.'''
@@ -29,12 +30,13 @@ 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)
@@ -48,9 +50,9 @@ 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)
@@ -59,11 +61,11 @@ class BlackBoxTest(unittest.TestCase):
'''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 278219434..4bd5c697c 100644
--- a/sources/shiboken6/tests/samplebinding/pair_test.py
+++ b/sources/shiboken6/tests/samplebinding/pair_test.py
@@ -15,6 +15,7 @@ init_paths()
from sample import PairUser
+
class ExtendedPairUser(PairUser):
def __init__(self):
PairUser.__init__(self)
@@ -24,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'''
@@ -48,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)
@@ -71,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)
@@ -79,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 88684dc38..106f3bd61 100644
--- a/sources/shiboken6/tests/samplebinding/pen_test.py
+++ b/sources/shiboken6/tests/samplebinding/pen_test.py
@@ -15,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 5e7415395..f86c0f423 100644
--- a/sources/shiboken6/tests/samplebinding/point_test.py
+++ b/sources/shiboken6/tests/samplebinding/point_test.py
@@ -15,6 +15,7 @@ init_paths()
from sample import Point
+
class PointTest(unittest.TestCase):
'''Test case for Point class, including operator overloads.'''
@@ -92,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 be2faa118..633525a9c 100644
--- a/sources/shiboken6/tests/samplebinding/pointerholder_test.py
+++ b/sources/shiboken6/tests/samplebinding/pointerholder_test.py
@@ -15,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')
@@ -31,9 +33,9 @@ class TestPointerHolder(unittest.TestCase):
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 41a9774e3..4da1a89c6 100644
--- a/sources/shiboken6/tests/samplebinding/pointerprimitivetype_test.py
+++ b/sources/shiboken6/tests/samplebinding/pointerprimitivetype_test.py
@@ -27,8 +27,6 @@ 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 get_signature
import typing
@@ -39,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
diff --git a/sources/shiboken6/tests/samplebinding/pointf_test.py b/sources/shiboken6/tests/samplebinding/pointf_test.py
index 53616aecb..91c58eb1d 100644
--- a/sources/shiboken6/tests/samplebinding/pointf_test.py
+++ b/sources/shiboken6/tests/samplebinding/pointf_test.py
@@ -15,6 +15,7 @@ init_paths()
from sample import PointF
+
class PointFTest(unittest.TestCase):
'''Test case for PointF class, including operator overloads.'''
@@ -45,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 45cf534a6..0b9fe2249 100644
--- a/sources/shiboken6/tests/samplebinding/primitivereferenceargument_test.py
+++ b/sources/shiboken6/tests/samplebinding/primitivereferenceargument_test.py
@@ -12,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)
@@ -25,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 235882997..63040388d 100644
--- a/sources/shiboken6/tests/samplebinding/privatector_test.py
+++ b/sources/shiboken6/tests/samplebinding/privatector_test.py
@@ -64,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 777a9923b..651f63b15 100644
--- a/sources/shiboken6/tests/samplebinding/privatedtor_test.py
+++ b/sources/shiboken6/tests/samplebinding/privatedtor_test.py
@@ -80,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 9538125f5..e4ccf721d 100644
--- a/sources/shiboken6/tests/samplebinding/protected_test.py
+++ b/sources/shiboken6/tests/samplebinding/protected_test.py
@@ -16,42 +16,51 @@ 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.'''
@@ -81,6 +90,7 @@ 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.'''
@@ -110,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.'''
@@ -153,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.'''
@@ -200,15 +213,18 @@ class ProtectedVirtualDtorTest(unittest.TestCase):
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.'''
@@ -223,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):
@@ -361,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 a257d5944..d60f9cf35 100644
--- a/sources/shiboken6/tests/samplebinding/pstrlist_test.py
+++ b/sources/shiboken6/tests/samplebinding/pstrlist_test.py
@@ -12,6 +12,7 @@ from shiboken_paths import init_paths
init_paths()
import sample
+
class PStrListTest(unittest.TestCase):
def testPStrList(self):
@@ -26,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 3472457e8..ec64c1e31 100644
--- a/sources/shiboken6/tests/samplebinding/pystr_test.py
+++ b/sources/shiboken6/tests/samplebinding/pystr_test.py
@@ -15,6 +15,7 @@ init_paths()
from sample import Point
+
class PyStrTest(unittest.TestCase):
'''Test case for definition of __str__ method.'''
@@ -23,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 03a75b824..65398b5c6 100644
--- a/sources/shiboken6/tests/samplebinding/python_thread_test.py
+++ b/sources/shiboken6/tests/samplebinding/python_thread_test.py
@@ -36,7 +36,7 @@ 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(f'PRODUCER - pushed {value}')
@@ -66,6 +66,7 @@ class Consumer(threading.Thread):
logging.debug('CONSUMER - empty bucket')
time.sleep(0.01)
+
class ProducerConsumer(unittest.TestCase):
'''Basic test case for producer-consumer QThread'''
@@ -91,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 f8c7f017d..1d19de941 100644
--- a/sources/shiboken6/tests/samplebinding/receive_null_cstring_test.py
+++ b/sources/shiboken6/tests/samplebinding/receive_null_cstring_test.py
@@ -15,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.'''
@@ -29,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 e590a7e4e..1b6dd3a7a 100644
--- a/sources/shiboken6/tests/samplebinding/reference_test.py
+++ b/sources/shiboken6/tests/samplebinding/reference_test.py
@@ -13,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):
@@ -48,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.'''
@@ -57,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)
@@ -88,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)
@@ -96,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 94bb1608b..942c7ea29 100644
--- a/sources/shiboken6/tests/samplebinding/referencetopointer_test.py
+++ b/sources/shiboken6/tests/samplebinding/referencetopointer_test.py
@@ -15,6 +15,7 @@ init_paths()
from sample import VirtualMethods, Str
+
class ExtendedVirtualMethods(VirtualMethods):
def __init__(self):
VirtualMethods.__init__(self)
@@ -72,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 2d6b95a45..b08438ef3 100644
--- a/sources/shiboken6/tests/samplebinding/renaming_test.py
+++ b/sources/shiboken6/tests/samplebinding/renaming_test.py
@@ -16,9 +16,6 @@ init_paths()
from sample import RenamedValue, RenamedUser
-from shiboken6 import Shiboken
-_init_pyside_extension() # trigger bootstrap
-
from shibokensupport.signature import get_signature
@@ -38,6 +35,5 @@ class RenamingTest(unittest.TestCase):
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 46d19e9f7..2c4f07c65 100644
--- a/sources/shiboken6/tests/samplebinding/return_null_test.py
+++ b/sources/shiboken6/tests/samplebinding/return_null_test.py
@@ -13,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.'''
@@ -33,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 e764b41a4..3146d0faf 100644
--- a/sources/shiboken6/tests/samplebinding/richcompare_test.py
+++ b/sources/shiboken6/tests/samplebinding/richcompare_test.py
@@ -11,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):
@@ -22,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 52abc968f..19b2f708d 100644
--- a/sources/shiboken6/tests/samplebinding/sample_test.py
+++ b/sources/shiboken6/tests/samplebinding/sample_test.py
@@ -15,35 +15,10 @@ init_paths()
import sample
+
class ModuleTest(unittest.TestCase):
'''Test case for module and global functions'''
- @unittest.skipIf(sys.pyside63_option_python_enum, "Makes no sense with strict Enums")
- 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)))
-
- @unittest.skipIf(sys.pyside63_option_python_enum, "Makes no sense with strict Enums")
- 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)))
-
- @unittest.skipIf(sys.pyside63_option_python_enum, "Makes no sense with strict Enums")
- 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'
@@ -76,7 +51,26 @@ class ModuleTest(unittest.TestCase):
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
index e71ba3737..43e6b08de 100644
--- a/sources/shiboken6/tests/samplebinding/samplesnippets.cpp
+++ b/sources/shiboken6/tests/samplebinding/samplesnippets.cpp
@@ -3,7 +3,7 @@
// @snippet intwrapper_add_ints
extern "C" {
-static PyObject *Sbk_IntWrapper_add_ints(PyObject *self, PyObject *args)
+static PyObject *Sbk_IntWrapper_add_ints(PyObject * /* self */, PyObject *args)
{
PyObject *result = nullptr;
if (PyTuple_Check(args) != 0 && PyTuple_Size(args) == 2) {
@@ -18,3 +18,37 @@ static PyObject *Sbk_IntWrapper_add_ints(PyObject *self, PyObject *args)
}
}
// @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_test.py b/sources/shiboken6/tests/samplebinding/simplefile_test.py
index 1217bd9a8..55c894a35 100644
--- a/sources/shiboken6/tests/samplebinding/simplefile_test.py
+++ b/sources/shiboken6/tests/samplebinding/simplefile_test.py
@@ -15,6 +15,7 @@ init_paths()
from sample import SimpleFile
+
class SimpleFileTest(unittest.TestCase):
'''Test cases for SimpleFile class.'''
@@ -54,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 179a961d9..069ce59b3 100644
--- a/sources/shiboken6/tests/samplebinding/size_test.py
+++ b/sources/shiboken6/tests/samplebinding/size_test.py
@@ -15,6 +15,7 @@ init_paths()
from sample import Size
+
class PointTest(unittest.TestCase):
'''Test case for Size class, including operator overloads.'''
@@ -94,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/static_nonstatic_methods_test.py b/sources/shiboken6/tests/samplebinding/static_nonstatic_methods_test.py
index e176b3347..cf0889299 100644
--- a/sources/shiboken6/tests/samplebinding/static_nonstatic_methods_test.py
+++ b/sources/shiboken6/tests/samplebinding/static_nonstatic_methods_test.py
@@ -15,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.'''
@@ -79,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 97df76452..c06fd6428 100644
--- a/sources/shiboken6/tests/samplebinding/str_test.py
+++ b/sources/shiboken6/tests/samplebinding/str_test.py
@@ -2,7 +2,8 @@
# 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.'''
+'''Test cases for a method that receives a reference to class that is implicitly
+ convertible from a Python native type.'''
import os
import sys
@@ -15,6 +16,7 @@ init_paths()
from sample import Str
+
class StrTest(unittest.TestCase):
'''Test cases for thr Str class.'''
@@ -31,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))
@@ -90,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 f768f9c63..2bfb80b67 100644
--- a/sources/shiboken6/tests/samplebinding/strlist_test.py
+++ b/sources/shiboken6/tests/samplebinding/strlist_test.py
@@ -15,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>.'''
@@ -88,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 f458ad0d2..11279c7ec 100644
--- a/sources/shiboken6/tests/samplebinding/templateinheritingclass_test.py
+++ b/sources/shiboken6/tests/samplebinding/templateinheritingclass_test.py
@@ -14,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):
@@ -57,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 9b32aaaee..6283a6744 100644
--- a/sources/shiboken6/tests/samplebinding/time_test.py
+++ b/sources/shiboken6/tests/samplebinding/time_test.py
@@ -4,7 +4,6 @@
'''Test cases for constructor and method signature decisor on Time class.'''
-import sys
import os
import sys
import unittest
@@ -17,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
@@ -115,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 a938e6af8..7dfd18a4a 100644
--- a/sources/shiboken6/tests/samplebinding/transform_test.py
+++ b/sources/shiboken6/tests/samplebinding/transform_test.py
@@ -15,6 +15,7 @@ init_paths()
from sample import Point, applyHomogeneousTransform
+
class TransformTest(unittest.TestCase):
'''Test cases for modifying a function with > 9 arguments.'''
@@ -32,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 10b7491b1..987ba6dfd 100644
--- a/sources/shiboken6/tests/samplebinding/typeconverters_test.py
+++ b/sources/shiboken6/tests/samplebinding/typeconverters_test.py
@@ -15,6 +15,7 @@ init_paths()
import sample
+
class GetPythonTypeByNameTest(unittest.TestCase):
'''Uses an added function with inject code that uses the libshiboken
@@ -159,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 1b47c62bc..ce881e802 100644
--- a/sources/shiboken6/tests/samplebinding/typedealloc_test.py
+++ b/sources/shiboken6/tests/samplebinding/typedealloc_test.py
@@ -33,12 +33,16 @@ class TypeDeallocTest(unittest.TestCase):
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)
@@ -46,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)
@@ -54,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 c486f2bcc..ab8e535b5 100644
--- a/sources/shiboken6/tests/samplebinding/typedtordoublefree_test.py
+++ b/sources/shiboken6/tests/samplebinding/typedtordoublefree_test.py
@@ -12,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.'''
@@ -22,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 7583a900a..e315e599e 100644
--- a/sources/shiboken6/tests/samplebinding/typesystem_sample.xml
+++ b/sources/shiboken6/tests/samplebinding/typesystem_sample.xml
@@ -1,12 +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'" />
-
<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>
@@ -74,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>
@@ -84,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">
@@ -168,6 +166,7 @@
%out = %OUTTYPE(str);
</add-conversion>
<add-conversion type="Py_None">
+ SBK_UNUSED(%in)
%out = %OUTTYPE();
</add-conversion>
</target-to-native>
@@ -256,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;
@@ -397,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)" />
@@ -418,6 +419,8 @@
<function signature="addStdStrings(const std::string&amp;, const std::string&amp;)"/>
<function signature="addStdWStrings(const std::wstring&amp;, const std::wstring&amp;)"/>
<function signature="testNullPtrT(std::nullptr_t)"/>
+ <function signature="takePolygon(Polygon&amp;&amp;)"/>
+ <function signature="takeObjectType(ObjectType&amp;&amp;)"/>
<value-type name="ArrayModifyTest">
<modify-function signature="sumIntArray(int, int*)">
@@ -426,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"/>
@@ -454,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"/>
@@ -564,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&amp;)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">
@@ -626,8 +641,8 @@
// CHECKTYPE and ISCONVERTIBLE are used here for test purposes, don't change them.
if (!%CHECKTYPE[ObjectTypeLayout*](layout) &amp;&amp; !%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
@@ -714,7 +729,7 @@
</modify-function>
</object-type>
- <value-type name="ObjectTypeHolder"/>
+ <object-type name="ObjectTypeHolder"/>
<value-type name="OnlyCopy"/>
<value-type name="FriendOfOnlyCopy"/>
@@ -1385,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">
@@ -1887,13 +1902,13 @@
</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&lt;char*>("setHeight"), const_cast&lt;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"/>
@@ -2058,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)">
@@ -2209,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"/>
@@ -2362,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&amp;()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&amp;()const">
+ <modify-argument index="return">
+ <define-ownership owner="c++"/>
+ </modify-argument>
+ </modify-function>
</value-type>
<value-type name="PersistentModelIndex" />
@@ -2383,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&lt;std::pair&lt;BlackBox *, BlackBox *&gt; &gt; &amp;)" rename="dummy_method" />
</object-type>
@@ -2398,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 &quot;Abstract::hideFunction(HideType*)&quot; 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&amp;'" />
-
- <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 &amp; 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 5e54ef6ee..f7f5342ee 100644
--- a/sources/shiboken6/tests/samplebinding/typesystypedef_test.py
+++ b/sources/shiboken6/tests/samplebinding/typesystypedef_test.py
@@ -13,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 dbc4097da..2a7e5cac7 100644
--- a/sources/shiboken6/tests/samplebinding/unsafe_parent_test.py
+++ b/sources/shiboken6/tests/samplebinding/unsafe_parent_test.py
@@ -15,6 +15,7 @@ init_paths()
from sample import ObjectType
+
class DerivedObjectType(ObjectType):
def isPython(self):
return True
@@ -22,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 3aee8d6f7..45d4095b6 100644
--- a/sources/shiboken6/tests/samplebinding/useraddedctor_test.py
+++ b/sources/shiboken6/tests/samplebinding/useraddedctor_test.py
@@ -12,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 69c3479c5..6be870269 100644
--- a/sources/shiboken6/tests/samplebinding/virtualdtor_test.py
+++ b/sources/shiboken6/tests/samplebinding/virtualdtor_test.py
@@ -16,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.'''
@@ -59,4 +61,3 @@ class VirtualDtorTest(unittest.TestCase):
if __name__ == '__main__':
unittest.main()
-
diff --git a/sources/shiboken6/tests/samplebinding/virtualmethods_test.py b/sources/shiboken6/tests/samplebinding/virtualmethods_test.py
index 7be424e26..52dc66c90 100644
--- a/sources/shiboken6/tests/samplebinding/virtualmethods_test.py
+++ b/sources/shiboken6/tests/samplebinding/virtualmethods_test.py
@@ -14,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)
@@ -36,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)
@@ -45,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)
@@ -54,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'''
@@ -66,7 +70,8 @@ class VirtualMethodsTest(unittest.TestCase):
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)
@@ -120,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 1b810e839..becdf7423 100644
--- a/sources/shiboken6/tests/samplebinding/visibilitychange_test.py
+++ b/sources/shiboken6/tests/samplebinding/visibilitychange_test.py
@@ -11,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 63882cc8a..186cb473e 100644
--- a/sources/shiboken6/tests/samplebinding/voidholder_test.py
+++ b/sources/shiboken6/tests/samplebinding/voidholder_test.py
@@ -16,6 +16,7 @@ init_paths()
from sample import VoidHolder, Point
from shiboken6 import Shiboken
+
class VoidHolderTest(unittest.TestCase):
'''Test case for void pointer manipulation.'''
@@ -44,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 317dfb53c..01c6d58d5 100644
--- a/sources/shiboken6/tests/samplebinding/weakref_test.py
+++ b/sources/shiboken6/tests/samplebinding/weakref_test.py
@@ -30,7 +30,7 @@ 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()
@@ -39,7 +39,7 @@ class WeakrefBasicTest(unittest.TestCase):
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()
diff --git a/sources/shiboken6/tests/samplebinding/writableclassdict_test.py b/sources/shiboken6/tests/samplebinding/writableclassdict_test.py
index e3ba10082..dfc962db9 100644
--- a/sources/shiboken6/tests/samplebinding/writableclassdict_test.py
+++ b/sources/shiboken6/tests/samplebinding/writableclassdict_test.py
@@ -13,7 +13,10 @@ init_paths()
from sample import Point
-class ExtPoint(Point): pass
+
+class ExtPoint(Point):
+ pass
+
class TestWritableClassDict(unittest.TestCase):
def testSetattrOnClass(self):
@@ -29,5 +32,6 @@ class TestWritableClassDict(unittest.TestCase):
pt = ExtPoint()
self.assertEqual(pt.bar, 321)
+
if __name__ == '__main__':
unittest.main()