Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add registry keepreference test
  • Loading branch information
m-kuhn committed Feb 6, 2019
1 parent 89ea819 commit b2aed60
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion tests/src/python/test_qgscolorschemeregistry.py
Expand Up @@ -15,7 +15,7 @@
import qgis # NOQA

from qgis.testing import start_app, unittest
from qgis.core import QgsColorSchemeRegistry, QgsRecentColorScheme, QgsApplication
from qgis.core import QgsColorSchemeRegistry, QgsRecentColorScheme, QgsApplication, QgsColorScheme

start_app()

Expand Down Expand Up @@ -72,6 +72,34 @@ def testRemoveScheme(self):
# try removing a scheme not in the registry
self.assertFalse(registry.removeColorScheme(recentScheme))

def testOwnership(self):
"""
Test that registered color schemes do not require that a reference to them is kept.
They should be parented to the registry (on transfer) and even if there's no reference
to the registry around (see the `del` below) this childship should continue to exist.
"""
class TestColorScheme(QgsColorScheme):

def schemeName(self):
return "TestScheme"

def fetchColors(self, context, baseColors):
return None

def clone(self):
return TestColorScheme()

def flags(self):
return 1

reg = QgsApplication.instance().colorSchemeRegistry()
reg.addColorScheme(TestColorScheme())
del reg

reg = QgsApplication.instance().colorSchemeRegistry()

self.assertIn('TestScheme', [scheme.schemeName() for scheme in reg.schemes()])


if __name__ == "__main__":
unittest.main()

0 comments on commit b2aed60

Please sign in to comment.