Skip to content

Commit b2aed60

Browse files
committedFeb 6, 2019
Add registry keepreference test
1 parent 89ea819 commit b2aed60

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed
 

‎tests/src/python/test_qgscolorschemeregistry.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import qgis # NOQA
1616

1717
from qgis.testing import start_app, unittest
18-
from qgis.core import QgsColorSchemeRegistry, QgsRecentColorScheme, QgsApplication
18+
from qgis.core import QgsColorSchemeRegistry, QgsRecentColorScheme, QgsApplication, QgsColorScheme
1919

2020
start_app()
2121

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

75+
def testOwnership(self):
76+
"""
77+
Test that registered color schemes do not require that a reference to them is kept.
78+
They should be parented to the registry (on transfer) and even if there's no reference
79+
to the registry around (see the `del` below) this childship should continue to exist.
80+
"""
81+
class TestColorScheme(QgsColorScheme):
82+
83+
def schemeName(self):
84+
return "TestScheme"
85+
86+
def fetchColors(self, context, baseColors):
87+
return None
88+
89+
def clone(self):
90+
return TestColorScheme()
91+
92+
def flags(self):
93+
return 1
94+
95+
reg = QgsApplication.instance().colorSchemeRegistry()
96+
reg.addColorScheme(TestColorScheme())
97+
del reg
98+
99+
reg = QgsApplication.instance().colorSchemeRegistry()
100+
101+
self.assertIn('TestScheme', [scheme.schemeName() for scheme in reg.schemes()])
102+
75103

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

0 commit comments

Comments
 (0)
Please sign in to comment.