Skip to content
Permalink
Browse files

Add registry keepreference test

  • Loading branch information
m-kuhn committed Feb 6, 2019
1 parent 89ea819 commit b2aed603f1dc52040ee9940facd7ccedf6208317
Showing with 29 additions and 1 deletion.
  1. +29 −1 tests/src/python/test_qgscolorschemeregistry.py
@@ -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()

@@ -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.
You can’t perform that action at this time.