diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-01-26 08:40:30 +0100 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-01-26 11:20:26 +0100 |
| commit | 019ab0d2388e30def0cb982c14e011af119d2409 (patch) | |
| tree | cc34379c3114f67fcbe2477cb7c5294c17c6fa50 /sources/pyside6/tests/QtStateMachine/qabstracttransition_test.py | |
| parent | f2e3e8d8d34c93dc8e61d0efd01a59f542abd94c (diff) | |
PySide6: Re-add QStateMachine
The code was moved from QtCore into a separate library, QStateMachine,
within the qtscxml repository.
Re-add tests and fix examples.
Task-number: PYSIDE-904
Task-number: PYSIDE-1482
Change-Id: I977b4835b3345fb342c369e4fdd92646118f7fda
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside6/tests/QtStateMachine/qabstracttransition_test.py')
| -rw-r--r-- | sources/pyside6/tests/QtStateMachine/qabstracttransition_test.py | 194 |
1 files changed, 194 insertions, 0 deletions
diff --git a/sources/pyside6/tests/QtStateMachine/qabstracttransition_test.py b/sources/pyside6/tests/QtStateMachine/qabstracttransition_test.py new file mode 100644 index 000000000..e5f1bc7fb --- /dev/null +++ b/sources/pyside6/tests/QtStateMachine/qabstracttransition_test.py @@ -0,0 +1,194 @@ +#!/usr/bin/python + +############################################################################# +## +## Copyright (C) 2021 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of Qt for Python. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +import os +import sys +from sys import getrefcount +import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from init_paths import init_test_paths +init_test_paths(False) + +from PySide6.QtCore import (QCoreApplication, QObject, QParallelAnimationGroup, + QTimer, SIGNAL) +from PySide6.QtStateMachine import (QEventTransition, QFinalState, QState, + QStateMachine, QSignalTransition) + + +def addStates(transition): + sx = QState() + sy = QState() + transition.setTargetStates([sx, sy]) + +def addAnimation(transition): + animation = QParallelAnimationGroup() + transition.addAnimation(animation) + +class QAbstractTransitionTest(unittest.TestCase): + + def testBasic(self): + app = QCoreApplication([]) + + o = QObject() + o.setProperty("text", "INdT") + + machine = QStateMachine() + s1 = QState() + s1.assignProperty(o, "text", "Rocks") + + s2 = QFinalState() + t = s1.addTransition(o, SIGNAL("change()"), s2) + + self.assertEqual(t.targetStates(), [s2]) + + addStates(t) + self.assertEqual(len(t.targetStates()), 2) + + animation = QParallelAnimationGroup() + t.addAnimation(animation) + + self.assertEqual(t.animations(), [animation]) + + addAnimation(t) + self.assertEqual(t.animations()[0].parent(), None) + + machine.addState(s1) + machine.addState(s2) + machine.setInitialState(s1) + machine.start() + + QTimer.singleShot(100, app.quit) + app.exec_() + + def testRefCountOfTargetState(self): + transition = QEventTransition() + state1 = QState() + refcount1 = getrefcount(state1) + + transition.setTargetState(state1) + + self.assertEqual(transition.targetState(), state1) + self.assertEqual(getrefcount(transition.targetState()), refcount1 + 1) + + state2 = QState() + refcount2 = getrefcount(state2) + + transition.setTargetState(state2) + + self.assertEqual(transition.targetState(), state2) + self.assertEqual(getrefcount(transition.targetState()), refcount2 + 1) + self.assertEqual(getrefcount(state1), refcount1) + + del transition + + self.assertEqual(getrefcount(state2), refcount2) + + def testRefCountOfTargetStates(self): + transition = QEventTransition() + state1 = QState() + state2 = QState() + states = [state1, state2] + refcount1 = getrefcount(state1) + refcount2 = getrefcount(state2) + + transition.setTargetStates(states) + + self.assertEqual(transition.targetStates(), states) + self.assertEqual(transition.targetState(), state1) + self.assertEqual(getrefcount(transition.targetStates()[0]), refcount1 + 1) + self.assertEqual(getrefcount(transition.targetStates()[1]), refcount2 + 1) + + del states + del transition + + self.assertEqual(getrefcount(state1), refcount1 - 1) + self.assertEqual(getrefcount(state2), refcount2 - 1) + + def testRefCountOfTargetStatesAfterSingleTargetState(self): + transition = QEventTransition() + state0 = QState() + refcount0 = getrefcount(state0) + + transition.setTargetState(state0) + + self.assertEqual(transition.targetState(), state0) + self.assertEqual(getrefcount(transition.targetState()), refcount0 + 1) + + state1 = QState() + state2 = QState() + states = [state1, state2] + refcount1 = getrefcount(state1) + refcount2 = getrefcount(state2) + + transition.setTargetStates(states) + + self.assertEqual(getrefcount(state0), refcount0) + self.assertEqual(transition.targetStates(), states) + self.assertEqual(transition.targetState(), state1) + self.assertEqual(getrefcount(transition.targetStates()[0]), refcount1 + 1) + self.assertEqual(getrefcount(transition.targetStates()[1]), refcount2 + 1) + + del states + del transition + + self.assertEqual(getrefcount(state1), refcount1 - 1) + self.assertEqual(getrefcount(state2), refcount2 - 1) + + def testRefCountOfTargetStatesBeforeSingleTargetState(self): + transition = QEventTransition() + state1 = QState() + state2 = QState() + states = [state1, state2] + refcount1 = getrefcount(state1) + refcount2 = getrefcount(state2) + + transition.setTargetStates(states) + + self.assertEqual(transition.targetStates(), states) + self.assertEqual(transition.targetState(), state1) + self.assertEqual(getrefcount(transition.targetStates()[0]), refcount1 + 1) + self.assertEqual(getrefcount(transition.targetStates()[1]), refcount2 + 1) + + state3 = QState() + refcount3 = getrefcount(state3) + + transition.setTargetState(state3) + + self.assertEqual(transition.targetState(), state3) + self.assertEqual(getrefcount(transition.targetState()), refcount3 + 1) + + del states + + self.assertEqual(getrefcount(state1), refcount1 - 1) + self.assertEqual(getrefcount(state2), refcount2 - 1) + +if __name__ == '__main__': + unittest.main() |
