|
1 | 1 | # -*- coding: utf-8 -*-
|
2 |
| -"""QGIS Unit tests for QgsProjectionSelectionWidget. |
| 2 | +"""QGIS Unit tests for various projection selection widgets. |
3 | 3 |
|
4 | 4 | .. note:: This program is free software; you can redistribute it and/or modify
|
5 | 5 | it under the terms of the GNU General Public License as published by
|
|
14 | 14 |
|
15 | 15 | import qgis # NOQA
|
16 | 16 |
|
17 |
| -from qgis.gui import QgsProjectionSelectionWidget |
| 17 | +from qgis.gui import (QgsProjectionSelectionWidget, |
| 18 | +QgsProjectionSelectionTreeWidget, |
| 19 | + QgsProjectionSelectionDialog) |
18 | 20 | from qgis.core import QgsCoordinateReferenceSystem, QgsProject
|
19 | 21 | from qgis.testing import start_app, unittest
|
20 | 22 | from qgis.PyQt.QtGui import QColor
|
21 | 23 | start_app()
|
22 | 24 |
|
23 | 25 |
|
24 |
| -class TestQgsProjectionSelectionWidget(unittest.TestCase): |
| 26 | +class TestQgsProjectionSelectionWidgets(unittest.TestCase): |
25 | 27 |
|
26 | 28 | def testShowingHiding(self):
|
27 | 29 | """ test showing and hiding options """
|
@@ -112,6 +114,53 @@ def testShowingNotSetOption(self):
|
112 | 114 | self.assertTrue(w.optionVisible(QgsProjectionSelectionWidget.CurrentCrs))
|
113 | 115 | self.assertTrue(w.optionVisible(QgsProjectionSelectionWidget.CrsNotSet))
|
114 | 116 |
|
| 117 | + def testTreeWidgetGettersSetters(self): |
| 118 | + """ basic tests for QgsProjectionSelectionTreeWidget """ |
| 119 | + w = QgsProjectionSelectionTreeWidget() |
| 120 | + w.show() |
| 121 | + self.assertFalse(w.hasValidSelection()) |
| 122 | + w.setCrs(QgsCoordinateReferenceSystem('EPSG:3111')) |
| 123 | + self.assertEqual(w.crs().authid(),'EPSG:3111') |
| 124 | + self.assertTrue(w.hasValidSelection()) |
| 125 | + |
| 126 | + |
| 127 | + def testTreeWidgetNotSetOption(self): |
| 128 | + """ test allowing no projection option for QgsProjectionSelectionTreeWidget """ |
| 129 | + w = QgsProjectionSelectionTreeWidget() |
| 130 | + w.show() |
| 131 | + w.setShowNoProjection(True) |
| 132 | + self.assertTrue(w.showNoProjection()) |
| 133 | + w.setShowNoProjection(False) |
| 134 | + self.assertFalse(w.showNoProjection()) |
| 135 | + |
| 136 | + w.setShowNoProjection(True) |
| 137 | + # no projection should be a valid selection |
| 138 | + w.setCrs(QgsCoordinateReferenceSystem()) |
| 139 | + self.assertTrue(w.hasValidSelection()) |
| 140 | + self.assertFalse(w.crs().isValid()) |
| 141 | + |
| 142 | + def testDialogGettersSetters(self): |
| 143 | + """ basic tests for QgsProjectionSelectionTreeWidget """ |
| 144 | + w = QgsProjectionSelectionDialog() |
| 145 | + w.show() |
| 146 | + w.setCrs(QgsCoordinateReferenceSystem('EPSG:3111')) |
| 147 | + self.assertEqual(w.crs().authid(),'EPSG:3111') |
| 148 | + |
| 149 | + def testDialogNotSetOption(self): |
| 150 | + """ test allowing no projection option for QgsProjectionSelectionTreeWidget """ |
| 151 | + w = QgsProjectionSelectionDialog() |
| 152 | + w.show() |
| 153 | + w.setShowNoProjection(True) |
| 154 | + self.assertTrue(w.showNoProjection()) |
| 155 | + w.setShowNoProjection(False) |
| 156 | + self.assertFalse(w.showNoProjection()) |
| 157 | + |
| 158 | + w.setShowNoProjection(True) |
| 159 | + w.setCrs(QgsCoordinateReferenceSystem()) |
| 160 | + self.assertFalse(w.crs().isValid()) |
| 161 | + |
| 162 | + |
| 163 | + |
115 | 164 |
|
116 | 165 | if __name__ == '__main__':
|
117 | 166 | unittest.main()
|
0 commit comments