Skip to content
Permalink
Browse files
Update unit tests for raster layer
  • Loading branch information
pblottiere committed May 18, 2017
1 parent 9f8b92d commit 344b964709c925990a51e3cdc1dda2c4ddf5829f
Showing with 30 additions and 3 deletions.
  1. +4 −2 src/core/raster/qgsrasterlayer.cpp
  2. +26 −1 tests/src/python/test_qgsrasterlayer.py
@@ -149,9 +149,11 @@ QgsRasterLayer *QgsRasterLayer::clone() const
QgsRasterLayer *layer = new QgsRasterLayer( source(), originalName(), mProviderKey );
QgsMapLayer::clone( layer );

for ( int i = 0; i < mPipe.size(); i++ )
// do not clone data provider which is the first element in pipe
for ( int i = 1; i < mPipe.size(); i++ )
{
layer->pipe()->set( mPipe.at( i )->clone() );
if ( mPipe.at( i ) )
layer->pipe()->set( mPipe.at( i )->clone() );
}

return layer;
@@ -23,6 +23,7 @@

from qgis.core import (QgsRaster,
QgsRasterLayer,
QgsReadWriteContext,
QgsColorRampShader,
QgsContrastEnhancement,
QgsProject,
@@ -666,8 +667,32 @@ def testClone(self):
renderer.setOpacity(33.3)
layer.setRenderer(renderer)

# clone layer
clone = layer.clone()
self.assertEqual(clone.renderer().opacity(), 33.3)

# generate xml from layer
layer_doc = QDomDocument("doc")
layer_elem = layer_doc.createElement("maplayer")
layer.writeLayerXml(layer_elem, layer_doc, QgsReadWriteContext())

# generate xml from clone
clone_doc = QDomDocument("doc")
clone_elem = clone_doc.createElement("maplayer")
clone.writeLayerXml(clone_elem, clone_doc, QgsReadWriteContext())

# replace id within xml of clone
clone_id_elem = clone_elem.firstChildElement("id")
clone_id_elem_patch = clone_doc.createElement("id")
clone_id_elem_patch_value = clone_doc.createTextNode(layer.id())
clone_id_elem_patch.appendChild(clone_id_elem_patch_value)
clone_elem.replaceChild(clone_id_elem_patch, clone_id_elem)

# update doc
clone_doc.appendChild(clone_elem)
layer_doc.appendChild(layer_elem)

# compare xml documents
self.assertEqual(layer_doc.toString(), clone_doc.toString())


if __name__ == '__main__':

0 comments on commit 344b964

Please sign in to comment.