mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -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
|
heigth:height
|
||||||
heigh:height
|
heigh:height
|
||||||
delimted:delimited
|
delimted:delimited
|
||||||
|
teh:the
|
||||||
|
@ -75,7 +75,7 @@ bool QgsRenderChecker::isKnownAnomaly( QString theDiffImageFile )
|
|||||||
QString myFilename = "*";
|
QString myFilename = "*";
|
||||||
myList = myDirectory.entryList( QStringList( myFilename ),
|
myList = myDirectory.entryList( QStringList( myFilename ),
|
||||||
QDir::Files | QDir::NoSymLinks );
|
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
|
//all files except the control file
|
||||||
myList.removeAt( myList.indexOf( mExpectedImageFile ) );
|
myList.removeAt( myList.indexOf( mExpectedImageFile ) );
|
||||||
|
|
||||||
@ -241,11 +241,11 @@ bool QgsRenderChecker::compareImages( QString theTestName,
|
|||||||
//
|
//
|
||||||
QString myDashMessage = "<DartMeasurementFile name=\"Rendered Image " + theTestName + "\""
|
QString myDashMessage = "<DartMeasurementFile name=\"Rendered Image " + theTestName + "\""
|
||||||
" type=\"image/png\">" + mRenderedImageFile +
|
" type=\"image/png\">" + mRenderedImageFile +
|
||||||
"</DartMeasurementFile>"
|
"</DartMeasurementFile>\n"
|
||||||
"<DartMeasurementFile name=\"Expected Image " + theTestName + "\" type=\"image/png\">" +
|
"<DartMeasurementFile name=\"Expected Image " + theTestName + "\" type=\"image/png\">" +
|
||||||
mExpectedImageFile + "</DartMeasurementFile>"
|
mExpectedImageFile + "</DartMeasurementFile>\n"
|
||||||
"<DartMeasurementFile name=\"Difference Image " + theTestName + "\" type=\"image/png\">" +
|
"<DartMeasurementFile name=\"Difference Image " + theTestName + "\" type=\"image/png\">" +
|
||||||
myDiffImageFile + "</DartMeasurementFile>";
|
myDiffImageFile + "</DartMeasurementFile>\n";
|
||||||
qDebug( ) << myDashMessage;
|
qDebug( ) << myDashMessage;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -16,9 +16,15 @@
|
|||||||
#ifndef QGSRENDERCHECKER_H
|
#ifndef QGSRENDERCHECKER_H
|
||||||
#define QGSRENDERCHECKER_H
|
#define QGSRENDERCHECKER_H
|
||||||
|
|
||||||
|
#include <qgis.h>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QRegExp>
|
||||||
|
#include <QList>
|
||||||
|
|
||||||
#include <qgsmaprenderer.h>
|
#include <qgsmaprenderer.h>
|
||||||
|
#include <qgslogger.h>
|
||||||
|
|
||||||
class QImage;
|
class QImage;
|
||||||
|
|
||||||
/** \ingroup UnitTests
|
/** \ingroup UnitTests
|
||||||
@ -86,7 +92,7 @@ class CORE_EXPORT QgsRenderChecker
|
|||||||
* @note: make sure to call setExpectedImage and setRenderedImage first.
|
* @note: make sure to call setExpectedImage and setRenderedImage first.
|
||||||
*/
|
*/
|
||||||
bool compareImages( QString theTestName, unsigned int theMismatchCount = 0, QString theRenderedImageFile = "" );
|
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
|
* file where there is some red pixel content (indicating a render check
|
||||||
* mismatch), but where the output was still acceptible. If the render
|
* mismatch), but where the output was still acceptible. If the render
|
||||||
* diff matches one of these anomalies we will still consider it to be
|
* diff matches one of these anomalies we will still consider it to be
|
||||||
@ -110,4 +116,50 @@ class CORE_EXPORT QgsRenderChecker
|
|||||||
|
|
||||||
}; // class 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
|
#endif
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
@ -35,6 +34,11 @@
|
|||||||
#include <qgsfield.h>
|
#include <qgsfield.h>
|
||||||
#include <qgis.h> //defines GEOWkt
|
#include <qgis.h> //defines GEOWkt
|
||||||
#include <qgsproviderregistry.h>
|
#include <qgsproviderregistry.h>
|
||||||
|
#include <qgslogger.h>
|
||||||
|
|
||||||
|
#if defined(linux)
|
||||||
|
#include <langinfo.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/** \ingroup UnitTests
|
/** \ingroup UnitTests
|
||||||
@ -90,6 +94,16 @@ void Regression1141::cleanupTestCase()
|
|||||||
|
|
||||||
void Regression1141::diacriticalTest()
|
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...
|
//create some objects that will be used in all tests...
|
||||||
mEncoding = "UTF-8";
|
mEncoding = "UTF-8";
|
||||||
QgsField myField( "ąęćń", QVariant::Int, "int", 10, 0, "Value on lon" );
|
QgsField myField( "ąęćń", QVariant::Int, "int", 10, 0, "Value on lon" );
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include <qgsexpression.h>
|
#include <qgsexpression.h>
|
||||||
#include <qgsfeature.h>
|
#include <qgsfeature.h>
|
||||||
#include <qgsgeometry.h>
|
#include <qgsgeometry.h>
|
||||||
|
#include <qgsrenderchecker.h>
|
||||||
|
|
||||||
#if QT_VERSION < 0x40701
|
#if QT_VERSION < 0x40701
|
||||||
// See http://hub.qgis.org/issues/4284
|
// See http://hub.qgis.org/issues/4284
|
||||||
@ -809,7 +810,7 @@ class TestQgsExpression: public QObject
|
|||||||
|
|
||||||
QCOMPARE( out.canConvert<QgsGeometry>(), true );
|
QCOMPARE( out.canConvert<QgsGeometry>(), true );
|
||||||
QgsGeometry outGeom = out.value<QgsGeometry>();
|
QgsGeometry outGeom = out.value<QgsGeometry>();
|
||||||
QCOMPARE( outGeom.exportToWkt(), result->exportToWkt() );
|
QVERIFY( compareWkt( outGeom.exportToWkt(), result->exportToWkt() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void eval_special_columns()
|
void eval_special_columns()
|
||||||
|
@ -370,7 +370,6 @@ void TestQgsGeometry::dumpPolyline( QgsPolyline &thePolyline )
|
|||||||
mpPainter->drawPolyline( myPoints );
|
mpPainter->drawPolyline( myPoints );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QTEST_MAIN( TestQgsGeometry )
|
QTEST_MAIN( TestQgsGeometry )
|
||||||
#include "moc_testqgsgeometry.cxx"
|
#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, '
|
'Copyright (c) 2011 German Carrillo, '
|
||||||
'geotux_tuxman@linuxmail.org')
|
'geotux_tuxman@linuxmail.org')
|
||||||
|
|
||||||
|
import qgis
|
||||||
|
|
||||||
from PyQt4.QtCore import QObject
|
from PyQt4.QtCore import QObject
|
||||||
from qgis.core import QgsMapLayerRegistry
|
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.QtCore import *
|
||||||
from PyQt4.QtGui import *
|
from PyQt4.QtGui import *
|
||||||
from qgis.core import *
|
from qgis.core import *
|
||||||
@ -92,7 +94,7 @@ class QgsCompositionChecker:
|
|||||||
mismatchCount = mismatchCount + 1
|
mismatchCount = mismatchCount + 1
|
||||||
differenceImage.setPixel( j, i, qRgb( 255, 0, 0 ) )
|
differenceImage.setPixel( j, i, qRgb( 255, 0, 0 ) )
|
||||||
|
|
||||||
if not differenceImagePath.isEmpty():
|
if differenceImagePath != "":
|
||||||
differenceImage.save( differenceImagePath, "PNG" )
|
differenceImage.save( differenceImagePath, "PNG" )
|
||||||
|
|
||||||
#allow pixel deviation of 1 percent
|
#allow pixel deviation of 1 percent
|
||||||
|
@ -17,8 +17,10 @@ test_analysis.py
|
|||||||
import unittest
|
import unittest
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import qgis
|
||||||
|
|
||||||
from utilities import unitTestDataPath, getQgisTestApp
|
from utilities import unitTestDataPath, getQgisTestApp
|
||||||
from PyQt4.QtCore import QFileInfo, QDir, QStringList
|
from PyQt4.QtCore import QFileInfo, QDir
|
||||||
from PyQt4.QtXml import QDomDocument
|
from PyQt4.QtXml import QDomDocument
|
||||||
|
|
||||||
# support python < 2.7 via unittest2
|
# 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
|
# This will get replaced with a git SHA1 when you do a git archive
|
||||||
__revision__ = '$Format:%H$'
|
__revision__ = '$Format:%H$'
|
||||||
|
|
||||||
|
import qgis
|
||||||
from utilities import getQgisTestApp, unittest
|
from utilities import getQgisTestApp, unittest
|
||||||
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
|
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ test_qgsatlascomposition.py
|
|||||||
* *
|
* *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
'''
|
'''
|
||||||
|
import qgis
|
||||||
import unittest
|
import unittest
|
||||||
from utilities import *
|
from utilities import *
|
||||||
from PyQt4.QtCore import *
|
from PyQt4.QtCore import *
|
||||||
@ -28,14 +29,14 @@ class TestQgsAtlasComposition(unittest.TestCase):
|
|||||||
|
|
||||||
def testCase(self):
|
def testCase(self):
|
||||||
self.TEST_DATA_DIR = unitTestDataPath()
|
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" )
|
mVectorLayer = QgsVectorLayer( vectorFileInfo.filePath(), vectorFileInfo.completeBaseName(), "ogr" )
|
||||||
|
|
||||||
QgsMapLayerRegistry.instance().addMapLayers( [mVectorLayer] )
|
QgsMapLayerRegistry.instance().addMapLayers( [mVectorLayer] )
|
||||||
|
|
||||||
# create composition with composer map
|
# create composition with composer map
|
||||||
mMapRenderer = QgsMapRenderer()
|
mMapRenderer = QgsMapRenderer()
|
||||||
layerStringList = QStringList()
|
layerStringList = []
|
||||||
layerStringList.append( mVectorLayer.id() )
|
layerStringList.append( mVectorLayer.id() )
|
||||||
mMapRenderer.setLayerSet( layerStringList )
|
mMapRenderer.setLayerSet( layerStringList )
|
||||||
mMapRenderer.setProjectionsEnabled( True )
|
mMapRenderer.setProjectionsEnabled( True )
|
||||||
@ -102,7 +103,7 @@ class TestQgsAtlasComposition(unittest.TestCase):
|
|||||||
self.mAtlas.beginRender()
|
self.mAtlas.beginRender()
|
||||||
for i in range(0, self.mAtlas.numFeatures()):
|
for i in range(0, self.mAtlas.numFeatures()):
|
||||||
self.mAtlas.prepareForFeature( i )
|
self.mAtlas.prepareForFeature( i )
|
||||||
expected = QString( "output_%1" ).arg(i+1)
|
expected = "output_%d" % (i+1)
|
||||||
assert self.mAtlas.currentFilename() == expected
|
assert self.mAtlas.currentFilename() == expected
|
||||||
self.mAtlas.endRender()
|
self.mAtlas.endRender()
|
||||||
|
|
||||||
@ -118,10 +119,10 @@ class TestQgsAtlasComposition(unittest.TestCase):
|
|||||||
|
|
||||||
checker = QgsCompositionChecker()
|
checker = QgsCompositionChecker()
|
||||||
res = checker.testComposition( "Atlas autoscale test", self.mComposition, \
|
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() + \
|
"control_images" + QDir.separator() + \
|
||||||
"expected_composermapatlas" + QDir.separator() + \
|
"expected_composermapatlas" + QDir.separator() + \
|
||||||
QString( "autoscale_%1.png" ).arg( i ) )
|
"autoscale_%d.png" % i )
|
||||||
assert res[0] == True
|
assert res[0] == True
|
||||||
self.mAtlas.endRender()
|
self.mAtlas.endRender()
|
||||||
|
|
||||||
@ -137,10 +138,10 @@ class TestQgsAtlasComposition(unittest.TestCase):
|
|||||||
|
|
||||||
checker = QgsCompositionChecker()
|
checker = QgsCompositionChecker()
|
||||||
res = checker.testComposition( "Atlas fixed scale test", self.mComposition, \
|
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() + \
|
"control_images" + QDir.separator() + \
|
||||||
"expected_composermapatlas" + QDir.separator() + \
|
"expected_composermapatlas" + QDir.separator() + \
|
||||||
QString( "fixedscale_%1.png" ).arg( i ) )
|
"fixedscale_%d.png" % i )
|
||||||
assert res[0] == True
|
assert res[0] == True
|
||||||
self.mAtlas.endRender()
|
self.mAtlas.endRender()
|
||||||
|
|
||||||
@ -157,10 +158,10 @@ class TestQgsAtlasComposition(unittest.TestCase):
|
|||||||
|
|
||||||
checker = QgsCompositionChecker()
|
checker = QgsCompositionChecker()
|
||||||
res = checker.testComposition( "Atlas hidden test", self.mComposition, \
|
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() + \
|
"control_images" + QDir.separator() + \
|
||||||
"expected_composermapatlas" + QDir.separator() + \
|
"expected_composermapatlas" + QDir.separator() + \
|
||||||
QString( "hiding_%1.png" ).arg( i ) )
|
"hiding_%d.png" % i )
|
||||||
assert res[0] == True
|
assert res[0] == True
|
||||||
self.mAtlas.endRender()
|
self.mAtlas.endRender()
|
||||||
|
|
||||||
@ -181,10 +182,10 @@ class TestQgsAtlasComposition(unittest.TestCase):
|
|||||||
|
|
||||||
checker = QgsCompositionChecker()
|
checker = QgsCompositionChecker()
|
||||||
res = checker.testComposition( "Atlas sorting test", self.mComposition, \
|
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() + \
|
"control_images" + QDir.separator() + \
|
||||||
"expected_composermapatlas" + QDir.separator() + \
|
"expected_composermapatlas" + QDir.separator() + \
|
||||||
QString( "sorting_%1.png" ).arg( i ) )
|
"sorting_%d.png" % i )
|
||||||
assert res[0] == True
|
assert res[0] == True
|
||||||
self.mAtlas.endRender()
|
self.mAtlas.endRender()
|
||||||
|
|
||||||
@ -206,10 +207,10 @@ class TestQgsAtlasComposition(unittest.TestCase):
|
|||||||
|
|
||||||
checker = QgsCompositionChecker()
|
checker = QgsCompositionChecker()
|
||||||
res = checker.testComposition( "Atlas filtering test", self.mComposition, \
|
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() + \
|
"control_images" + QDir.separator() + \
|
||||||
"expected_composermapatlas" + QDir.separator() + \
|
"expected_composermapatlas" + QDir.separator() + \
|
||||||
QString( "filtering_%1.png" ).arg( i ) )
|
"filtering_%d.png" % i )
|
||||||
assert res[0] == True
|
assert res[0] == True
|
||||||
self.mAtlas.endRender()
|
self.mAtlas.endRender()
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ __copyright__ = '(C) 2013, Nyall Dawson, Massimo Endrighi'
|
|||||||
__revision__ = '$Format:%H$'
|
__revision__ = '$Format:%H$'
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import qgis
|
||||||
|
|
||||||
from PyQt4.QtCore import *
|
from PyQt4.QtCore import *
|
||||||
from PyQt4.QtGui import *
|
from PyQt4.QtGui import *
|
||||||
@ -95,7 +96,7 @@ class TestQgsBlendModes(TestCase):
|
|||||||
"""Test that blend modes work for vector layers."""
|
"""Test that blend modes work for vector layers."""
|
||||||
|
|
||||||
#Add vector layers to map
|
#Add vector layers to map
|
||||||
myLayers = QStringList()
|
myLayers = []
|
||||||
myLayers.append(self.mLineLayer.id())
|
myLayers.append(self.mLineLayer.id())
|
||||||
myLayers.append(self.mPolygonLayer.id())
|
myLayers.append(self.mPolygonLayer.id())
|
||||||
self.mMapRenderer.setLayerSet(myLayers)
|
self.mMapRenderer.setLayerSet(myLayers)
|
||||||
@ -121,7 +122,7 @@ class TestQgsBlendModes(TestCase):
|
|||||||
"""Test that feature blend modes work for vector layers."""
|
"""Test that feature blend modes work for vector layers."""
|
||||||
|
|
||||||
#Add vector layers to map
|
#Add vector layers to map
|
||||||
myLayers = QStringList()
|
myLayers = []
|
||||||
myLayers.append(self.mLineLayer.id())
|
myLayers.append(self.mLineLayer.id())
|
||||||
myLayers.append(self.mPolygonLayer.id())
|
myLayers.append(self.mPolygonLayer.id())
|
||||||
self.mMapRenderer.setLayerSet(myLayers)
|
self.mMapRenderer.setLayerSet(myLayers)
|
||||||
@ -145,7 +146,7 @@ class TestQgsBlendModes(TestCase):
|
|||||||
"""Test that layer transparency works for vector layers."""
|
"""Test that layer transparency works for vector layers."""
|
||||||
|
|
||||||
#Add vector layers to map
|
#Add vector layers to map
|
||||||
myLayers = QStringList()
|
myLayers = []
|
||||||
myLayers.append(self.mLineLayer.id())
|
myLayers.append(self.mLineLayer.id())
|
||||||
myLayers.append(self.mPolygonLayer.id())
|
myLayers.append(self.mPolygonLayer.id())
|
||||||
self.mMapRenderer.setLayerSet(myLayers)
|
self.mMapRenderer.setLayerSet(myLayers)
|
||||||
@ -165,7 +166,7 @@ class TestQgsBlendModes(TestCase):
|
|||||||
def testRasterBlending(self):
|
def testRasterBlending(self):
|
||||||
"""Test that blend modes work for raster layers."""
|
"""Test that blend modes work for raster layers."""
|
||||||
#Add raster layers to map
|
#Add raster layers to map
|
||||||
myLayers = QStringList()
|
myLayers = []
|
||||||
myLayers.append(self.mRasterLayer1.id())
|
myLayers.append(self.mRasterLayer1.id())
|
||||||
myLayers.append(self.mRasterLayer2.id())
|
myLayers.append(self.mRasterLayer2.id())
|
||||||
self.mMapRenderer.setLayerSet(myLayers)
|
self.mMapRenderer.setLayerSet(myLayers)
|
||||||
|
@ -13,8 +13,8 @@ __copyright__ = 'Copyright 2012, The QGIS Project'
|
|||||||
__revision__ = '$Format:%H$'
|
__revision__ = '$Format:%H$'
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from PyQt4.QtCore import (QStringList,
|
import qgis
|
||||||
QFileInfo)
|
from PyQt4.QtCore import QFileInfo
|
||||||
from PyQt4.QtXml import QDomDocument
|
from PyQt4.QtXml import QDomDocument
|
||||||
from PyQt4.QtGui import (QPainter, QColor)
|
from PyQt4.QtGui import (QPainter, QColor)
|
||||||
|
|
||||||
|
@ -14,7 +14,8 @@ __revision__ = '$Format:%H$'
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import os
|
import os
|
||||||
from PyQt4.QtCore import QUrl, QString, qDebug
|
import qgis
|
||||||
|
from PyQt4.QtCore import QUrl, qDebug
|
||||||
from PyQt4.QtXml import QDomDocument
|
from PyQt4.QtXml import QDomDocument
|
||||||
from qgis.core import (QgsComposition,
|
from qgis.core import (QgsComposition,
|
||||||
QgsComposerHtml,
|
QgsComposerHtml,
|
||||||
@ -54,7 +55,7 @@ class TestQgsComposerHtml(TestCase):
|
|||||||
def htmlUrl(self):
|
def htmlUrl(self):
|
||||||
"""Helper to get the url of the html doc."""
|
"""Helper to get the url of the html doc."""
|
||||||
myPath = os.path.join(TEST_DATA_DIR, "html_table.html")
|
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
|
return myUrl
|
||||||
|
|
||||||
@expectedFailure
|
@expectedFailure
|
||||||
|
@ -15,6 +15,7 @@ test_qgscomposerlabel.py
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
'''
|
'''
|
||||||
import unittest
|
import unittest
|
||||||
|
import qgis
|
||||||
from utilities import *
|
from utilities import *
|
||||||
from PyQt4.QtCore import *
|
from PyQt4.QtCore import *
|
||||||
from PyQt4.QtGui import *
|
from PyQt4.QtGui import *
|
||||||
@ -27,14 +28,14 @@ class TestQgsComposerLabel(unittest.TestCase):
|
|||||||
|
|
||||||
def testCase(self):
|
def testCase(self):
|
||||||
TEST_DATA_DIR = unitTestDataPath()
|
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" )
|
mVectorLayer = QgsVectorLayer( vectorFileInfo.filePath(), vectorFileInfo.completeBaseName(), "ogr" )
|
||||||
|
|
||||||
QgsMapLayerRegistry.instance().addMapLayers( [mVectorLayer] )
|
QgsMapLayerRegistry.instance().addMapLayers( [mVectorLayer] )
|
||||||
|
|
||||||
# create composition with composer map
|
# create composition with composer map
|
||||||
mMapRenderer = QgsMapRenderer()
|
mMapRenderer = QgsMapRenderer()
|
||||||
layerStringList = QStringList()
|
layerStringList = []
|
||||||
layerStringList.append( mVectorLayer.id() )
|
layerStringList.append( mVectorLayer.id() )
|
||||||
mMapRenderer.setLayerSet( layerStringList )
|
mMapRenderer.setLayerSet( layerStringList )
|
||||||
mMapRenderer.setProjectionsEnabled( False )
|
mMapRenderer.setProjectionsEnabled( False )
|
||||||
@ -62,7 +63,7 @@ class TestQgsComposerLabel(unittest.TestCase):
|
|||||||
# $CURRENT_DATE() evaluation (inside an expression)
|
# $CURRENT_DATE() evaluation (inside an expression)
|
||||||
mLabel.setText( "__[%$CURRENT_DATE(dd) + 1%](ok)__" )
|
mLabel.setText( "__[%$CURRENT_DATE(dd) + 1%](ok)__" )
|
||||||
dd = QDate.currentDate().day()
|
dd = QDate.currentDate().day()
|
||||||
expected = "__" + QString( "%1" ).arg(dd+1) + "(ok)__"
|
expected = "__%d(ok)__" % (dd+1)
|
||||||
assert mLabel.displayText() == expected
|
assert mLabel.displayText() == expected
|
||||||
|
|
||||||
# expression evaluation (without associated feature)
|
# expression evaluation (without associated feature)
|
||||||
@ -101,9 +102,9 @@ class TestQgsComposerLabel(unittest.TestCase):
|
|||||||
|
|
||||||
# use setSpecialColumn
|
# use setSpecialColumn
|
||||||
mLabel.setText( "[%$var1 + 1%]" )
|
mLabel.setText( "[%$var1 + 1%]" )
|
||||||
QgsExpression.setSpecialColumn( "$var1", QVariant(41) )
|
QgsExpression.setSpecialColumn( "$var1", 41 )
|
||||||
assert mLabel.displayText() == "42"
|
assert mLabel.displayText() == "42"
|
||||||
QgsExpression.setSpecialColumn( "$var1", QVariant(99) )
|
QgsExpression.setSpecialColumn( "$var1", 99 )
|
||||||
assert mLabel.displayText() == "100"
|
assert mLabel.displayText() == "100"
|
||||||
QgsExpression.unsetSpecialColumn( "$var1" )
|
QgsExpression.unsetSpecialColumn( "$var1" )
|
||||||
assert mLabel.displayText() == "[%$var1 + 1%]"
|
assert mLabel.displayText() == "[%$var1 + 1%]"
|
||||||
|
@ -13,8 +13,8 @@ __copyright__ = 'Copyright 2012, The QGIS Project'
|
|||||||
__revision__ = '$Format:%H$'
|
__revision__ = '$Format:%H$'
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from PyQt4.QtCore import (QStringList,
|
import qgis
|
||||||
QFileInfo)
|
from PyQt4.QtCore import QFileInfo
|
||||||
from PyQt4.QtXml import QDomDocument
|
from PyQt4.QtXml import QDomDocument
|
||||||
from PyQt4.QtGui import (QPainter,
|
from PyQt4.QtGui import (QPainter,
|
||||||
QColor)
|
QColor)
|
||||||
@ -57,7 +57,7 @@ class TestQgsComposerMap(TestCase):
|
|||||||
|
|
||||||
# create composition with composer map
|
# create composition with composer map
|
||||||
self.mMapRenderer = QgsMapRenderer()
|
self.mMapRenderer = QgsMapRenderer()
|
||||||
layerStringList = QStringList()
|
layerStringList = []
|
||||||
layerStringList.append(mRasterLayer.id())
|
layerStringList.append(mRasterLayer.id())
|
||||||
self.mMapRenderer.setLayerSet(layerStringList)
|
self.mMapRenderer.setLayerSet(layerStringList)
|
||||||
self.mMapRenderer.setProjectionsEnabled(False)
|
self.mMapRenderer.setProjectionsEnabled(False)
|
||||||
|
@ -13,8 +13,9 @@ __copyright__ = 'Copyright 2012, The QGIS Project'
|
|||||||
__revision__ = '$Format:%H$'
|
__revision__ = '$Format:%H$'
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import qgis
|
||||||
|
|
||||||
from PyQt4.QtCore import QFileInfo, QDir, QStringList
|
from PyQt4.QtCore import QFileInfo, QDir
|
||||||
from PyQt4.QtXml import QDomDocument
|
from PyQt4.QtXml import QDomDocument
|
||||||
|
|
||||||
from qgis.core import (QgsComposition,
|
from qgis.core import (QgsComposition,
|
||||||
@ -104,7 +105,7 @@ class TestQgsComposition(TestCase):
|
|||||||
QgsMapLayerRegistry.instance().addMapLayers([myRasterLayer])
|
QgsMapLayerRegistry.instance().addMapLayers([myRasterLayer])
|
||||||
|
|
||||||
myMapRenderer = QgsMapRenderer()
|
myMapRenderer = QgsMapRenderer()
|
||||||
myLayerStringList = QStringList()
|
myLayerStringList = []
|
||||||
myLayerStringList.append(myRasterLayer.id())
|
myLayerStringList.append(myRasterLayer.id())
|
||||||
myMapRenderer.setLayerSet(myLayerStringList)
|
myMapRenderer.setLayerSet(myLayerStringList)
|
||||||
myMapRenderer.setProjectionsEnabled(False)
|
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
|
# This will get replaced with a git SHA1 when you do a git archive
|
||||||
__revision__ = '$Format:%H$'
|
__revision__ = '$Format:%H$'
|
||||||
|
|
||||||
|
import qgis
|
||||||
from qgis.core import (QgsRectangle,
|
from qgis.core import (QgsRectangle,
|
||||||
QgsCoordinateReferenceSystem,
|
QgsCoordinateReferenceSystem,
|
||||||
QgsCoordinateTransform,
|
QgsCoordinateTransform,
|
||||||
|
@ -23,8 +23,8 @@ __revision__ = '$Format:%H$'
|
|||||||
#
|
#
|
||||||
# To recreate all tests, set rebuildTests to true
|
# To recreate all tests, set rebuildTests to true
|
||||||
|
|
||||||
import os;
|
import os
|
||||||
import os.path;
|
import os.path
|
||||||
import re
|
import re
|
||||||
import tempfile
|
import tempfile
|
||||||
import inspect
|
import inspect
|
||||||
@ -33,13 +33,7 @@ import test_qgsdelimitedtextprovider_wanted as want
|
|||||||
|
|
||||||
rebuildTests = 'REBUILD_DELIMITED_TEXT_TESTS' in os.environ;
|
rebuildTests = 'REBUILD_DELIMITED_TEXT_TESTS' in os.environ;
|
||||||
|
|
||||||
|
import qgis
|
||||||
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)
|
|
||||||
|
|
||||||
from PyQt4.QtCore import (QVariant,
|
from PyQt4.QtCore import (QVariant,
|
||||||
QCoreApplication,
|
QCoreApplication,
|
||||||
@ -69,6 +63,7 @@ from utilities import (getQgisTestApp,
|
|||||||
|
|
||||||
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
|
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
|
||||||
|
|
||||||
|
import sip
|
||||||
sipversion=str(sip.getapi('QVariant'))
|
sipversion=str(sip.getapi('QVariant'))
|
||||||
sipwanted='2'
|
sipwanted='2'
|
||||||
geomkey = "#geometry"
|
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
|
# This will get replaced with a git SHA1 when you do a git archive
|
||||||
__revision__ = '$Format:%H$'
|
__revision__ = '$Format:%H$'
|
||||||
|
|
||||||
|
import qgis
|
||||||
from utilities import unittest, TestCase
|
from utilities import unittest, TestCase
|
||||||
from qgis.utils import qgsfunction
|
from qgis.utils import qgsfunction
|
||||||
from qgis.core import QgsExpression
|
from qgis.core import QgsExpression
|
||||||
from PyQt4.QtCore import QString
|
|
||||||
|
|
||||||
class TestQgsExpressionCustomFunctions(TestCase):
|
class TestQgsExpressionCustomFunctions(TestCase):
|
||||||
@qgsfunction(1, 'testing', register=False)
|
@qgsfunction(1, 'testing', register=False)
|
||||||
def testfun(values, feature, parent):
|
def testfun(values, feature, parent):
|
||||||
""" Function help """
|
""" Function help """
|
||||||
return "Testing_%s" % str(values[0].toString())
|
return "Testing_%s" % values[0]
|
||||||
|
|
||||||
@qgsfunction(0, 'testing', register=False)
|
@qgsfunction(0, 'testing', register=False)
|
||||||
def special(values, feature, parent):
|
def special(values, feature, parent):
|
||||||
@ -51,8 +51,8 @@ class TestQgsExpressionCustomFunctions(TestCase):
|
|||||||
def testCanEvaluateFunction(self):
|
def testCanEvaluateFunction(self):
|
||||||
QgsExpression.registerFunction(self.testfun)
|
QgsExpression.registerFunction(self.testfun)
|
||||||
exp = QgsExpression('testfun(1)')
|
exp = QgsExpression('testfun(1)')
|
||||||
result = exp.evaluate().toString()
|
result = exp.evaluate()
|
||||||
self.assertEqual(QString('Testing_1'), result)
|
self.assertEqual('Testing_1', result)
|
||||||
|
|
||||||
def testZeroArgFunctionsAreSpecialColumns(self):
|
def testZeroArgFunctionsAreSpecialColumns(self):
|
||||||
special = self.special
|
special = self.special
|
||||||
|
@ -14,7 +14,7 @@ __revision__ = '$Format:%H$'
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from PyQt4.QtCore import QVariant
|
import qgis
|
||||||
from qgis.core import QgsFeature, QgsGeometry, QgsPoint, QgsVectorLayer
|
from qgis.core import QgsFeature, QgsGeometry, QgsPoint, QgsVectorLayer
|
||||||
from utilities import (unitTestDataPath,
|
from utilities import (unitTestDataPath,
|
||||||
getQgisTestApp,
|
getQgisTestApp,
|
||||||
@ -44,6 +44,7 @@ class TestQgsFeature(TestCase):
|
|||||||
fit = provider.getFeatures()
|
fit = provider.getFeatures()
|
||||||
feat = QgsFeature()
|
feat = QgsFeature()
|
||||||
fit.nextFeature(feat)
|
fit.nextFeature(feat)
|
||||||
|
fit.close()
|
||||||
myValidValue = feat.isValid()
|
myValidValue = feat.isValid()
|
||||||
myMessage = '\nExpected: %s\nGot: %s' % ("True", myValidValue)
|
myMessage = '\nExpected: %s\nGot: %s' % ("True", myValidValue)
|
||||||
assert myValidValue == True, myMessage
|
assert myValidValue == True, myMessage
|
||||||
@ -55,13 +56,14 @@ class TestQgsFeature(TestCase):
|
|||||||
fit = provider.getFeatures()
|
fit = provider.getFeatures()
|
||||||
feat = QgsFeature()
|
feat = QgsFeature()
|
||||||
fit.nextFeature(feat)
|
fit.nextFeature(feat)
|
||||||
|
fit.close()
|
||||||
myAttributes = feat.attributes()
|
myAttributes = feat.attributes()
|
||||||
myExpectedAttributes = [ QVariant("Highway"), QVariant(1) ]
|
myExpectedAttributes = [ "Highway", 1 ]
|
||||||
|
|
||||||
# Only for printing purposes
|
# Only for printing purposes
|
||||||
myAttributeDict = [
|
myAttributeDict = [
|
||||||
str(myAttributes[0].toString()),
|
myAttributes[0],
|
||||||
int(myAttributes[1].toString()) ]
|
myAttributes[1] ]
|
||||||
myExpectedAttributes = [ "Highway", 1 ]
|
myExpectedAttributes = [ "Highway", 1 ]
|
||||||
myMessage = '\nExpected: %s\nGot: %s' % (myExpectedAttributes,
|
myMessage = '\nExpected: %s\nGot: %s' % (myExpectedAttributes,
|
||||||
myAttributes)
|
myAttributes)
|
||||||
@ -71,11 +73,11 @@ class TestQgsFeature(TestCase):
|
|||||||
def test_DeleteAttribute(self):
|
def test_DeleteAttribute(self):
|
||||||
feat = QgsFeature()
|
feat = QgsFeature()
|
||||||
feat.initAttributes(3)
|
feat.initAttributes(3)
|
||||||
feat[0] = QVariant("text1")
|
feat[0] = "text1"
|
||||||
feat[1] = QVariant("text2")
|
feat[1] = "text2"
|
||||||
feat[2] = QVariant("text3")
|
feat[2] = "text3"
|
||||||
feat.deleteAttribute(1)
|
feat.deleteAttribute(1)
|
||||||
myAttrs = [ str(feat[0].toString()), str(feat[1].toString()) ]
|
myAttrs = [ feat[0], feat[1] ]
|
||||||
myExpectedAttrs = [ "text1", "text3" ]
|
myExpectedAttrs = [ "text1", "text3" ]
|
||||||
myMessage = '\nExpected: %s\nGot: %s' % (str(myExpectedAttrs), str(myAttrs))
|
myMessage = '\nExpected: %s\nGot: %s' % (str(myExpectedAttrs), str(myAttrs))
|
||||||
assert myAttrs == myExpectedAttrs, myMessage
|
assert myAttrs == myExpectedAttrs, myMessage
|
||||||
|
@ -14,7 +14,7 @@ __revision__ = '$Format:%H$'
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from PyQt4.QtCore import QVariant
|
import qgis
|
||||||
|
|
||||||
from qgis.core import (QgsGeometry,
|
from qgis.core import (QgsGeometry,
|
||||||
QgsVectorLayer,
|
QgsVectorLayer,
|
||||||
@ -264,7 +264,7 @@ class TestQgsGeometry(TestCase):
|
|||||||
QgsPoint(40,10),
|
QgsPoint(40,10),
|
||||||
]
|
]
|
||||||
))
|
))
|
||||||
myFeature1.setAttributes([QVariant('Johny')])
|
myFeature1.setAttributes(['Johny'])
|
||||||
|
|
||||||
myFeature2 = QgsFeature()
|
myFeature2 = QgsFeature()
|
||||||
myFeature2.setGeometry(QgsGeometry.fromPolyline([
|
myFeature2.setGeometry(QgsGeometry.fromPolyline([
|
||||||
@ -274,7 +274,7 @@ class TestQgsGeometry(TestCase):
|
|||||||
QgsPoint(40,40),
|
QgsPoint(40,40),
|
||||||
]
|
]
|
||||||
))
|
))
|
||||||
myFeature2.setAttributes([QVariant('Be')])
|
myFeature2.setAttributes(['Be'])
|
||||||
|
|
||||||
myFeature3 = QgsFeature()
|
myFeature3 = QgsFeature()
|
||||||
myFeature3.setGeometry(QgsGeometry.fromPolyline([
|
myFeature3.setGeometry(QgsGeometry.fromPolyline([
|
||||||
@ -285,7 +285,7 @@ class TestQgsGeometry(TestCase):
|
|||||||
]
|
]
|
||||||
))
|
))
|
||||||
|
|
||||||
myFeature3.setAttributes([QVariant('Good')])
|
myFeature3.setAttributes(['Good'])
|
||||||
|
|
||||||
myResult, myFeatures = myProvider.addFeatures(
|
myResult, myFeatures = myProvider.addFeatures(
|
||||||
[myFeature1, myFeature2, myFeature3])
|
[myFeature1, myFeature2, myFeature3])
|
||||||
|
@ -14,6 +14,7 @@ __revision__ = '$Format:%H$'
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
import qgis
|
||||||
|
|
||||||
from qgis.core import *
|
from qgis.core import *
|
||||||
from qgis.gui import *
|
from qgis.gui import *
|
||||||
|
@ -14,6 +14,7 @@ __revision__ = '$Format:%H$'
|
|||||||
|
|
||||||
import tempfile
|
import tempfile
|
||||||
import os
|
import os
|
||||||
|
import qgis
|
||||||
from qgis.core import QgsLogger
|
from qgis.core import QgsLogger
|
||||||
from utilities import (TestCase,
|
from utilities import (TestCase,
|
||||||
unittest
|
unittest
|
||||||
|
@ -13,6 +13,7 @@ __copyright__ = 'Copyright 2012, The QGIS Project'
|
|||||||
__revision__ = '$Format:%H$'
|
__revision__ = '$Format:%H$'
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import qgis
|
||||||
from PyQt4.QtCore import *
|
from PyQt4.QtCore import *
|
||||||
from PyQt4.QtGui import *
|
from PyQt4.QtGui import *
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ __copyright__ = 'Copyright 2012, The QGIS Project'
|
|||||||
__revision__ = '$Format:%H$'
|
__revision__ = '$Format:%H$'
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import qgis
|
||||||
|
|
||||||
from qgis.core import QgsPoint
|
from qgis.core import QgsPoint
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ __revision__ = '$Format:%H$'
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import glob
|
import glob
|
||||||
|
import qgis
|
||||||
|
|
||||||
from PyQt4.QtCore import (QTemporaryFile,
|
from PyQt4.QtCore import (QTemporaryFile,
|
||||||
QDir)
|
QDir)
|
||||||
|
@ -14,8 +14,9 @@ __revision__ = '$Format:%H$'
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
|
import qgis
|
||||||
|
|
||||||
from PyQt4.QtCore import QFileInfo, QString, QStringList
|
from PyQt4.QtCore import QFileInfo
|
||||||
from PyQt4 import QtGui
|
from PyQt4 import QtGui
|
||||||
|
|
||||||
from qgis.core import (QgsRaster,
|
from qgis.core import (QgsRaster,
|
||||||
@ -60,7 +61,7 @@ class TestQgsRasterLayer(TestCase):
|
|||||||
|
|
||||||
# Get the name of the first band
|
# Get the name of the first band
|
||||||
myBand = myRasterValues.keys()[0]
|
myBand = myRasterValues.keys()[0]
|
||||||
#myExpectedName = QString('Band 1')
|
#myExpectedName = 'Band 1
|
||||||
myExpectedBand = 1
|
myExpectedBand = 1
|
||||||
myMessage = 'Expected "%s" got "%s" for first raster band name' % (
|
myMessage = 'Expected "%s" got "%s" for first raster band name' % (
|
||||||
myExpectedBand, myBand)
|
myExpectedBand, myBand)
|
||||||
@ -71,8 +72,7 @@ class TestQgsRasterLayer(TestCase):
|
|||||||
myValues = myRasterValues.values()
|
myValues = myRasterValues.values()
|
||||||
myIntValues = []
|
myIntValues = []
|
||||||
for myValue in myValues:
|
for myValue in myValues:
|
||||||
#myIntValues.append(int(str(myValue)))
|
myIntValues.append( int(myValue) )
|
||||||
myIntValues.append( myValue.toInt()[0] )
|
|
||||||
myValues = str(myIntValues)
|
myValues = str(myIntValues)
|
||||||
myExpectedValues = '[127, 141, 112, 72, 86, 126, 156, 211, 170]'
|
myExpectedValues = '[127, 141, 112, 72, 86, 126, 156, 211, 170]'
|
||||||
myMessage = 'Expected: %s\nGot: %s' % (myValues, myExpectedValues)
|
myMessage = 'Expected: %s\nGot: %s' % (myValues, myExpectedValues)
|
||||||
@ -140,7 +140,7 @@ class TestQgsRasterLayer(TestCase):
|
|||||||
|
|
||||||
myMapRenderer = QgsMapRenderer()
|
myMapRenderer = QgsMapRenderer()
|
||||||
|
|
||||||
myLayers = QStringList()
|
myLayers = []
|
||||||
myLayers.append(myRasterLayer.id())
|
myLayers.append(myRasterLayer.id())
|
||||||
myMapRenderer.setLayerSet(myLayers)
|
myMapRenderer.setLayerSet(myLayers)
|
||||||
myMapRenderer.setExtent(myRasterLayer.extent())
|
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
|
# This will get replaced with a git SHA1 when you do a git archive
|
||||||
__revision__ = '$Format:%H$'
|
__revision__ = '$Format:%H$'
|
||||||
|
|
||||||
|
import qgis
|
||||||
from qgis.core import (QgsRectangle,
|
from qgis.core import (QgsRectangle,
|
||||||
QgsPoint)
|
QgsPoint)
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ __copyright__ = 'Copyright 2012, The QGIS Project'
|
|||||||
__revision__ = '$Format:%H$'
|
__revision__ = '$Format:%H$'
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
import qgis
|
||||||
|
|
||||||
from qgis.core import (QgsSpatialIndex,
|
from qgis.core import (QgsSpatialIndex,
|
||||||
QgsFeature,
|
QgsFeature,
|
||||||
|
@ -14,6 +14,7 @@ __revision__ = '$Format:%H$'
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import qgis
|
||||||
|
|
||||||
from qgis.core import *
|
from qgis.core import *
|
||||||
|
|
||||||
|
@ -13,8 +13,9 @@ __copyright__ = 'Copyright 2012, The QGIS Project'
|
|||||||
__revision__ = '$Format:%H$'
|
__revision__ = '$Format:%H$'
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import qgis
|
||||||
|
|
||||||
from PyQt4.QtCore import QVariant, QDir, QString, QStringList
|
from PyQt4.QtCore import QDir
|
||||||
|
|
||||||
from qgis.core import (QgsVectorLayer,
|
from qgis.core import (QgsVectorLayer,
|
||||||
QgsFeature,
|
QgsFeature,
|
||||||
@ -51,9 +52,7 @@ class TestQgsVectorLayer(TestCase):
|
|||||||
|
|
||||||
ft = QgsFeature()
|
ft = QgsFeature()
|
||||||
ft.setGeometry(QgsGeometry.fromPoint(QgsPoint(10,10)))
|
ft.setGeometry(QgsGeometry.fromPoint(QgsPoint(10,10)))
|
||||||
ft.setAttributes([ QVariant('Johny'),
|
ft.setAttributes([ 'Johny', 20, 0.3 ])
|
||||||
QVariant(20),
|
|
||||||
QVariant(0.3)])
|
|
||||||
myResult, myFeatures = myProvider.addFeatures([ft])
|
myResult, myFeatures = myProvider.addFeatures([ft])
|
||||||
assert myResult == True
|
assert myResult == True
|
||||||
assert len(myFeatures) > 0
|
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
|
# This will get replaced with a git SHA1 when you do a git archive
|
||||||
__revision__ = '$Format:%H$'
|
__revision__ = '$Format:%H$'
|
||||||
|
|
||||||
import os
|
import qgis
|
||||||
|
|
||||||
|
import os
|
||||||
from PyQt4.QtCore import *
|
from PyQt4.QtCore import *
|
||||||
from qgis.core import *
|
from qgis.core import *
|
||||||
from qgis.analysis import *
|
from qgis.analysis import *
|
||||||
@ -33,6 +34,7 @@ class TestQgsZonalStatistics(TestCase):
|
|||||||
myTempPath = QDir.tempPath() + sep
|
myTempPath = QDir.tempPath() + sep
|
||||||
testDir = QDir(TEST_DATA_DIR)
|
testDir = QDir(TEST_DATA_DIR)
|
||||||
for f in testDir.entryList(QDir.Files):
|
for f in testDir.entryList(QDir.Files):
|
||||||
|
QFile.remove(myTempPath + f)
|
||||||
QFile.copy(TEST_DATA_DIR + f, myTempPath + f)
|
QFile.copy(TEST_DATA_DIR + f, myTempPath + f)
|
||||||
|
|
||||||
myVector = QgsVectorLayer(myTempPath + "polys.shp", "poly", "ogr")
|
myVector = QgsVectorLayer(myTempPath + "polys.shp", "poly", "ogr")
|
||||||
@ -44,30 +46,30 @@ class TestQgsZonalStatistics(TestCase):
|
|||||||
# validate statistics for each feature
|
# validate statistics for each feature
|
||||||
request = QgsFeatureRequest().setFilterFid(0)
|
request = QgsFeatureRequest().setFilterFid(0)
|
||||||
feat = myVector.getFeatures(request).next()
|
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
|
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
|
assert feat[2] == 8.0, myMessage
|
||||||
myMessage = ('Expected: %f\nGot: %f\n' % (0.666666666666667, feat[3].toDouble()[0]))
|
myMessage = ('Expected: %f\nGot: %f\n' % (0.666666666666667, feat[3]))
|
||||||
assert feat[3] == 0.666666666666667, myMessage
|
assert abs(feat[3] - 0.666666666666667 ) < 0.00001, myMessage
|
||||||
|
|
||||||
request.setFilterFid(1)
|
request.setFilterFid(1)
|
||||||
feat = myVector.getFeatures(request).next()
|
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
|
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
|
assert feat[2] == 5.0, myMessage
|
||||||
myMessage = ('Expected: %f\nGot: %f\n' % (0.555555555555556, feat[3].toDouble()[0]))
|
myMessage = ('Expected: %f\nGot: %f\n' % (0.555555555555556, feat[3]))
|
||||||
assert feat[3] == 0.555555555555556, myMessage
|
assert abs( feat[3] - 0.555555555555556) < 0.00001, myMessage
|
||||||
|
|
||||||
request.setFilterFid(2)
|
request.setFilterFid(2)
|
||||||
feat = myVector.getFeatures(request).next()
|
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
|
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
|
assert feat[2] == 5.0, myMessage
|
||||||
myMessage = ('Expected: %f\nGot: %f\n' % (0.833333333333333, feat[3].toDouble()[0]))
|
myMessage = ('Expected: %f\nGot: %f\n' % (0.833333333333333, feat[3]))
|
||||||
assert feat[3] == 0.833333333333333, myMessage
|
assert abs( feat[3] - 0.833333333333333 ) < 0.00001, myMessage
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -13,6 +13,7 @@ __revision__ = '$Format:%H$'
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import qgis
|
||||||
from PyQt4 import QtGui, QtCore
|
from PyQt4 import QtGui, QtCore
|
||||||
from qgis.core import (QgsApplication,
|
from qgis.core import (QgsApplication,
|
||||||
QgsCoordinateReferenceSystem,
|
QgsCoordinateReferenceSystem,
|
||||||
@ -166,9 +167,9 @@ def writeShape(theMemoryLayer, theFileName):
|
|||||||
myFileName = os.path.join(str(QtCore.QDir.tempPath()), theFileName)
|
myFileName = os.path.join(str(QtCore.QDir.tempPath()), theFileName)
|
||||||
print myFileName
|
print myFileName
|
||||||
# Explicitly giving all options, not really needed but nice for clarity
|
# Explicitly giving all options, not really needed but nice for clarity
|
||||||
myErrorMessage = QtCore.QString()
|
myErrorMessage = ''
|
||||||
myOptions = QtCore.QStringList()
|
myOptions = []
|
||||||
myLayerOptions = QtCore.QStringList()
|
myLayerOptions = []
|
||||||
mySelectedOnlyFlag = False
|
mySelectedOnlyFlag = False
|
||||||
mySkipAttributesFlag = False
|
mySkipAttributesFlag = False
|
||||||
myGeoCrs = QgsCoordinateReferenceSystem()
|
myGeoCrs = QgsCoordinateReferenceSystem()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user