Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
address comments, fix test
  • Loading branch information
nirvn committed Sep 4, 2018
1 parent 65d9911 commit 5cd2803
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/rearrange_bands.py
Expand Up @@ -2,7 +2,7 @@

"""
***************************************************************************
translate.py
rearrange_bands.py
---------------------
Date : August 2018
Copyright : (C) 2018 by Mathieu Pellerin
Expand Down
28 changes: 28 additions & 0 deletions python/plugins/processing/tests/GdalAlgorithmsTest.py
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions tests/src/analysis/testqgsprocessing.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 5cd2803

Please sign in to comment.