Skip to content
Permalink
Browse files
test fixes:
* port python test to sip api v2 (fixes #8314)
* introduce compareWkt for more tolerant WKT comparisions in C++ tests
* require UTF-8 locale for regression1141 test on linux
  • Loading branch information
jef-n committed Jul 19, 2013
1 parent 6831498 commit 51074d7b82aa245ab6fadf04df54302b1d9c2217
Showing with 177 additions and 91 deletions.
  1. +1 −0 scripts/spelling.dat
  2. +4 −4 src/core/qgsrenderchecker.cpp
  3. +53 −1 src/core/qgsrenderchecker.h
  4. +15 −1 tests/src/core/regression1141.cpp
  5. +2 −1 tests/src/core/testqgsexpression.cpp
  6. +0 −1 tests/src/core/testqgsgeometry.cpp
  7. +1 −0 tests/src/python/qgis_interface.py
  8. +3 −1 tests/src/python/qgscompositionchecker.py
  9. +3 −1 tests/src/python/test_qgsanalysis.py
  10. +1 −0 tests/src/python/test_qgsapplication.py
  11. +14 −13 tests/src/python/test_qgsatlascomposition.py
  12. +5 −4 tests/src/python/test_qgsblendmodes.py
  13. +2 −2 tests/src/python/test_qgscomposereffects.py
  14. +3 −2 tests/src/python/test_qgscomposerhtml.py
  15. +6 −5 tests/src/python/test_qgscomposerlabel.py
  16. +3 −3 tests/src/python/test_qgscomposermap.py
  17. +3 −2 tests/src/python/test_qgscomposition.py
  18. +1 −0 tests/src/python/test_qgscoordinatetransform.py
  19. +4 −9 tests/src/python/test_qgsdelimitedtextprovider.py
  20. +4 −4 tests/src/python/test_qgsexpression.py
  21. +10 −8 tests/src/python/test_qgsfeature.py
  22. +4 −4 tests/src/python/test_qgsgeometry.py
  23. +1 −0 tests/src/python/test_qgsissue7244.py
  24. +1 −0 tests/src/python/test_qgslogger.py
  25. +1 −0 tests/src/python/test_qgspallabeling.py
  26. +1 −0 tests/src/python/test_qgspoint.py
  27. +1 −0 tests/src/python/test_qgsrasterfilewriter.py
  28. +5 −5 tests/src/python/test_qgsrasterlayer.py
  29. +1 −0 tests/src/python/test_qgsrectangle.py
  30. +1 −0 tests/src/python/test_qgsspatialindex.py
  31. +1 −0 tests/src/python/test_qgsspatialiteprovider.py
  32. +3 −4 tests/src/python/test_qgsvectorfilewriter.py
  33. +15 −13 tests/src/python/test_qgszonalstatistics.py
  34. +4 −3 tests/src/python/utilities.py
@@ -467,3 +467,4 @@ widht:width
heigth:height
heigh:height
delimted:delimited
teh:the
@@ -75,7 +75,7 @@ bool QgsRenderChecker::isKnownAnomaly( QString theDiffImageFile )
QString myFilename = "*";
myList = myDirectory.entryList( QStringList( myFilename ),
QDir::Files | QDir::NoSymLinks );
//remove the control file from teh list as the anomalies are
//remove the control file from the list as the anomalies are
//all files except the control file
myList.removeAt( myList.indexOf( mExpectedImageFile ) );

@@ -241,11 +241,11 @@ bool QgsRenderChecker::compareImages( QString theTestName,
//
QString myDashMessage = "<DartMeasurementFile name=\"Rendered Image " + theTestName + "\""
" type=\"image/png\">" + mRenderedImageFile +
"</DartMeasurementFile>"
"</DartMeasurementFile>\n"
"<DartMeasurementFile name=\"Expected Image " + theTestName + "\" type=\"image/png\">" +
mExpectedImageFile + "</DartMeasurementFile>"
mExpectedImageFile + "</DartMeasurementFile>\n"
"<DartMeasurementFile name=\"Difference Image " + theTestName + "\" type=\"image/png\">" +
myDiffImageFile + "</DartMeasurementFile>";
myDiffImageFile + "</DartMeasurementFile>\n";
qDebug( ) << myDashMessage;

//
@@ -16,9 +16,15 @@
#ifndef QGSRENDERCHECKER_H
#define QGSRENDERCHECKER_H

#include <qgis.h>
#include <QDir>
#include <QString>
#include <QRegExp>
#include <QList>

#include <qgsmaprenderer.h>
#include <qgslogger.h>

class QImage;

/** \ingroup UnitTests
@@ -86,7 +92,7 @@ class CORE_EXPORT QgsRenderChecker
* @note: make sure to call setExpectedImage and setRenderedImage first.
*/
bool compareImages( QString theTestName, unsigned int theMismatchCount = 0, QString theRenderedImageFile = "" );
/** Get a list of all teh anomalies. An anomaly is a rendered difference
/** Get a list of all the anomalies. An anomaly is a rendered difference
* file where there is some red pixel content (indicating a render check
* mismatch), but where the output was still acceptible. If the render
* diff matches one of these anomalies we will still consider it to be
@@ -110,4 +116,50 @@ class CORE_EXPORT QgsRenderChecker

}; // class QgsRenderChecker


/** Compare two WKT strings with some tolerance
* @param a first WKT string
* @param b second WKT string
* @param tolerance tolerance to use (optional, defaults to 0.000001)
* @return bool indicating if the WKT are sufficiently equal
*/

inline bool compareWkt( QString a, QString b, double tolerance = 0.000001 )
{
QgsDebugMsg( QString( "a:%1 b:%2 tol:%3" ).arg( a ).arg( b ).arg( tolerance ) );
QRegExp re( "-?\\d+(?:\\.\\d+)?(?:[eE]\\d+)?" );

QString a0( a ), b0( b );
a0.replace( re, "#" );
b0.replace( re, "#" );

QgsDebugMsg( QString( "a0:%1 b0:%2" ).arg( a0 ).arg( b0 ) );

if ( a0 != b0 )
return false;

QList<double> al, bl;

int pos;
for ( pos = 0; ( pos = re.indexIn( a, pos ) ) != -1; pos += re.matchedLength() )
{
al << re.cap( 0 ).toDouble();
}
for ( pos = 0; ( pos = re.indexIn( b, pos ) ) != -1; pos += re.matchedLength() )
{
bl << re.cap( 0 ).toDouble();
}

if ( al.size() != bl.size() )
return false;

for ( int i = 0; i < al.size(); i++ )
{
if ( !qgsDoubleNear( al[i], bl[i], tolerance ) )
return false;
}

return true;
}

#endif
@@ -19,7 +19,6 @@
#include <QObject>
#include <QPainter>
#include <QTime>
#include <iostream>

#include <QApplication>
#include <QDesktopServices>
@@ -35,6 +34,11 @@
#include <qgsfield.h>
#include <qgis.h> //defines GEOWkt
#include <qgsproviderregistry.h>
#include <qgslogger.h>

#if defined(linux)
#include <langinfo.h>
#endif


/** \ingroup UnitTests
@@ -90,6 +94,16 @@ void Regression1141::cleanupTestCase()

void Regression1141::diacriticalTest()
{
#if defined(linux)
const char *cs = nl_langinfo( CODESET );
QgsDebugMsg( QString( "CODESET:%1" ).arg( cs ? cs : "unset" ) );
if ( !cs || strcmp( cs, "UTF-8" ) != 0 )
{
QSKIP( "This test requires a UTF-8 locale", SkipSingle );
return;
}
#endif

//create some objects that will be used in all tests...
mEncoding = "UTF-8";
QgsField myField( "ąęćń", QVariant::Int, "int", 10, 0, "Value on lon" );
@@ -21,6 +21,7 @@
#include <qgsexpression.h>
#include <qgsfeature.h>
#include <qgsgeometry.h>
#include <qgsrenderchecker.h>

#if QT_VERSION < 0x40701
// See http://hub.qgis.org/issues/4284
@@ -809,7 +810,7 @@ class TestQgsExpression: public QObject

QCOMPARE( out.canConvert<QgsGeometry>(), true );
QgsGeometry outGeom = out.value<QgsGeometry>();
QCOMPARE( outGeom.exportToWkt(), result->exportToWkt() );
QVERIFY( compareWkt( outGeom.exportToWkt(), result->exportToWkt() ) );
}

void eval_special_columns()
@@ -370,7 +370,6 @@ void TestQgsGeometry::dumpPolyline( QgsPolyline &thePolyline )
mpPainter->drawPolyline( myPoints );
}


QTEST_MAIN( TestQgsGeometry )
#include "moc_testqgsgeometry.cxx"

@@ -24,6 +24,7 @@
'Copyright (c) 2011 German Carrillo, '
'geotux_tuxman@linuxmail.org')

import qgis

from PyQt4.QtCore import QObject
from qgis.core import QgsMapLayerRegistry
@@ -14,6 +14,8 @@
* *
***************************************************************************/
'''
import qgis

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
@@ -92,7 +94,7 @@ def compareImages( self, imgExpected, imgRendered, differenceImagePath ):
mismatchCount = mismatchCount + 1
differenceImage.setPixel( j, i, qRgb( 255, 0, 0 ) )

if not differenceImagePath.isEmpty():
if differenceImagePath != "":
differenceImage.save( differenceImagePath, "PNG" )

#allow pixel deviation of 1 percent
@@ -17,8 +17,10 @@
import unittest
import sys
import os
import qgis

from utilities import unitTestDataPath, getQgisTestApp
from PyQt4.QtCore import QFileInfo, QDir, QStringList
from PyQt4.QtCore import QFileInfo, QDir
from PyQt4.QtXml import QDomDocument

# support python < 2.7 via unittest2
@@ -11,6 +11,7 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import qgis
from utilities import getQgisTestApp, unittest
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()

@@ -14,6 +14,7 @@
* *
***************************************************************************/
'''
import qgis
import unittest
from utilities import *
from PyQt4.QtCore import *
@@ -28,14 +29,14 @@ class TestQgsAtlasComposition(unittest.TestCase):

def testCase(self):
self.TEST_DATA_DIR = unitTestDataPath()
vectorFileInfo = QFileInfo( self.TEST_DATA_DIR + QDir().separator().toAscii() + "france_parts.shp")
vectorFileInfo = QFileInfo( self.TEST_DATA_DIR + QDir().separator() + "france_parts.shp")
mVectorLayer = QgsVectorLayer( vectorFileInfo.filePath(), vectorFileInfo.completeBaseName(), "ogr" )

QgsMapLayerRegistry.instance().addMapLayers( [mVectorLayer] )

# create composition with composer map
mMapRenderer = QgsMapRenderer()
layerStringList = QStringList()
layerStringList = []
layerStringList.append( mVectorLayer.id() )
mMapRenderer.setLayerSet( layerStringList )
mMapRenderer.setProjectionsEnabled( True )
@@ -102,7 +103,7 @@ def filename_test( self ):
self.mAtlas.beginRender()
for i in range(0, self.mAtlas.numFeatures()):
self.mAtlas.prepareForFeature( i )
expected = QString( "output_%1" ).arg(i+1)
expected = "output_%d" % (i+1)
assert self.mAtlas.currentFilename() == expected
self.mAtlas.endRender()

@@ -118,10 +119,10 @@ def autoscale_render_test( self ):

checker = QgsCompositionChecker()
res = checker.testComposition( "Atlas autoscale test", self.mComposition, \
QString( self.TEST_DATA_DIR ) + QDir.separator() + \
self.TEST_DATA_DIR + QDir.separator() + \
"control_images" + QDir.separator() + \
"expected_composermapatlas" + QDir.separator() + \
QString( "autoscale_%1.png" ).arg( i ) )
"autoscale_%d.png" % i )
assert res[0] == True
self.mAtlas.endRender()

@@ -137,10 +138,10 @@ def fixedscale_render_test( self ):

checker = QgsCompositionChecker()
res = checker.testComposition( "Atlas fixed scale test", self.mComposition, \
QString( self.TEST_DATA_DIR ) + QDir.separator() + \
self.TEST_DATA_DIR + QDir.separator() + \
"control_images" + QDir.separator() + \
"expected_composermapatlas" + QDir.separator() + \
QString( "fixedscale_%1.png" ).arg( i ) )
"fixedscale_%d.png" % i )
assert res[0] == True
self.mAtlas.endRender()

@@ -157,10 +158,10 @@ def hidden_render_test( self ):

checker = QgsCompositionChecker()
res = checker.testComposition( "Atlas hidden test", self.mComposition, \
QString( self.TEST_DATA_DIR ) + QDir.separator() + \
self.TEST_DATA_DIR + QDir.separator() + \
"control_images" + QDir.separator() + \
"expected_composermapatlas" + QDir.separator() + \
QString( "hiding_%1.png" ).arg( i ) )
"hiding_%d.png" % i )
assert res[0] == True
self.mAtlas.endRender()

@@ -181,10 +182,10 @@ def sorting_render_test( self ):

checker = QgsCompositionChecker()
res = checker.testComposition( "Atlas sorting test", self.mComposition, \
QString( self.TEST_DATA_DIR ) + QDir.separator() + \
self.TEST_DATA_DIR + QDir.separator() + \
"control_images" + QDir.separator() + \
"expected_composermapatlas" + QDir.separator() + \
QString( "sorting_%1.png" ).arg( i ) )
"sorting_%d.png" % i )
assert res[0] == True
self.mAtlas.endRender()

@@ -206,10 +207,10 @@ def filtering_render_test( self ):

checker = QgsCompositionChecker()
res = checker.testComposition( "Atlas filtering test", self.mComposition, \
QString( self.TEST_DATA_DIR ) + QDir.separator() + \
self.TEST_DATA_DIR + QDir.separator() + \
"control_images" + QDir.separator() + \
"expected_composermapatlas" + QDir.separator() + \
QString( "filtering_%1.png" ).arg( i ) )
"filtering_%d.png" % i )
assert res[0] == True
self.mAtlas.endRender()

@@ -24,6 +24,7 @@
__revision__ = '$Format:%H$'

import os
import qgis

from PyQt4.QtCore import *
from PyQt4.QtGui import *
@@ -95,7 +96,7 @@ def testVectorBlending(self):
"""Test that blend modes work for vector layers."""

#Add vector layers to map
myLayers = QStringList()
myLayers = []
myLayers.append(self.mLineLayer.id())
myLayers.append(self.mPolygonLayer.id())
self.mMapRenderer.setLayerSet(myLayers)
@@ -121,7 +122,7 @@ def testVectorFeatureBlending(self):
"""Test that feature blend modes work for vector layers."""

#Add vector layers to map
myLayers = QStringList()
myLayers = []
myLayers.append(self.mLineLayer.id())
myLayers.append(self.mPolygonLayer.id())
self.mMapRenderer.setLayerSet(myLayers)
@@ -145,7 +146,7 @@ def testVectorLayerTransparency(self):
"""Test that layer transparency works for vector layers."""

#Add vector layers to map
myLayers = QStringList()
myLayers = []
myLayers.append(self.mLineLayer.id())
myLayers.append(self.mPolygonLayer.id())
self.mMapRenderer.setLayerSet(myLayers)
@@ -165,7 +166,7 @@ def testVectorLayerTransparency(self):
def testRasterBlending(self):
"""Test that blend modes work for raster layers."""
#Add raster layers to map
myLayers = QStringList()
myLayers = []
myLayers.append(self.mRasterLayer1.id())
myLayers.append(self.mRasterLayer2.id())
self.mMapRenderer.setLayerSet(myLayers)
@@ -13,8 +13,8 @@
__revision__ = '$Format:%H$'

import os
from PyQt4.QtCore import (QStringList,
QFileInfo)
import qgis
from PyQt4.QtCore import QFileInfo
from PyQt4.QtXml import QDomDocument
from PyQt4.QtGui import (QPainter, QColor)

@@ -14,7 +14,8 @@

import unittest
import os
from PyQt4.QtCore import QUrl, QString, qDebug
import qgis
from PyQt4.QtCore import QUrl, qDebug
from PyQt4.QtXml import QDomDocument
from qgis.core import (QgsComposition,
QgsComposerHtml,
@@ -54,7 +55,7 @@ def controlImagePath(self, theImageName):
def htmlUrl(self):
"""Helper to get the url of the html doc."""
myPath = os.path.join(TEST_DATA_DIR, "html_table.html")
myUrl = QUrl(QString("file:///%1").arg(myPath))
myUrl = QUrl("file:///%1").arg(myPath)
return myUrl

@expectedFailure

0 comments on commit 51074d7

Please sign in to comment.