Skip to content

Commit

Permalink
Followup 5daa54, add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 4, 2016
1 parent 3d8269e commit e102111
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion tests/src/python/test_qgsmaplayerregistry.py
Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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()

Expand Down

0 comments on commit e102111

Please sign in to comment.