|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +"""QGIS Unit tests for QgsPanelWidget. |
| 3 | +
|
| 4 | +.. note:: This program is free software; you can redistribute it and/or modify |
| 5 | +it under the terms of the GNU General Public License as published by |
| 6 | +the Free Software Foundation; either version 2 of the License, or |
| 7 | +(at your option) any later version. |
| 8 | +""" |
| 9 | +__author__ = 'Nyall Dawson' |
| 10 | +__date__ = '16/08/2016' |
| 11 | +__copyright__ = 'Copyright 2016, The QGIS Project' |
| 12 | +# This will get replaced with a git SHA1 when you do a git archive |
| 13 | +__revision__ = '$Format:%H$' |
| 14 | + |
| 15 | +import qgis # NOQA |
| 16 | + |
| 17 | +from qgis.PyQt.QtWidgets import QWidget |
| 18 | +from qgis.gui import QgsPanelWidget |
| 19 | +from qgis.testing import start_app, unittest |
| 20 | + |
| 21 | +start_app() |
| 22 | + |
| 23 | + |
| 24 | +class TestQgsPanelWidget(unittest.TestCase): |
| 25 | + |
| 26 | + def testFindParentPanel(self): |
| 27 | + """ test QgsPanelWidget.findParentPanel """ |
| 28 | + |
| 29 | + # no widget |
| 30 | + self.assertFalse(QgsPanelWidget.findParentPanel(None)) |
| 31 | + |
| 32 | + # widget with no parent |
| 33 | + w = QWidget() |
| 34 | + self.assertFalse(QgsPanelWidget.findParentPanel(w)) |
| 35 | + |
| 36 | + # widget with no panel parent |
| 37 | + w2 = QWidget(w) |
| 38 | + self.assertFalse(QgsPanelWidget.findParentPanel(w2)) |
| 39 | + |
| 40 | + # panel widget itself |
| 41 | + w3 = QgsPanelWidget() |
| 42 | + self.assertEqual(QgsPanelWidget.findParentPanel(w3), w3) |
| 43 | + |
| 44 | + # widget with direct QgsPanelWidget parent |
| 45 | + w4 = QWidget(w3) |
| 46 | + self.assertEqual(QgsPanelWidget.findParentPanel(w4), w3) |
| 47 | + |
| 48 | + # widget with QgsPanelWidget grandparent |
| 49 | + w5 = QWidget(w4) |
| 50 | + self.assertEqual(QgsPanelWidget.findParentPanel(w5), w3) |
| 51 | + |
| 52 | + |
| 53 | +if __name__ == '__main__': |
| 54 | + unittest.main() |
0 commit comments