Skip to content
Permalink
Browse files

address comments, fix test

  • Loading branch information
nirvn committed Sep 4, 2018
1 parent 65d9911 commit 5cd28034bd8300a595aa2c9b585166fa30c812ba
@@ -2,7 +2,7 @@

"""
***************************************************************************
translate.py
rearrange_bands.py
---------------------
Date : August 2018
Copyright : (C) 2018 by Mathieu Pellerin
@@ -52,6 +52,7 @@
from processing.algs.gdal.translate import translate
from processing.algs.gdal.warp import warp
from processing.algs.gdal.fillnodata import fillnodata
from processing.algs.gdal.rearrange_bands import rearrange_bands

from qgis.core import (QgsProcessingContext,
QgsProcessingFeedback,
@@ -1532,6 +1533,33 @@ def testWarp(self):
source + ' ' +
'd:/temp/check.jpg'])

def testRearrangeBands(self):
context = QgsProcessingContext()
feedback = QgsProcessingFeedback()
source = os.path.join(testDataPath, 'dem.tif')
outsource = 'd:/temp/check.tif'

alg = rearrange_bands()
alg.initAlgorithm()

# single band
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'BANDS': 1,
'OUTPUT': outsource}, context, feedback),
['gdal_translate', '-b 1 ' +
'-ot Float32 -of GTiff ' +
source + ' ' + outsource])

# three bands, re-ordered
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'BANDS': [3, 2, 1],
'OUTPUT': outsource}, context, feedback),
['gdal_translate', '-b 3 -b 2 -b 1 ' +
'-ot Float32 -of GTiff ' +
source + ' ' + outsource])

def testFillnodata(self):
context = QgsProcessingContext()
feedback = QgsProcessingFeedback()
@@ -1703,6 +1703,7 @@ void TestQgsProcessing::parameters()
params.insert( QStringLiteral( "string" ), QStringLiteral( "a string" ) );
params.insert( QStringLiteral( "double" ), 5.2 );
params.insert( QStringLiteral( "int" ), 15 );
params.insert( QStringLiteral( "ints" ), QVariant( QList<QVariant>() << 3 << 2 << 1 ) );
params.insert( QStringLiteral( "bool" ), true );

QgsProcessingContext context;
@@ -1763,6 +1764,12 @@ void TestQgsProcessing::parameters()
def->setName( QStringLiteral( "prop" ) );
QCOMPARE( QgsProcessingParameters::parameterAsInt( def.get(), params, context ), 6 );

// as ints
def->setName( QStringLiteral( "int" ) );
QCOMPARE( QgsProcessingParameters::parameterAsInts( def.get(), params, context ), QList<int>() << 15 );
def->setName( QStringLiteral( "ints" ) );
QCOMPARE( QgsProcessingParameters::parameterAsInts( def.get(), params, context ), QList<int>() << 3 << 2 << 1 );

// as bool
def->setName( QStringLiteral( "double" ) );
QCOMPARE( QgsProcessingParameters::parameterAsBool( def.get(), params, context ), true );

0 comments on commit 5cd2803

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