Skip to content

Commit

Permalink
Fix QgsMapLayerRegistry test on Travis builds
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 4, 2016
1 parent ea32e6a commit a0f329e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tests/src/python/test_qgsmaplayerregistry.py
Expand Up @@ -14,7 +14,6 @@

from qgis.core import QgsMapLayerRegistry, QgsVectorLayer, QgsMapLayer
from qgis.testing import start_app, unittest
from qgis.PyQt.QtTest import QSignalSpy
from qgis.PyQt.QtCore import QT_VERSION_STR
import sip

Expand Down Expand Up @@ -94,6 +93,8 @@ def test_addMapLayerInvalid(self):
def test_addMapLayerSignals(self):
""" test that signals are correctly emitted when adding map layer"""

QgsMapLayerRegistry.instance().removeAllMapLayers()

layer_was_added_spy = QSignalSpy(QgsMapLayerRegistry.instance().layerWasAdded)
layers_added_spy = QSignalSpy(QgsMapLayerRegistry.instance().layersAdded)
legend_layers_added_spy = QSignalSpy(QgsMapLayerRegistry.instance().legendLayersAdded)
Expand All @@ -108,7 +109,7 @@ def test_addMapLayerSignals(self):
self.assertEqual(len(legend_layers_added_spy), 1)

# layer not added to legend
QgsMapLayerRegistry.instance().addMapLayer(createLayer('test'), False)
QgsMapLayerRegistry.instance().addMapLayer(createLayer('test2'), False)
self.assertEqual(len(layer_was_added_spy), 2)
self.assertEqual(len(layers_added_spy), 2)
self.assertEqual(len(legend_layers_added_spy), 1)
Expand Down Expand Up @@ -170,6 +171,7 @@ def test_addMapLayersAlreadyAdded(self):
@unittest.skipIf(not use_signal_spy, "No QSignalSpy available")
def test_addMapLayersSignals(self):
""" test that signals are correctly emitted when adding map layers"""
QgsMapLayerRegistry.instance().removeAllMapLayers()

layer_was_added_spy = QSignalSpy(QgsMapLayerRegistry.instance().layerWasAdded)
layers_added_spy = QSignalSpy(QgsMapLayerRegistry.instance().layersAdded)
Expand Down Expand Up @@ -465,6 +467,8 @@ def test_addRemoveLayersSignals(self):
self.assertEqual(len(remove_all_spy), 1)

def test_RemoveLayerShouldNotSegFault(self):
QgsMapLayerRegistry.instance().removeAllMapLayers()

reg = QgsMapLayerRegistry.instance()
# Should not segfault
reg.removeMapLayers(['not_exists'])
Expand Down

0 comments on commit a0f329e

Please sign in to comment.