Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fix tests
- Loading branch information
Showing
9 changed files
with
140 additions
and
130 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
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,83 @@ | ||
# -*- coding: utf-8 -*- | ||
"""QGIS Unit tests for QgsLayerTree. | ||
.. 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__ = 'Matthias Kuhn' | ||
__date__ = '22.3.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 | ||
|
||
import os | ||
|
||
from qgis.core import ( | ||
QgsLayerTree, | ||
QgsProject, | ||
QgsVectorLayer | ||
) | ||
from qgis.testing import start_app, unittest | ||
from utilities import (unitTestDataPath) | ||
from qgis.PyQt.QtTest import QSignalSpy | ||
from qgis.PyQt.QtCore import QDir | ||
|
||
app = start_app() | ||
TEST_DATA_DIR = unitTestDataPath() | ||
|
||
|
||
class TestQgsLayerTree(unittest.TestCase): | ||
|
||
def __init__(self, methodName): | ||
"""Run once on class initialization.""" | ||
unittest.TestCase.__init__(self, methodName) | ||
|
||
def testCustomLayerOrder(self): | ||
""" test project layer order""" | ||
prj = QgsProject() | ||
layer = QgsVectorLayer("Point?field=fldtxt:string", | ||
"layer1", "memory") | ||
layer2 = QgsVectorLayer("Point?field=fldtxt:string", | ||
"layer2", "memory") | ||
layer3 = QgsVectorLayer("Point?field=fldtxt:string", | ||
"layer3", "memory") | ||
prj.addMapLayers([layer, layer2, layer3]) | ||
|
||
layer_order_changed_spy = QSignalSpy(prj.layerTreeRoot().customLayerOrderChanged) | ||
prj.layerTreeRoot().setCustomLayerOrder([layer2, layer]) | ||
self.assertEqual(len(layer_order_changed_spy), 1) | ||
prj.layerTreeRoot().setCustomLayerOrder([layer2, layer]) | ||
self.assertEqual(len(layer_order_changed_spy), 1) # no signal, order not changed | ||
|
||
self.assertEqual(prj.layerTreeRoot().customLayerOrder(), [layer2, layer]) | ||
prj.layerTreeRoot().setCustomLayerOrder([layer]) | ||
self.assertEqual(prj.layerTreeRoot().customLayerOrder(), [layer]) | ||
self.assertEqual(len(layer_order_changed_spy), 2) | ||
|
||
# remove a layer | ||
prj.layerTreeRoot().setCustomLayerOrder([layer2, layer, layer3]) | ||
self.assertEqual(len(layer_order_changed_spy), 3) | ||
prj.removeMapLayer(layer) | ||
self.assertEqual(prj.layerTreeRoot().customLayerOrder(), [layer2, layer3]) | ||
self.assertEqual(len(layer_order_changed_spy), 4) | ||
|
||
# save and restore | ||
file_name = os.path.join(QDir.tempPath(), 'proj.qgs') | ||
prj.setFileName(file_name) | ||
prj.write() | ||
prj2 = QgsProject() | ||
prj2.setFileName(file_name) | ||
prj2.read() | ||
self.assertEqual([l.id() for l in prj2.layerTreeRoot().customLayerOrder()], [layer2.id(), layer3.id()]) | ||
|
||
# clear project | ||
prj.clear() | ||
self.assertEqual(prj.layerTreeRoot().customLayerOrder(), []) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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
Oops, something went wrong.