Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure that QgsApplication members are usable even when no
QgsApplication instance is available Fixes crash when using custom widgets with Qt Designer
- Loading branch information
Showing
4 changed files
with
183 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# -*- coding: utf-8 -*- | ||
"""QGIS Unit tests for accessing QgsApplication members with a QgsApplication instance. | ||
.. note:: This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
""" | ||
__author__ = 'Nyall Dawson' | ||
__date__ = '1/02/2017' | ||
__copyright__ = 'Copyright 2017, The QGIS Project' | ||
# This will get replaced with a git SHA1 when you do a git archive | ||
__revision__ = '$Format:%H$' | ||
|
||
import qgis # NOQA | ||
|
||
from qgis.core import (QgsApplication) | ||
from qgis.testing import unittest | ||
|
||
""" | ||
Really important!! This test is designed to ensure that the members | ||
which usually belong to a QgsApplication instance are still usable | ||
when no QgsApplication instance is available (eg when using | ||
custom editor widgets in QtDesigner). In this case QgsApplication | ||
falls back to static members, which this test is designed to check. | ||
So don't add start_app here or anything else which creates a | ||
QgsApplication instance! | ||
""" | ||
|
||
|
||
class TestQgsNoApplication(unittest.TestCase): | ||
def testMembers(self): | ||
self.assertTrue(QgsApplication.actionScopeRegistry()) | ||
# self.assertTrue(QgsApplication.annotationRegistry()) NOT AVAILABLE IN BINDINGS | ||
self.assertTrue(QgsApplication.colorSchemeRegistry()) | ||
self.assertTrue(QgsApplication.fieldFormatterRegistry()) | ||
self.assertTrue(QgsApplication.gpsConnectionRegistry()) | ||
self.assertTrue(QgsApplication.messageLog()) | ||
self.assertTrue(QgsApplication.paintEffectRegistry()) | ||
self.assertTrue(QgsApplication.pluginLayerRegistry()) | ||
self.assertTrue(QgsApplication.processingRegistry()) | ||
self.assertTrue(QgsApplication.profiler()) | ||
# self.assertTrue(QgsApplication.rasterRendererRegistry()) NOT AVAILABLE IN BINDINGS | ||
self.assertTrue(QgsApplication.rendererRegistry()) | ||
self.assertTrue(QgsApplication.svgCache()) | ||
self.assertTrue(QgsApplication.symbolLayerRegistry()) | ||
self.assertTrue(QgsApplication.taskManager()) | ||
|
||
def testNullRepresentation(self): | ||
nr = 'my_null_value' | ||
QgsApplication.setNullRepresentation(nr) | ||
self.assertEqual(QgsApplication.nullRepresentation(), nr) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |