mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
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
This commit is contained in:
parent
6831498484
commit
51074d7b82
@ -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__ = ('Copyright (c) 2010 by Ivan Mincik, ivan.mincik@gista.sk and '
|
||||
'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 @@ qgscompositionchecker.py - check rendering of Qgscomposition against an expected
|
||||
* *
|
||||
***************************************************************************/
|
||||
'''
|
||||
import qgis
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
from PyQt4.QtGui import *
|
||||
from qgis.core import *
|
||||
@ -92,7 +94,7 @@ class QgsCompositionChecker:
|
||||
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 @@ test_analysis.py
|
||||
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 @@ __copyright__ = 'Copyright 2012, The QGIS Project'
|
||||
# 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 @@ test_qgsatlascomposition.py
|
||||
* *
|
||||
***************************************************************************/
|
||||
'''
|
||||
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 @@ class TestQgsAtlasComposition(unittest.TestCase):
|
||||
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 @@ class TestQgsAtlasComposition(unittest.TestCase):
|
||||
|
||||
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 @@ class TestQgsAtlasComposition(unittest.TestCase):
|
||||
|
||||
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 @@ class TestQgsAtlasComposition(unittest.TestCase):
|
||||
|
||||
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 @@ class TestQgsAtlasComposition(unittest.TestCase):
|
||||
|
||||
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 @@ class TestQgsAtlasComposition(unittest.TestCase):
|
||||
|
||||
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 @@ __copyright__ = '(C) 2013, Nyall Dawson, Massimo Endrighi'
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
import qgis
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
from PyQt4.QtGui import *
|
||||
@ -95,7 +96,7 @@ class TestQgsBlendModes(TestCase):
|
||||
"""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 @@ class TestQgsBlendModes(TestCase):
|
||||
"""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 @@ class TestQgsBlendModes(TestCase):
|
||||
"""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 @@ class TestQgsBlendModes(TestCase):
|
||||
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 @@ __copyright__ = 'Copyright 2012, The QGIS Project'
|
||||
__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 @@ __revision__ = '$Format:%H$'
|
||||
|
||||
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 @@ class TestQgsComposerHtml(TestCase):
|
||||
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
|
||||
|
@ -15,6 +15,7 @@ test_qgscomposerlabel.py
|
||||
***************************************************************************/
|
||||
'''
|
||||
import unittest
|
||||
import qgis
|
||||
from utilities import *
|
||||
from PyQt4.QtCore import *
|
||||
from PyQt4.QtGui import *
|
||||
@ -27,14 +28,14 @@ class TestQgsComposerLabel(unittest.TestCase):
|
||||
|
||||
def testCase(self):
|
||||
TEST_DATA_DIR = unitTestDataPath()
|
||||
vectorFileInfo = QFileInfo( TEST_DATA_DIR + QDir().separator().toAscii() + "france_parts.shp")
|
||||
vectorFileInfo = QFileInfo( 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( False )
|
||||
@ -62,7 +63,7 @@ class TestQgsComposerLabel(unittest.TestCase):
|
||||
# $CURRENT_DATE() evaluation (inside an expression)
|
||||
mLabel.setText( "__[%$CURRENT_DATE(dd) + 1%](ok)__" )
|
||||
dd = QDate.currentDate().day()
|
||||
expected = "__" + QString( "%1" ).arg(dd+1) + "(ok)__"
|
||||
expected = "__%d(ok)__" % (dd+1)
|
||||
assert mLabel.displayText() == expected
|
||||
|
||||
# expression evaluation (without associated feature)
|
||||
@ -101,9 +102,9 @@ class TestQgsComposerLabel(unittest.TestCase):
|
||||
|
||||
# use setSpecialColumn
|
||||
mLabel.setText( "[%$var1 + 1%]" )
|
||||
QgsExpression.setSpecialColumn( "$var1", QVariant(41) )
|
||||
QgsExpression.setSpecialColumn( "$var1", 41 )
|
||||
assert mLabel.displayText() == "42"
|
||||
QgsExpression.setSpecialColumn( "$var1", QVariant(99) )
|
||||
QgsExpression.setSpecialColumn( "$var1", 99 )
|
||||
assert mLabel.displayText() == "100"
|
||||
QgsExpression.unsetSpecialColumn( "$var1" )
|
||||
assert mLabel.displayText() == "[%$var1 + 1%]"
|
||||
|
@ -13,8 +13,8 @@ __copyright__ = 'Copyright 2012, The QGIS Project'
|
||||
__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)
|
||||
@ -57,7 +57,7 @@ class TestQgsComposerMap(TestCase):
|
||||
|
||||
# create composition with composer map
|
||||
self.mMapRenderer = QgsMapRenderer()
|
||||
layerStringList = QStringList()
|
||||
layerStringList = []
|
||||
layerStringList.append(mRasterLayer.id())
|
||||
self.mMapRenderer.setLayerSet(layerStringList)
|
||||
self.mMapRenderer.setProjectionsEnabled(False)
|
||||
|
@ -13,8 +13,9 @@ __copyright__ = 'Copyright 2012, The QGIS Project'
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
import qgis
|
||||
|
||||
from PyQt4.QtCore import QFileInfo, QDir, QStringList
|
||||
from PyQt4.QtCore import QFileInfo, QDir
|
||||
from PyQt4.QtXml import QDomDocument
|
||||
|
||||
from qgis.core import (QgsComposition,
|
||||
@ -104,7 +105,7 @@ class TestQgsComposition(TestCase):
|
||||
QgsMapLayerRegistry.instance().addMapLayers([myRasterLayer])
|
||||
|
||||
myMapRenderer = QgsMapRenderer()
|
||||
myLayerStringList = QStringList()
|
||||
myLayerStringList = []
|
||||
myLayerStringList.append(myRasterLayer.id())
|
||||
myMapRenderer.setLayerSet(myLayerStringList)
|
||||
myMapRenderer.setProjectionsEnabled(False)
|
||||
|
@ -12,6 +12,7 @@ __copyright__ = 'Copyright 2012, The QGIS Project'
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import qgis
|
||||
from qgis.core import (QgsRectangle,
|
||||
QgsCoordinateReferenceSystem,
|
||||
QgsCoordinateTransform,
|
||||
|
@ -23,8 +23,8 @@ __revision__ = '$Format:%H$'
|
||||
#
|
||||
# To recreate all tests, set rebuildTests to true
|
||||
|
||||
import os;
|
||||
import os.path;
|
||||
import os
|
||||
import os.path
|
||||
import re
|
||||
import tempfile
|
||||
import inspect
|
||||
@ -33,13 +33,7 @@ import test_qgsdelimitedtextprovider_wanted as want
|
||||
|
||||
rebuildTests = 'REBUILD_DELIMITED_TEXT_TESTS' in os.environ;
|
||||
|
||||
|
||||
import sip
|
||||
#API_NAMES = ["QDate", "QDateTime", "QString", "QTextStream", "QTime", "QUrl", "QVariant"]
|
||||
API_NAMES = ["QString", "QUrl", "QVariant"]
|
||||
API_VERSION = 2
|
||||
for name in API_NAMES:
|
||||
sip.setapi(name, API_VERSION)
|
||||
import qgis
|
||||
|
||||
from PyQt4.QtCore import (QVariant,
|
||||
QCoreApplication,
|
||||
@ -69,6 +63,7 @@ from utilities import (getQgisTestApp,
|
||||
|
||||
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
|
||||
|
||||
import sip
|
||||
sipversion=str(sip.getapi('QVariant'))
|
||||
sipwanted='2'
|
||||
geomkey = "#geometry"
|
||||
|
@ -12,16 +12,16 @@ __copyright__ = 'Copyright 2012, The QGIS Project'
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import qgis
|
||||
from utilities import unittest, TestCase
|
||||
from qgis.utils import qgsfunction
|
||||
from qgis.core import QgsExpression
|
||||
from PyQt4.QtCore import QString
|
||||
|
||||
class TestQgsExpressionCustomFunctions(TestCase):
|
||||
@qgsfunction(1, 'testing', register=False)
|
||||
def testfun(values, feature, parent):
|
||||
""" Function help """
|
||||
return "Testing_%s" % str(values[0].toString())
|
||||
return "Testing_%s" % values[0]
|
||||
|
||||
@qgsfunction(0, 'testing', register=False)
|
||||
def special(values, feature, parent):
|
||||
@ -51,8 +51,8 @@ class TestQgsExpressionCustomFunctions(TestCase):
|
||||
def testCanEvaluateFunction(self):
|
||||
QgsExpression.registerFunction(self.testfun)
|
||||
exp = QgsExpression('testfun(1)')
|
||||
result = exp.evaluate().toString()
|
||||
self.assertEqual(QString('Testing_1'), result)
|
||||
result = exp.evaluate()
|
||||
self.assertEqual('Testing_1', result)
|
||||
|
||||
def testZeroArgFunctionsAreSpecialColumns(self):
|
||||
special = self.special
|
||||
|
@ -14,7 +14,7 @@ __revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
|
||||
from PyQt4.QtCore import QVariant
|
||||
import qgis
|
||||
from qgis.core import QgsFeature, QgsGeometry, QgsPoint, QgsVectorLayer
|
||||
from utilities import (unitTestDataPath,
|
||||
getQgisTestApp,
|
||||
@ -44,6 +44,7 @@ class TestQgsFeature(TestCase):
|
||||
fit = provider.getFeatures()
|
||||
feat = QgsFeature()
|
||||
fit.nextFeature(feat)
|
||||
fit.close()
|
||||
myValidValue = feat.isValid()
|
||||
myMessage = '\nExpected: %s\nGot: %s' % ("True", myValidValue)
|
||||
assert myValidValue == True, myMessage
|
||||
@ -55,13 +56,14 @@ class TestQgsFeature(TestCase):
|
||||
fit = provider.getFeatures()
|
||||
feat = QgsFeature()
|
||||
fit.nextFeature(feat)
|
||||
fit.close()
|
||||
myAttributes = feat.attributes()
|
||||
myExpectedAttributes = [ QVariant("Highway"), QVariant(1) ]
|
||||
myExpectedAttributes = [ "Highway", 1 ]
|
||||
|
||||
# Only for printing purposes
|
||||
myAttributeDict = [
|
||||
str(myAttributes[0].toString()),
|
||||
int(myAttributes[1].toString()) ]
|
||||
myAttributes[0],
|
||||
myAttributes[1] ]
|
||||
myExpectedAttributes = [ "Highway", 1 ]
|
||||
myMessage = '\nExpected: %s\nGot: %s' % (myExpectedAttributes,
|
||||
myAttributes)
|
||||
@ -71,11 +73,11 @@ class TestQgsFeature(TestCase):
|
||||
def test_DeleteAttribute(self):
|
||||
feat = QgsFeature()
|
||||
feat.initAttributes(3)
|
||||
feat[0] = QVariant("text1")
|
||||
feat[1] = QVariant("text2")
|
||||
feat[2] = QVariant("text3")
|
||||
feat[0] = "text1"
|
||||
feat[1] = "text2"
|
||||
feat[2] = "text3"
|
||||
feat.deleteAttribute(1)
|
||||
myAttrs = [ str(feat[0].toString()), str(feat[1].toString()) ]
|
||||
myAttrs = [ feat[0], feat[1] ]
|
||||
myExpectedAttrs = [ "text1", "text3" ]
|
||||
myMessage = '\nExpected: %s\nGot: %s' % (str(myExpectedAttrs), str(myAttrs))
|
||||
assert myAttrs == myExpectedAttrs, myMessage
|
||||
|
@ -14,7 +14,7 @@ __revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
|
||||
from PyQt4.QtCore import QVariant
|
||||
import qgis
|
||||
|
||||
from qgis.core import (QgsGeometry,
|
||||
QgsVectorLayer,
|
||||
@ -264,7 +264,7 @@ class TestQgsGeometry(TestCase):
|
||||
QgsPoint(40,10),
|
||||
]
|
||||
))
|
||||
myFeature1.setAttributes([QVariant('Johny')])
|
||||
myFeature1.setAttributes(['Johny'])
|
||||
|
||||
myFeature2 = QgsFeature()
|
||||
myFeature2.setGeometry(QgsGeometry.fromPolyline([
|
||||
@ -274,7 +274,7 @@ class TestQgsGeometry(TestCase):
|
||||
QgsPoint(40,40),
|
||||
]
|
||||
))
|
||||
myFeature2.setAttributes([QVariant('Be')])
|
||||
myFeature2.setAttributes(['Be'])
|
||||
|
||||
myFeature3 = QgsFeature()
|
||||
myFeature3.setGeometry(QgsGeometry.fromPolyline([
|
||||
@ -285,7 +285,7 @@ class TestQgsGeometry(TestCase):
|
||||
]
|
||||
))
|
||||
|
||||
myFeature3.setAttributes([QVariant('Good')])
|
||||
myFeature3.setAttributes(['Good'])
|
||||
|
||||
myResult, myFeatures = myProvider.addFeatures(
|
||||
[myFeature1, myFeature2, myFeature3])
|
||||
|
@ -14,6 +14,7 @@ __revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
import random
|
||||
import qgis
|
||||
|
||||
from qgis.core import *
|
||||
from qgis.gui import *
|
||||
|
@ -14,6 +14,7 @@ __revision__ = '$Format:%H$'
|
||||
|
||||
import tempfile
|
||||
import os
|
||||
import qgis
|
||||
from qgis.core import QgsLogger
|
||||
from utilities import (TestCase,
|
||||
unittest
|
||||
|
@ -13,6 +13,7 @@ __copyright__ = 'Copyright 2012, The QGIS Project'
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
import qgis
|
||||
from PyQt4.QtCore import *
|
||||
from PyQt4.QtGui import *
|
||||
|
||||
|
@ -13,6 +13,7 @@ __copyright__ = 'Copyright 2012, The QGIS Project'
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
import qgis
|
||||
|
||||
from qgis.core import QgsPoint
|
||||
|
||||
|
@ -14,6 +14,7 @@ __revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
import glob
|
||||
import qgis
|
||||
|
||||
from PyQt4.QtCore import (QTemporaryFile,
|
||||
QDir)
|
||||
|
@ -14,8 +14,9 @@ __revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
import unittest
|
||||
import qgis
|
||||
|
||||
from PyQt4.QtCore import QFileInfo, QString, QStringList
|
||||
from PyQt4.QtCore import QFileInfo
|
||||
from PyQt4 import QtGui
|
||||
|
||||
from qgis.core import (QgsRaster,
|
||||
@ -60,7 +61,7 @@ class TestQgsRasterLayer(TestCase):
|
||||
|
||||
# Get the name of the first band
|
||||
myBand = myRasterValues.keys()[0]
|
||||
#myExpectedName = QString('Band 1')
|
||||
#myExpectedName = 'Band 1
|
||||
myExpectedBand = 1
|
||||
myMessage = 'Expected "%s" got "%s" for first raster band name' % (
|
||||
myExpectedBand, myBand)
|
||||
@ -71,8 +72,7 @@ class TestQgsRasterLayer(TestCase):
|
||||
myValues = myRasterValues.values()
|
||||
myIntValues = []
|
||||
for myValue in myValues:
|
||||
#myIntValues.append(int(str(myValue)))
|
||||
myIntValues.append( myValue.toInt()[0] )
|
||||
myIntValues.append( int(myValue) )
|
||||
myValues = str(myIntValues)
|
||||
myExpectedValues = '[127, 141, 112, 72, 86, 126, 156, 211, 170]'
|
||||
myMessage = 'Expected: %s\nGot: %s' % (myValues, myExpectedValues)
|
||||
@ -140,7 +140,7 @@ class TestQgsRasterLayer(TestCase):
|
||||
|
||||
myMapRenderer = QgsMapRenderer()
|
||||
|
||||
myLayers = QStringList()
|
||||
myLayers = []
|
||||
myLayers.append(myRasterLayer.id())
|
||||
myMapRenderer.setLayerSet(myLayers)
|
||||
myMapRenderer.setExtent(myRasterLayer.extent())
|
||||
|
@ -12,6 +12,7 @@ __copyright__ = 'Copyright 2012, The QGIS Project'
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import qgis
|
||||
from qgis.core import (QgsRectangle,
|
||||
QgsPoint)
|
||||
|
||||
|
@ -13,6 +13,7 @@ __copyright__ = 'Copyright 2012, The QGIS Project'
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import unittest
|
||||
import qgis
|
||||
|
||||
from qgis.core import (QgsSpatialIndex,
|
||||
QgsFeature,
|
||||
|
@ -14,6 +14,7 @@ __revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
import qgis
|
||||
|
||||
from qgis.core import *
|
||||
|
||||
|
@ -13,8 +13,9 @@ __copyright__ = 'Copyright 2012, The QGIS Project'
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
import qgis
|
||||
|
||||
from PyQt4.QtCore import QVariant, QDir, QString, QStringList
|
||||
from PyQt4.QtCore import QDir
|
||||
|
||||
from qgis.core import (QgsVectorLayer,
|
||||
QgsFeature,
|
||||
@ -51,9 +52,7 @@ class TestQgsVectorLayer(TestCase):
|
||||
|
||||
ft = QgsFeature()
|
||||
ft.setGeometry(QgsGeometry.fromPoint(QgsPoint(10,10)))
|
||||
ft.setAttributes([ QVariant('Johny'),
|
||||
QVariant(20),
|
||||
QVariant(0.3)])
|
||||
ft.setAttributes([ 'Johny', 20, 0.3 ])
|
||||
myResult, myFeatures = myProvider.addFeatures([ft])
|
||||
assert myResult == True
|
||||
assert len(myFeatures) > 0
|
||||
|
@ -12,8 +12,9 @@ __copyright__ = 'Copyright 2013, The QGIS Project'
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
import qgis
|
||||
|
||||
import os
|
||||
from PyQt4.QtCore import *
|
||||
from qgis.core import *
|
||||
from qgis.analysis import *
|
||||
@ -33,6 +34,7 @@ class TestQgsZonalStatistics(TestCase):
|
||||
myTempPath = QDir.tempPath() + sep
|
||||
testDir = QDir(TEST_DATA_DIR)
|
||||
for f in testDir.entryList(QDir.Files):
|
||||
QFile.remove(myTempPath + f)
|
||||
QFile.copy(TEST_DATA_DIR + f, myTempPath + f)
|
||||
|
||||
myVector = QgsVectorLayer(myTempPath + "polys.shp", "poly", "ogr")
|
||||
@ -44,30 +46,30 @@ class TestQgsZonalStatistics(TestCase):
|
||||
# validate statistics for each feature
|
||||
request = QgsFeatureRequest().setFilterFid(0)
|
||||
feat = myVector.getFeatures(request).next()
|
||||
myMessage = ('Expected: %f\nGot: %f\n' % (12.0, feat[1].toDouble()[0]))
|
||||
myMessage = ('Expected: %f\nGot: %f\n' % (12.0, feat[1]))
|
||||
assert feat[1] == 12.0, myMessage
|
||||
myMessage = ('Expected: %f\nGot: %f\n' % (8.0, feat[2].toDouble()[0]))
|
||||
myMessage = ('Expected: %f\nGot: %f\n' % (8.0, feat[2]))
|
||||
assert feat[2] == 8.0, myMessage
|
||||
myMessage = ('Expected: %f\nGot: %f\n' % (0.666666666666667, feat[3].toDouble()[0]))
|
||||
assert feat[3] == 0.666666666666667, myMessage
|
||||
myMessage = ('Expected: %f\nGot: %f\n' % (0.666666666666667, feat[3]))
|
||||
assert abs(feat[3] - 0.666666666666667 ) < 0.00001, myMessage
|
||||
|
||||
request.setFilterFid(1)
|
||||
feat = myVector.getFeatures(request).next()
|
||||
myMessage = ('Expected: %f\nGot: %f\n' % (9.0, feat[1].toDouble()[0]))
|
||||
myMessage = ('Expected: %f\nGot: %f\n' % (9.0, feat[1]))
|
||||
assert feat[1] == 9.0, myMessage
|
||||
myMessage = ('Expected: %f\nGot: %f\n' % (5.0, feat[2].toDouble()[0]))
|
||||
myMessage = ('Expected: %f\nGot: %f\n' % (5.0, feat[2]))
|
||||
assert feat[2] == 5.0, myMessage
|
||||
myMessage = ('Expected: %f\nGot: %f\n' % (0.555555555555556, feat[3].toDouble()[0]))
|
||||
assert feat[3] == 0.555555555555556, myMessage
|
||||
myMessage = ('Expected: %f\nGot: %f\n' % (0.555555555555556, feat[3]))
|
||||
assert abs( feat[3] - 0.555555555555556) < 0.00001, myMessage
|
||||
|
||||
request.setFilterFid(2)
|
||||
feat = myVector.getFeatures(request).next()
|
||||
myMessage = ('Expected: %f\nGot: %f\n' % (6.0, feat[1].toDouble()[0]))
|
||||
myMessage = ('Expected: %f\nGot: %f\n' % (6.0, feat[1]))
|
||||
assert feat[1] == 6.0, myMessage
|
||||
myMessage = ('Expected: %f\nGot: %f\n' % (5.0, feat[2].toDouble()[0]))
|
||||
myMessage = ('Expected: %f\nGot: %f\n' % (5.0, feat[2]))
|
||||
assert feat[2] == 5.0, myMessage
|
||||
myMessage = ('Expected: %f\nGot: %f\n' % (0.833333333333333, feat[3].toDouble()[0]))
|
||||
assert feat[3] == 0.833333333333333, myMessage
|
||||
myMessage = ('Expected: %f\nGot: %f\n' % (0.833333333333333, feat[3]))
|
||||
assert abs( feat[3] - 0.833333333333333 ) < 0.00001, myMessage
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -13,6 +13,7 @@ __revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
import sys
|
||||
import qgis
|
||||
from PyQt4 import QtGui, QtCore
|
||||
from qgis.core import (QgsApplication,
|
||||
QgsCoordinateReferenceSystem,
|
||||
@ -166,9 +167,9 @@ def writeShape(theMemoryLayer, theFileName):
|
||||
myFileName = os.path.join(str(QtCore.QDir.tempPath()), theFileName)
|
||||
print myFileName
|
||||
# Explicitly giving all options, not really needed but nice for clarity
|
||||
myErrorMessage = QtCore.QString()
|
||||
myOptions = QtCore.QStringList()
|
||||
myLayerOptions = QtCore.QStringList()
|
||||
myErrorMessage = ''
|
||||
myOptions = []
|
||||
myLayerOptions = []
|
||||
mySelectedOnlyFlag = False
|
||||
mySkipAttributesFlag = False
|
||||
myGeoCrs = QgsCoordinateReferenceSystem()
|
||||
|
Loading…
x
Reference in New Issue
Block a user