117 changes: 58 additions & 59 deletions python/plugins/sextante/tests/QgisAlgsTest.py

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions python/plugins/sextante/tests/RunAlgTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ def parametrize(testcase_klass, useTempFiles):
for name in testnames:
suite.addTest(testcase_klass(name, useTempFiles=useTempFiles))
return suite

class RunAlgTest(ParametrizedTestCase):
'''This test takes a reduced set of algorithms and executes them in different ways, changing
parameters such as whether to use temp outputs, the output file format, etc.
'''This test takes a reduced set of algorithms and executes them in different ways, changing
parameters such as whether to use temp outputs, the output file format, etc.
Basically, it uses some algorithms to test other parts of SEXTANTE, not the algorithms themselves'''

def getOutputFile(self):
if self.useTempFiles:
return None
else:
return SextanteUtils.getTempFilename('shp')

def test_qgiscountpointsinpolygon(self):
outputs=sextante.runalg("qgis:countpointsinpolygon",polygons(),points(),"NUMPOINTS", self.getOutputFile())
output=outputs['OUTPUT']
Expand All @@ -49,16 +49,15 @@ def test_qgiscountpointsinpolygon(self):
expectedvalues=["1","1.1","string a","6"]
values=[str(attr.toString()) for attr in attrs]
self.assertEqual(expectedvalues, values)

def suite():
suite = unittest.TestSuite()
suite.addTest(ParametrizedTestCase.parametrize(RunAlgTest, False))
suite.addTest(ParametrizedTestCase.parametrize(RunAlgTest, True))
suite.addTest(ParametrizedTestCase.parametrize(RunAlgTest, True))
return suite

def runtests():
result = unittest.TestResult()
result = unittest.TestResult()
testsuite = suite()
testsuite.run(result)
return result

36 changes: 18 additions & 18 deletions python/plugins/sextante/tests/SagaTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

class SagaTest(unittest.TestCase):
'''tests for saga algorithms'''
'''the following tests are not meant to test the algorithms themselves,
but the algorithm provider, testing things such as the file conversion,


'''the following tests are not meant to test the algorithms themselves,
but the algorithm provider, testing things such as the file conversion,
the selection awareness of SAGA process, etc'''

def test_SagaVvectorAlgorithmWithSelection(self):
layer = sextante.getobject(polygons2());
feature = layer.getFeatures().next()
selected = [feature.id()]
selected = [feature.id()]
layer.setSelectedFeatures(selected)
outputs=sextante.runalg("saga:polygoncentroids",polygons2(),True,None)
output=outputs['CENTROIDS']
Expand All @@ -37,12 +37,12 @@ def test_SagaVvectorAlgorithmWithSelection(self):
self.assertEqual(expectedvalues, values)
wkt='POINT(270820.58189697 4458968.73298999)'
self.assertEqual(wkt, str(feature.geometry().exportToWkt()))

def test_SagaVectorAlgorithWithUnsupportedInputAndOutputFormat(self):
'''this tests both the exporting to shp and then the format change in the output layer'''
'''this tests both the exporting to shp and then the format change in the output layer'''
layer = sextante.getobject(polygonsGeoJson());
feature = layer.getFeatures().next()
selected = [feature.id()]
selected = [feature.id()]
layer.setSelectedFeatures(selected)
outputs=sextante.runalg("saga:polygoncentroids",polygonsGeoJson(),True, SextanteUtils.getTempFilename("geojson"))
output=outputs['CENTROIDS']
Expand All @@ -62,20 +62,20 @@ def test_SagaVectorAlgorithWithUnsupportedInputAndOutputFormat(self):
values=[str(attr.toString()) for attr in attrs]
self.assertEqual(expectedvalues, values)
wkt='POINT(270787.49991451 4458955.46775295)'
self.assertEqual(wkt, str(feature.geometry().exportToWkt()))

self.assertEqual(wkt, str(feature.geometry().exportToWkt()))












def suite():
suite = unittest.makeSuite(SagaTest, 'test')
suite = unittest.makeSuite(SagaTest, 'test')
return suite

def runtests():
result = unittest.TestResult()
result = unittest.TestResult()
testsuite = suite()
testsuite.run(result)
return result
14 changes: 7 additions & 7 deletions python/plugins/sextante/tests/ScriptTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class ScriptTest(unittest.TestCase):
'''tests that use scripts'''

def test_scriptcreatetilingfromvectorlayer(self):
outputs=sextante.runalg("script:createtilingfromvectorlayer",union(),10,None)
output=outputs['polygons']
Expand All @@ -27,7 +27,7 @@ def test_scriptcreatetilingfromvectorlayer(self):
self.assertEqual(expectedvalues, values)
wkt='POLYGON((270755.54427424 4458901.23378639,270755.54427424 4458995.35799007,270767.28651824 4458995.35799007,270767.28651824 4458901.23378639,270755.54427424 4458901.23378639))'
self.assertEqual(wkt, str(feature.geometry().exportToWkt()))

def test_scripthexgridfromlayerbounds(self):
outputs=sextante.runalg("script:hexgridfromlayerbounds",polygons(),10,None)
output=outputs['grid']
Expand All @@ -48,18 +48,18 @@ def test_scripthexgridfromlayerbounds(self):
self.assertEqual(expectedvalues, values)
wkt='POLYGON((270771.39533669 4458907.27146471,270768.50858535 4458902.27146471,270762.73508265 4458902.27146471,270759.84833131 4458907.27146471,270762.73508265 4458912.27146471,270768.50858535 4458912.27146471,270771.39533669 4458907.27146471))'
self.assertEqual(wkt, str(feature.geometry().exportToWkt()))

def test_scriptascriptthatreturnsanumber(self):
outputs=sextante.runalg("script:ascriptthatreturnsanumber")
output=outputs['number']
self.assertTrue(10, output.value)
self.assertTrue(10, output.value)

def suite():
suite = unittest.makeSuite(ScriptTest, 'test')
suite = unittest.makeSuite(ScriptTest, 'test')
return suite

def runtests():
result = unittest.TestResult()
result = unittest.TestResult()
testsuite = suite()
testsuite.run(result)
return result
10 changes: 5 additions & 5 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6244,11 +6244,11 @@ class QgsPythonRunnerImpl : public QgsPythonRunner

virtual bool evalCommand( QString command, QString &result )
{
if ( mPythonUtils && mPythonUtils->isEnabled() )
{
return mPythonUtils->evalString( command, result );
}
return false;
if ( mPythonUtils && mPythonUtils->isEnabled() )
{
return mPythonUtils->evalString( command, result );
}
return false;
}

protected:
Expand Down
12 changes: 6 additions & 6 deletions src/core/composer/qgscomposerlegendstyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,29 @@ class CORE_EXPORT QgsComposerLegendStyle
QFont & rfont() { return mFont; }
void setFont( const QFont & font ) { mFont = font; }

double margin( Side side ) { return mMarginMap.value( side ); }
double margin( Side side ) { return mMarginMap.value( side ); }
void setMargin( Side side, double margin ) { mMarginMap[side] = margin; }

// set all margins
void setMargin( double margin );

void writeXML( QString name, QDomElement& elem, QDomDocument & doc ) const;
void writeXML( QString name, QDomElement& elem, QDomDocument & doc ) const;

void readXML( const QDomElement& elem, const QDomDocument& doc );

/** Get name for style, used in project file */
static QString styleName ( Style s );
static QString styleName( Style s );

/** Get style from name, used in project file */
static Style styleFromName ( QString styleName );
static Style styleFromName( QString styleName );

/** Get style label, translated, used in UI */
static QString styleLabel ( Style s );
static QString styleLabel( Style s );

private:
QFont mFont;
// Space around element
QMap<Side,double> mMarginMap;
QMap<Side, double> mMarginMap;
};

#endif
2 changes: 1 addition & 1 deletion src/core/qgsfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ QgsFeature::QgsFeature( const QgsFields &fields, QgsFeatureId id )
, mValid( false )
, mFields( &fields )
{
initAttributes( fields.count() );
initAttributes( fields.count() );
}

QgsFeature::QgsFeature( QgsFeature const & rhs )
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgspallabeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1753,14 +1753,14 @@ void QgsPalLabeling::drawLabeling( QgsRenderContext& context )
{
// Set the painter composition mode for the buffer
painter->setCompositionMode( mMapRenderer->getCompositionMode( bufferBlendMode ) );

int bufferPixelSize = lyr.sizeToPixel( bufferSize, context, true );
drawLabel( *it, painter, fontForLabel, fontColor, xform, bufferPixelSize, bufferColor, true );
}

// Set the painter composition mode before rendering the label
painter->setCompositionMode( mMapRenderer->getCompositionMode( blendMode ) );

drawLabel( *it, painter, fontForLabel, fontColor, xform );

if ( mLabelSearchTree )
Expand Down
18 changes: 9 additions & 9 deletions src/core/qgspythonrunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ bool QgsPythonRunner::run( QString command, QString messageOnError )

bool QgsPythonRunner::eval( QString command, QString& result )
{
if ( mInstance )
{
return mInstance->evalCommand( command, result );
}
else
{
QgsDebugMsg( "Unable to run Python command: runner not available!" );
return false;
}
if ( mInstance )
{
return mInstance->evalCommand( command, result );
}
else
{
QgsDebugMsg( "Unable to run Python command: runner not available!" );
return false;
}
}

void QgsPythonRunner::setInstance( QgsPythonRunner* runner )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgspythonrunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CORE_EXPORT QgsPythonRunner
static bool run( QString command, QString messageOnError = QString() );

/** Eval a python statement */
static bool eval( QString command, QString& result);
static bool eval( QString command, QString& result );

/** assign an instance of python runner so that run() can be used.
This method should be called during app initialization.
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayercache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ void QgsVectorLayerCache::geometryChanged( QgsFeatureId fid, QgsGeometry& geom )

void QgsVectorLayerCache::layerDeleted()
{
emit ( cachedLayerDeleted() );
emit( cachedLayerDeleted() );

mLayer = NULL;
}
Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgsattributedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
/* Reload the module if the DEBUGMODE switch has been set in the module.
If set to False you have to reload QGIS to reset it to True due to Python
module caching */
QString reload = QString("if hasattr(%1,'DEBUGMODE') and %1.DEBUGMODE:"
" reload(%1)").arg( module.left( pos ) );
QString reload = QString( "if hasattr(%1,'DEBUGMODE') and %1.DEBUGMODE:"
" reload(%1)" ).arg( module.left( pos ) );

QgsPythonRunner::run( reload );

Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmaptool.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class GUI_EXPORT QgsMapTool : public QObject

//! Mouse wheel event for overriding. Default implementation does nothing.
//! Added in version 2.0
virtual void wheelEvent ( QWheelEvent* e );
virtual void wheelEvent( QWheelEvent* e );

//! Key event for overriding. Default implementation does nothing.
virtual void keyPressEvent( QKeyEvent* e );
Expand Down
14 changes: 7 additions & 7 deletions tests/src/core/testqgsvectorlayercache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void TestVectorLayerCache::initTestCase()
QString myDataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt
QString myTestDataDir = myDataDir + QDir::separator();

foreach( QString f, backupFiles )
foreach ( QString f, backupFiles )
{
QTemporaryFile* tmpFile = new QTemporaryFile();
tmpFile->open();
Expand Down Expand Up @@ -99,7 +99,7 @@ void TestVectorLayerCache::cleanupTestCase()
if ( mAddedFeatures.length() > 0 )
{
mPointsLayer->startEditing();
foreach( QgsFeature f, mAddedFeatures )
foreach ( QgsFeature f, mAddedFeatures )
{
mPointsLayer->deleteFeature( f.id() );
}
Expand All @@ -116,7 +116,7 @@ void TestVectorLayerCache::cleanupTestCase()
// Clean tmp files
QMap<QString, QString>::const_iterator it;

for( it = mTmpFiles.constBegin(); it != mTmpFiles.constEnd(); ++it )
for ( it = mTmpFiles.constBegin(); it != mTmpFiles.constEnd(); ++it )
{
QString tmpFileName = it.value();
QString origFileName = it.key();
Expand All @@ -141,7 +141,7 @@ void TestVectorLayerCache::testCacheOverflow()
}
it.close();

QVERIFY ( i == 17 );
QVERIFY( i == 17 );
}

void TestVectorLayerCache::testCacheAttrActions()
Expand Down Expand Up @@ -179,9 +179,9 @@ void TestVectorLayerCache::testFeatureActions()
mPointsLayer->startEditing();
QVERIFY( mPointsLayer->addFeature( f ) );

connect( mPointsLayer, SIGNAL(committedFeaturesAdded(QString,QgsFeatureList)), SLOT(onCommittedFeaturesAdded(QString,QgsFeatureList)));
connect( mPointsLayer, SIGNAL( committedFeaturesAdded( QString, QgsFeatureList ) ), SLOT( onCommittedFeaturesAdded( QString, QgsFeatureList ) ) );
mPointsLayer->commitChanges();
disconnect( mPointsLayer, SIGNAL(committedFeaturesAdded(QString,QgsFeatureList)), this,SLOT(onCommittedFeaturesAdded(QString,QgsFeatureList)));
disconnect( mPointsLayer, SIGNAL( committedFeaturesAdded( QString, QgsFeatureList ) ), this, SLOT( onCommittedFeaturesAdded( QString, QgsFeatureList ) ) );

QgsFeatureId fid = mAddedFeatures.last().id();

Expand All @@ -197,7 +197,7 @@ void TestVectorLayerCache::testFeatureActions()

void TestVectorLayerCache::onCommittedFeaturesAdded( QString layerId, QgsFeatureList features )
{
Q_UNUSED ( layerId )
Q_UNUSED( layerId )
mAddedFeatures.append( features );
}

Expand Down