diff options
Diffstat (limited to 'sources/pyside6/tests/pysidetest')
23 files changed, 71 insertions, 8 deletions
diff --git a/sources/pyside6/tests/pysidetest/all_modules_load_test.py b/sources/pyside6/tests/pysidetest/all_modules_load_test.py index 70da51eb7..f8f2d4b79 100644 --- a/sources/pyside6/tests/pysidetest/all_modules_load_test.py +++ b/sources/pyside6/tests/pysidetest/all_modules_load_test.py @@ -42,11 +42,13 @@ import PySide6 # It is also really not recommended to use. But for testing, # the "__all__" variable is a great feature! + class AllModulesImportTest(unittest.TestCase): def testAllModulesCanImport(self): # would also work: exec("from PySide6 import *") for name in PySide6.__all__: exec(f"import PySide6.{name}") + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/pysidetest/bug_1016.py b/sources/pyside6/tests/pysidetest/bug_1016.py index 54a155fea..db57302a2 100644 --- a/sources/pyside6/tests/pysidetest/bug_1016.py +++ b/sources/pyside6/tests/pysidetest/bug_1016.py @@ -46,5 +46,6 @@ class TestBug1016 (unittest.TestCase): self.assertEqual(obj.callMe(), None) self.assertTrue(obj.wasCalled()) + if __name__ == "__main__": unittest.main() diff --git a/sources/pyside6/tests/pysidetest/decoratedslot_test.py b/sources/pyside6/tests/pysidetest/decoratedslot_test.py index d1f8f6d40..6db8cafc3 100644 --- a/sources/pyside6/tests/pysidetest/decoratedslot_test.py +++ b/sources/pyside6/tests/pysidetest/decoratedslot_test.py @@ -40,6 +40,7 @@ init_test_paths(True) from PySide6.QtCore import QObject from testbinding import TestObject + class Receiver(QObject): def __init__(self): super().__init__() diff --git a/sources/pyside6/tests/pysidetest/delegatecreateseditor_test.py b/sources/pyside6/tests/pysidetest/delegatecreateseditor_test.py index acbf5828e..9d1c5bf2b 100644 --- a/sources/pyside6/tests/pysidetest/delegatecreateseditor_test.py +++ b/sources/pyside6/tests/pysidetest/delegatecreateseditor_test.py @@ -47,6 +47,7 @@ from PySide6.QtWidgets import (QAbstractItemDelegate, QComboBox, id_text = 'This is me' + class DelegateDoesntKeepReferenceToEditor(QAbstractItemDelegate): def createEditor(self, parent, option, index): comboBox = QComboBox(parent) diff --git a/sources/pyside6/tests/pysidetest/embedding_test.py b/sources/pyside6/tests/pysidetest/embedding_test.py index e4b5cb9f6..682b4c0b7 100644 --- a/sources/pyside6/tests/pysidetest/embedding_test.py +++ b/sources/pyside6/tests/pysidetest/embedding_test.py @@ -77,5 +77,6 @@ class EmbeddingTest(unittest.TestCase): name = os.path.basename(dn(dn(dn(PySide6.support.signature.__file__)))) self.assertTrue(name.startswith("embedded.") and name.endswith(".zip")) + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/pysidetest/enum_test.py b/sources/pyside6/tests/pysidetest/enum_test.py index 6dbd2fb47..61febb299 100644 --- a/sources/pyside6/tests/pysidetest/enum_test.py +++ b/sources/pyside6/tests/pysidetest/enum_test.py @@ -39,6 +39,7 @@ init_test_paths(True) from testbinding import Enum1, TestObjectWithoutNamespace + class ListConnectionTest(unittest.TestCase): def testEnumVisibility(self): @@ -47,6 +48,7 @@ class ListConnectionTest(unittest.TestCase): self.assertEqual(TestObjectWithoutNamespace.Enum2.Option3, 3) self.assertEqual(TestObjectWithoutNamespace.Enum2.Option4, 4) + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/pysidetest/homonymoussignalandmethod_test.py b/sources/pyside6/tests/pysidetest/homonymoussignalandmethod_test.py index 0ca946541..b29d37fc2 100644 --- a/sources/pyside6/tests/pysidetest/homonymoussignalandmethod_test.py +++ b/sources/pyside6/tests/pysidetest/homonymoussignalandmethod_test.py @@ -41,6 +41,7 @@ from testbinding import TestObject '''Tests the behaviour of homonymous signals and slots.''' + class HomonymousSignalAndMethodTest(unittest.TestCase): def setUp(self): @@ -84,6 +85,7 @@ class HomonymousSignalAndMethodTest(unittest.TestCase): def testHomonymousSignalAndStaticMethodFromInstance(self): self.assertEqual(self.obj.staticMethodDouble(4), 8) + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/pysidetest/iterable_test.py b/sources/pyside6/tests/pysidetest/iterable_test.py index e8a85acf8..d2bf8c9f2 100644 --- a/sources/pyside6/tests/pysidetest/iterable_test.py +++ b/sources/pyside6/tests/pysidetest/iterable_test.py @@ -50,6 +50,7 @@ try: except ImportError: have_numpy = False + class PySequenceTest(unittest.TestCase): def test_iterable(self): diff --git a/sources/pyside6/tests/pysidetest/list_signal_test.py b/sources/pyside6/tests/pysidetest/list_signal_test.py index 58e849df9..93b8514d7 100644 --- a/sources/pyside6/tests/pysidetest/list_signal_test.py +++ b/sources/pyside6/tests/pysidetest/list_signal_test.py @@ -40,6 +40,7 @@ init_test_paths(True) from testbinding import TestObject from PySide6.QtCore import QObject + class ListConnectionTest(unittest.TestCase): def childrenChanged(self, children): @@ -54,6 +55,7 @@ class ListConnectionTest(unittest.TestCase): o.addChild(c) self.assertEqual(self._child.objectName(), "child") + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/pysidetest/mixin_signal_slots_test.py b/sources/pyside6/tests/pysidetest/mixin_signal_slots_test.py index adf8b8045..19b9a583e 100644 --- a/sources/pyside6/tests/pysidetest/mixin_signal_slots_test.py +++ b/sources/pyside6/tests/pysidetest/mixin_signal_slots_test.py @@ -47,9 +47,11 @@ from PySide6.QtCore import QObject, Signal, Slot class Mixin(object): mixinSignal = Signal() + def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + class MixinTwo(Mixin): mixinTwoSignal = Signal() @@ -61,6 +63,7 @@ class MixinTwo(Mixin): def mixinTwoSlot(self): self.mixinTwoSlotCalled = True + class MixinThree(object): mixinThreeSignal = Signal() @@ -72,6 +75,7 @@ class MixinThree(object): def mixinThreeSlot(self): self.mixinThreeSlotCalled = True + class Derived(Mixin, QObject): derivedSignal = Signal(str) @@ -85,6 +89,7 @@ class Derived(Mixin, QObject): self.derivedSlotCalled = True self.derivedSlotString = theString + class MultipleDerived(MixinTwo, MixinThree, Mixin, QObject): derivedSignal = Signal(str) @@ -121,6 +126,7 @@ class MixinTest(unittest.TestCase): # Check derivedSignal emission after mixingSignal connection self.outsideSlotCalled = False + @Slot() def outsideSlot(): self.outsideSlotCalled = True @@ -146,7 +152,6 @@ class MixinTest(unittest.TestCase): signature = m.method(i).methodSignature() self.assertEqual(methodIndices[signature], i) - def testMixinSignalSlotRegistrationWithMultipleInheritance(self): obj = MultipleDerived() m = obj.metaObject() @@ -170,6 +175,7 @@ class MixinTest(unittest.TestCase): # Check derivedSignal emission after mixinThreeSignal connection self.outsideSlotCalled = False + @Slot() def outsideSlot(): self.outsideSlotCalled = True diff --git a/sources/pyside6/tests/pysidetest/modelview_test.py b/sources/pyside6/tests/pysidetest/modelview_test.py index 1aa72d98a..3329b5875 100644 --- a/sources/pyside6/tests/pysidetest/modelview_test.py +++ b/sources/pyside6/tests/pysidetest/modelview_test.py @@ -44,9 +44,11 @@ from PySide6.QtCore import QAbstractListModel, QObject, QModelIndex object_name = 'test object' + class MyObject(QObject): pass + class ListModelKeepsReference(QAbstractListModel): def __init__(self, parent=None): QAbstractListModel.__init__(self, parent) @@ -59,6 +61,7 @@ class ListModelKeepsReference(QAbstractListModel): def data(self, index, role): return self.obj + class ListModelDoesntKeepsReference(QAbstractListModel): def rowCount(self, parent=QModelIndex()): return 1 @@ -68,6 +71,7 @@ class ListModelDoesntKeepsReference(QAbstractListModel): obj.setObjectName(object_name) return obj + class ListModelThatReturnsString(QAbstractListModel): def rowCount(self, parent=QModelIndex()): return 1 @@ -101,6 +105,7 @@ class ModelViewTest(unittest.TestCase): self.assertEqual(type(obj), str) self.assertEqual(obj, 'string') + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/pysidetest/new_inherited_functions_test.py b/sources/pyside6/tests/pysidetest/new_inherited_functions_test.py index a4e996f96..f4d83ad9f 100644 --- a/sources/pyside6/tests/pysidetest/new_inherited_functions_test.py +++ b/sources/pyside6/tests/pysidetest/new_inherited_functions_test.py @@ -182,16 +182,17 @@ class MainTest(unittest.TestCase): except AttributeError: unittest.TestCase().skipTest("this test makes only sense if QtWidgets is available.") try: - PySide6.QtWidgets.QApplication.palette(42) # raises + PySide6.QtWidgets.QApplication.palette(42) # raises except TypeError as e: lines = e.args[0].splitlines() heading_pos = lines.index("Supported signatures:") - lines = lines[heading_pos+1:] + lines = lines[heading_pos + 1:] self.assertEqual(len(lines), 3) txt = '\n'.join(lines) print("Signatures found:") print(txt) self.assertTrue("palette()" in txt) + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/pysidetest/notify_id.py b/sources/pyside6/tests/pysidetest/notify_id.py index f3c38ab06..f11eacdda 100644 --- a/sources/pyside6/tests/pysidetest/notify_id.py +++ b/sources/pyside6/tests/pysidetest/notify_id.py @@ -40,6 +40,7 @@ from PySide6.QtCore import QObject, Signal, Property, Slot '''Tests that the signal notify id of a property is correct, aka corresponds to the initially set notify method.''' + class Foo(QObject): def __init__(self): super().__init__() @@ -63,6 +64,7 @@ class Foo(QObject): propChanged = Signal() prop = Property(str, getProp, setProp, notify=propChanged) + class NotifyIdSignal(unittest.TestCase): def setUp(self): self.obj = Foo() @@ -80,5 +82,6 @@ class NotifyIdSignal(unittest.TestCase): signalName = signal.name() self.assertEqual(signalName, "propChanged") + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/pysidetest/property_python_test.py b/sources/pyside6/tests/pysidetest/property_python_test.py index 6e19e92a0..baf4cdb01 100644 --- a/sources/pyside6/tests/pysidetest/property_python_test.py +++ b/sources/pyside6/tests/pysidetest/property_python_test.py @@ -49,7 +49,6 @@ from init_paths import init_test_paths init_test_paths(False) from PySide6.QtCore import Property, QObject -#from PyQt5.QtCore import pyqtProperty as Property, QObject # This are the original imports. import sys @@ -61,18 +60,23 @@ try: except ImportError: pass + class PropertyBase(Exception): pass + class PropertyGet(PropertyBase): pass + class PropertySet(PropertyBase): pass + class PropertyDel(PropertyBase): pass + class BaseClass(QObject): def __init__(self): super().__init__() @@ -92,6 +96,7 @@ class BaseClass(QObject): def spam(self): del self._spam + class SubClass(BaseClass): @BaseClass.spam.getter @@ -107,24 +112,29 @@ class SubClass(BaseClass): def spam(self): raise PropertyDel(self._spam) + class PropertyDocBase(object): _spam = 1 + def _get_spam(self): return self._spam spam = Property(object, _get_spam, doc="spam spam spam") + class PropertyDocSub(PropertyDocBase): @PropertyDocBase.spam.getter def spam(self): """The decorator does not use this doc string""" return self._spam + class PropertySubNewGetter(BaseClass): @BaseClass.spam.getter def spam(self): """new docstring""" return 5 + class PropertyNewGetter(QObject): def __init__(self): super().__init__() @@ -133,11 +143,13 @@ class PropertyNewGetter(QObject): def spam(self): """original docstring""" return 1 + @spam.getter def spam(self): """new docstring""" return 8 + class PropertyTests(unittest.TestCase): def test_property_decorator_baseclass(self): # see #1620 diff --git a/sources/pyside6/tests/pysidetest/qapp_like_a_macro_test.py b/sources/pyside6/tests/pysidetest/qapp_like_a_macro_test.py index 5acefefa1..c83d2a860 100644 --- a/sources/pyside6/tests/pysidetest/qapp_like_a_macro_test.py +++ b/sources/pyside6/tests/pysidetest/qapp_like_a_macro_test.py @@ -42,6 +42,7 @@ import PySide6 # Note: this test makes qapplication_singleton_test.py obsolete. + class qAppMacroTest(unittest.TestCase): _test_1093_is_first = True @@ -62,9 +63,11 @@ class qAppMacroTest(unittest.TestCase): QtWidgets.QApplication) fil = sys.stderr for klass in classes: - print("CREATED", klass([]), file=fil); fil.flush() + print("CREATED", klass([]), file=fil) + fil.flush() qApp.shutdown() - print("DELETED qApp", qApp, file=fil); fil.flush() + print("DELETED qApp", qApp, file=fil) + fil.flush() # creating without deletion raises: QtCore.QCoreApplication([]) with self.assertRaises(RuntimeError): diff --git a/sources/pyside6/tests/pysidetest/qvariant_test.py b/sources/pyside6/tests/pysidetest/qvariant_test.py index eadc2aad0..637aa95cf 100644 --- a/sources/pyside6/tests/pysidetest/qvariant_test.py +++ b/sources/pyside6/tests/pysidetest/qvariant_test.py @@ -41,6 +41,7 @@ from PySide6.QtGui import QKeySequence from helper.usesqapplication import UsesQApplication + class QVariantTest(UsesQApplication): def testQKeySequenceQVariantOperator(self): @@ -48,5 +49,6 @@ class QVariantTest(UsesQApplication): ks = QKeySequence(Qt.SHIFT, Qt.CTRL, Qt.Key_P, Qt.Key_R) self.assertEqual(TestObject.checkType(ks), 4107) + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/pysidetest/repr_test.py b/sources/pyside6/tests/pysidetest/repr_test.py index 587caddcc..dd9f08ea4 100644 --- a/sources/pyside6/tests/pysidetest/repr_test.py +++ b/sources/pyside6/tests/pysidetest/repr_test.py @@ -51,6 +51,7 @@ init_test_paths(True) from testbinding import PySideCPP, TestObject + class QObjectDerivedReprTest(unittest.TestCase): """Test the __repr__ implementation of QObject derived classes""" @@ -86,6 +87,7 @@ class QObjectDerivedReprTest(unittest.TestCase): # __repr__ should use the operator<<(QDebug,...) implementation self.assertEqual(str(t), "TestObject2WithNamespace(injected_repr)") + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/pysidetest/signal_slot_warning.py b/sources/pyside6/tests/pysidetest/signal_slot_warning.py index 429fb113a..67dce8084 100644 --- a/sources/pyside6/tests/pysidetest/signal_slot_warning.py +++ b/sources/pyside6/tests/pysidetest/signal_slot_warning.py @@ -54,6 +54,7 @@ class Whatever(QtCore.QObject): def mySlot(self, v): pass + class WarningTest(unittest.TestCase): def testSignalSlotWarning(self): # we create an object. This gives no warning. diff --git a/sources/pyside6/tests/pysidetest/signalandnamespace_test.py b/sources/pyside6/tests/pysidetest/signalandnamespace_test.py index f78d05ed6..c84346928 100644 --- a/sources/pyside6/tests/pysidetest/signalandnamespace_test.py +++ b/sources/pyside6/tests/pysidetest/signalandnamespace_test.py @@ -39,6 +39,7 @@ init_test_paths(True) from testbinding import PySideCPP, TestObjectWithoutNamespace + class ModelViewTest(unittest.TestCase): def callback(self, o): @@ -70,7 +71,6 @@ class ModelViewTest(unittest.TestCase): o.callSignalWithNamespace(o) self.assertTrue(o == self._called) - def testWithoutNamespace1(self): self._called = None o = TestObjectWithoutNamespace(None) @@ -123,6 +123,7 @@ class ModelViewTest(unittest.TestCase): o.callSignalWithTypedef(10) self.assertEqual(10, self._called) + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/pysidetest/signalemissionfrompython_test.py b/sources/pyside6/tests/pysidetest/signalemissionfrompython_test.py index 4a3f8a178..8a3f64032 100644 --- a/sources/pyside6/tests/pysidetest/signalemissionfrompython_test.py +++ b/sources/pyside6/tests/pysidetest/signalemissionfrompython_test.py @@ -42,6 +42,7 @@ from PySide6.QtCore import QObject, SIGNAL '''Tests the behaviour of signals with default values when emitted from Python.''' + class SignalEmissionFromPython(unittest.TestCase): def setUp(self): @@ -60,6 +61,7 @@ class SignalEmissionFromPython(unittest.TestCase): def callbackOne(): self.one_called += 1 self.obj2.signalWithDefaultValue.emit() + def callbackTwo(): self.two_called += 1 self.obj1.signalWithDefaultValue.connect(callbackOne) @@ -73,6 +75,7 @@ class SignalEmissionFromPython(unittest.TestCase): def callbackOne(): self.one_called += 1 self.obj2.signalWithDefaultValue.emit() + def callbackTwo(): self.two_called += 1 QObject.connect(self.obj1, SIGNAL('signalWithDefaultValue()'), callbackOne) @@ -86,6 +89,7 @@ class SignalEmissionFromPython(unittest.TestCase): def callbackOne(): self.one_called += 1 self.obj2.signalWithDefaultValue[bool].emit(True) + def callbackTwo(): self.two_called += 1 self.obj1.signalWithDefaultValue.connect(callbackOne) @@ -99,6 +103,7 @@ class SignalEmissionFromPython(unittest.TestCase): def callbackOne(): self.one_called += 1 self.obj2.signalWithDefaultValue[bool].emit(True) + def callbackTwo(): self.two_called += 1 QObject.connect(self.obj1, SIGNAL('signalWithDefaultValue()'), callbackOne) @@ -109,7 +114,6 @@ class SignalEmissionFromPython(unittest.TestCase): self.assertEqual(self.two_called, 2) - if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/pysidetest/signalwithdefaultvalue_test.py b/sources/pyside6/tests/pysidetest/signalwithdefaultvalue_test.py index 1e715da38..c44cca396 100644 --- a/sources/pyside6/tests/pysidetest/signalwithdefaultvalue_test.py +++ b/sources/pyside6/tests/pysidetest/signalwithdefaultvalue_test.py @@ -42,6 +42,7 @@ from PySide6.QtCore import QObject, SIGNAL '''Tests the behaviour of signals with default values.''' + class SignalWithDefaultValueTest(unittest.TestCase): def setUp(self): @@ -57,6 +58,7 @@ class SignalWithDefaultValueTest(unittest.TestCase): def testConnectNewStyleEmitVoidSignal(self): def callbackVoid(): self.void_called = True + def callbackBool(value): self.bool_called = True self.obj.signalWithDefaultValue.connect(callbackVoid) @@ -68,6 +70,7 @@ class SignalWithDefaultValueTest(unittest.TestCase): def testConnectNewStyleEmitBoolSignal(self): def callbackVoid(): self.void_called = True + def callbackBool(value): self.bool_called = True self.obj.signalWithDefaultValue.connect(callbackVoid) @@ -79,6 +82,7 @@ class SignalWithDefaultValueTest(unittest.TestCase): def testConnectOldStyleEmitVoidSignal(self): def callbackVoid(): self.void_called = True + def callbackBool(value): self.bool_called = True QObject.connect(self.obj, SIGNAL('signalWithDefaultValue()'), callbackVoid) @@ -90,6 +94,7 @@ class SignalWithDefaultValueTest(unittest.TestCase): def testConnectOldStyleEmitBoolSignal(self): def callbackVoid(): self.void_called = True + def callbackBool(value): self.bool_called = True QObject.connect(self.obj, SIGNAL('signalWithDefaultValue()'), callbackVoid) @@ -98,6 +103,7 @@ class SignalWithDefaultValueTest(unittest.TestCase): self.assertTrue(self.void_called) self.assertTrue(self.bool_called) + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/pysidetest/typedef_signal_test.py b/sources/pyside6/tests/pysidetest/typedef_signal_test.py index 8bab3eab5..714695823 100644 --- a/sources/pyside6/tests/pysidetest/typedef_signal_test.py +++ b/sources/pyside6/tests/pysidetest/typedef_signal_test.py @@ -38,6 +38,7 @@ init_test_paths(True) from PySide6.QtCore import QObject from testbinding import TestObject + class Receiver(QObject): def __init__(self): @@ -47,6 +48,7 @@ class Receiver(QObject): def slot(self, value): self.received = value + class TypedefSignal(unittest.TestCase): def testTypedef(self): @@ -57,5 +59,6 @@ class TypedefSignal(unittest.TestCase): obj.emitSignalWithTypedefValue(2) self.assertEqual(receiver.received.value, 2) + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/pysidetest/version_test.py b/sources/pyside6/tests/pysidetest/version_test.py index aba4da9c0..397e61a68 100644 --- a/sources/pyside6/tests/pysidetest/version_test.py +++ b/sources/pyside6/tests/pysidetest/version_test.py @@ -51,6 +51,7 @@ class CheckForVariablesTest(unittest.TestCase): self.assertTrue(__version_info__ >= (4, 5, 0)) self.assertTrue(__version__) + if __name__ == '__main__': unittest.main() |