|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +"""QGIS Unit tests for QgsRatioLockButton |
| 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__ = '18/07/2017' |
| 11 | +__copyright__ = 'Copyright 2017, 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.gui import QgsRatioLockButton |
| 18 | + |
| 19 | +from qgis.PyQt.QtWidgets import QDoubleSpinBox |
| 20 | + |
| 21 | +from qgis.testing import start_app, unittest |
| 22 | + |
| 23 | +start_app() |
| 24 | + |
| 25 | + |
| 26 | +class TestQgsRatioLockButton(unittest.TestCase): |
| 27 | + |
| 28 | + def testLinkedWidgets(self): |
| 29 | + """ test linking spin boxes to combobox""" |
| 30 | + w = qgis.gui.QgsRatioLockButton() |
| 31 | + |
| 32 | + spin_width = QDoubleSpinBox() |
| 33 | + spin_width.setMaximum(100000) |
| 34 | + spin_height = QDoubleSpinBox() |
| 35 | + spin_height.setMaximum(100000) |
| 36 | + |
| 37 | + w.setWidthSpinBox(spin_width) |
| 38 | + spin_width.setValue(1000) |
| 39 | + self.assertEqual(spin_width.value(), 1000) |
| 40 | + |
| 41 | + w.setLocked(True) |
| 42 | + spin_width.setValue(2000) |
| 43 | + self.assertEqual(spin_width.value(), 2000) |
| 44 | + w.setLocked(False) |
| 45 | + |
| 46 | + w.setHeightSpinBox(spin_height) |
| 47 | + spin_width.setValue(1000) |
| 48 | + self.assertEqual(spin_width.value(), 1000) |
| 49 | + self.assertEqual(spin_height.value(), 0) |
| 50 | + |
| 51 | + w.setLocked(True) |
| 52 | + spin_width.setValue(2000) |
| 53 | + self.assertEqual(spin_width.value(), 2000) |
| 54 | + self.assertEqual(spin_height.value(), 0) |
| 55 | + |
| 56 | + spin_height.setValue(1000) |
| 57 | + self.assertEqual(spin_width.value(), 2000) |
| 58 | + self.assertEqual(spin_height.value(), 1000) |
| 59 | + |
| 60 | + # ok, that was all setup tests... let's check the real thing now |
| 61 | + spin_width.setValue(1000) |
| 62 | + self.assertEqual(spin_width.value(), 1000) |
| 63 | + self.assertEqual(spin_height.value(), 500) |
| 64 | + spin_height.setValue(1000) |
| 65 | + self.assertEqual(spin_width.value(), 2000) |
| 66 | + self.assertEqual(spin_height.value(), 1000) |
| 67 | + |
| 68 | + w.setLocked(False) |
| 69 | + spin_width.setValue(1000) |
| 70 | + self.assertEqual(spin_width.value(), 1000) |
| 71 | + self.assertEqual(spin_height.value(), 1000) |
| 72 | + spin_height.setValue(2000) |
| 73 | + self.assertEqual(spin_width.value(), 1000) |
| 74 | + self.assertEqual(spin_height.value(), 2000) |
| 75 | + |
| 76 | + w.setLocked(True) |
| 77 | + spin_height.setValue(1000) |
| 78 | + self.assertEqual(spin_width.value(), 500) |
| 79 | + self.assertEqual(spin_height.value(), 1000) |
| 80 | + |
| 81 | + # setting to 0 should "break" lock |
| 82 | + spin_height.setValue(0) |
| 83 | + self.assertEqual(spin_width.value(), 500) |
| 84 | + self.assertEqual(spin_height.value(), 0) |
| 85 | + spin_width.setValue(1000) |
| 86 | + self.assertEqual(spin_width.value(), 1000) |
| 87 | + self.assertEqual(spin_height.value(), 0) |
| 88 | + spin_height.setValue(100) |
| 89 | + self.assertEqual(spin_width.value(), 1000) |
| 90 | + self.assertEqual(spin_height.value(), 100) |
| 91 | + |
| 92 | + spin_width.setValue(0) |
| 93 | + self.assertEqual(spin_width.value(), 0) |
| 94 | + self.assertEqual(spin_height.value(), 100) |
| 95 | + spin_height.setValue(1000) |
| 96 | + self.assertEqual(spin_width.value(), 0) |
| 97 | + self.assertEqual(spin_height.value(), 1000) |
| 98 | + spin_width.setValue(200) |
| 99 | + self.assertEqual(spin_width.value(), 200) |
| 100 | + self.assertEqual(spin_height.value(), 1000) |
| 101 | + |
| 102 | + |
| 103 | +if __name__ == '__main__': |
| 104 | + unittest.main() |
0 commit comments