Skip to content
Permalink
Browse files

Followup 5daa54, add unit tests

  • Loading branch information
nyalldawson committed Jul 4, 2016
1 parent 3d8269e commit e10211178c25563ba710fb9f081bd9f13e292285
Showing with 25 additions and 1 deletion.
  1. +25 −1 tests/src/python/test_qgsmaplayerregistry.py
@@ -292,6 +292,11 @@ def test_removeMapLayersById(self):
self.assertEqual(QgsMapLayerRegistry.instance().count(), 0)
self.assertTrue(sip.isdeleted(l2))

# try removing a layer not in the registry
l4 = createLayer('test4')
QgsMapLayerRegistry.instance().removeMapLayers([l4.id()])
self.assertFalse(sip.isdeleted(l4))

# fails on qt5 due to removeMapLayers list type conversion - needs a PyName alias
# added to removeMapLayers for QGIS 3.0
@unittest.expectedFailure(QT_VERSION_STR[0] == '5')
@@ -362,6 +367,11 @@ def test_removeMapLayerById(self):
self.assertEqual(QgsMapLayerRegistry.instance().count(), 0)
self.assertTrue(sip.isdeleted(l2))

# try removing a layer not in the registry
l3 = createLayer('test3')
QgsMapLayerRegistry.instance().removeMapLayer(l3.id())
self.assertFalse(sip.isdeleted(l3))

def test_removeMapLayerByLayer(self):
""" test removing a map layer by layer """
QgsMapLayerRegistry.instance().removeAllMapLayers()
@@ -395,6 +405,11 @@ def test_removeMapLayerByLayer(self):
self.assertEqual(QgsMapLayerRegistry.instance().count(), 0)
self.assertTrue(sip.isdeleted(l2))

# try removing a layer not in the registry
l3 = createLayer('test3')
QgsMapLayerRegistry.instance().removeMapLayer(l3)
self.assertFalse(sip.isdeleted(l3))

def test_removeAllMapLayers(self):
""" test removing all map layers from registry """
QgsMapLayerRegistry.instance().removeAllMapLayers()
@@ -457,7 +472,7 @@ def test_addRemoveLayersSignals(self):
self.assertEqual(len(layer_removed_spy), 4)
self.assertEqual(len(remove_all_spy), 1)

#remove a layer which isn't in the registry
#remove some layers which aren't in the registry
QgsMapLayerRegistry.instance().removeMapLayers(['asdasd'])
self.assertEqual(len(layers_will_be_removed_spy), 3)
self.assertEqual(len(layer_will_be_removed_spy_str), 4)
@@ -466,6 +481,15 @@ def test_addRemoveLayersSignals(self):
self.assertEqual(len(layer_removed_spy), 4)
self.assertEqual(len(remove_all_spy), 1)

l5 = createLayer('test5')
QgsMapLayerRegistry.instance().removeMapLayer(l5)
self.assertEqual(len(layers_will_be_removed_spy), 3)
self.assertEqual(len(layer_will_be_removed_spy_str), 4)
self.assertEqual(len(layer_will_be_removed_spy_layer), 4)
self.assertEqual(len(layers_removed_spy), 3)
self.assertEqual(len(layer_removed_spy), 4)
self.assertEqual(len(remove_all_spy), 1)

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

0 comments on commit e102111

Please sign in to comment.
You can’t perform that action at this time.