11 changes: 6 additions & 5 deletions tests/src/python/test_qgscomposerlabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
***************************************************************************/
'''
import unittest
import qgis
from utilities import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
Expand All @@ -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 )
Expand Down Expand Up @@ -62,7 +63,7 @@ def evaluation_test( self, mComposition, mLabel ):
# $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)
Expand Down Expand Up @@ -101,9 +102,9 @@ def page_evaluation_test( self, mComposition, mLabel, mVectorLayer ):

# 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%]"
Expand Down
6 changes: 3 additions & 3 deletions tests/src/python/test_qgscomposermap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -57,7 +57,7 @@ def __init__(self, methodName):

# create composition with composer map
self.mMapRenderer = QgsMapRenderer()
layerStringList = QStringList()
layerStringList = []
layerStringList.append(mRasterLayer.id())
self.mMapRenderer.setLayerSet(layerStringList)
self.mMapRenderer.setProjectionsEnabled(False)
Expand Down
5 changes: 3 additions & 2 deletions tests/src/python/test_qgscomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
__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,
Expand Down Expand Up @@ -104,7 +105,7 @@ def testPrintMapFromTemplate(self):
QgsMapLayerRegistry.instance().addMapLayers([myRasterLayer])

myMapRenderer = QgsMapRenderer()
myLayerStringList = QStringList()
myLayerStringList = []
myLayerStringList.append(myRasterLayer.id())
myMapRenderer.setLayerSet(myLayerStringList)
myMapRenderer.setProjectionsEnabled(False)
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/test_qgscoordinatetransform.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# 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,
Expand Down
13 changes: 4 additions & 9 deletions tests/src/python/test_qgsdelimitedtextprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#
# To recreate all tests, set rebuildTests to true

import os;
import os.path;
import os
import os.path
import re
import tempfile
import inspect
Expand All @@ -33,13 +33,7 @@

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,
Expand Down Expand Up @@ -69,6 +63,7 @@

QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()

import sip
sipversion=str(sip.getapi('QVariant'))
sipwanted='2'
geomkey = "#geometry"
Expand Down
8 changes: 4 additions & 4 deletions tests/src/python/test_qgsexpression.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
# 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):
Expand Down Expand Up @@ -51,8 +51,8 @@ def testCanUnregisterFunction(self):
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
Expand Down
18 changes: 10 additions & 8 deletions tests/src/python/test_qgsfeature.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import os

from PyQt4.QtCore import QVariant
import qgis
from qgis.core import QgsFeature, QgsGeometry, QgsPoint, QgsVectorLayer
from utilities import (unitTestDataPath,
getQgisTestApp,
Expand Down Expand Up @@ -44,6 +44,7 @@ def test_ValidFeature(self):
fit = provider.getFeatures()
feat = QgsFeature()
fit.nextFeature(feat)
fit.close()
myValidValue = feat.isValid()
myMessage = '\nExpected: %s\nGot: %s' % ("True", myValidValue)
assert myValidValue == True, myMessage
Expand All @@ -55,13 +56,14 @@ def test_Attributes(self):
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)
Expand All @@ -71,11 +73,11 @@ def test_Attributes(self):
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
Expand Down
8 changes: 4 additions & 4 deletions tests/src/python/test_qgsgeometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import os

from PyQt4.QtCore import QVariant
import qgis

from qgis.core import (QgsGeometry,
QgsVectorLayer,
Expand Down Expand Up @@ -264,7 +264,7 @@ def testClipping(self):
QgsPoint(40,10),
]
))
myFeature1.setAttributes([QVariant('Johny')])
myFeature1.setAttributes(['Johny'])

myFeature2 = QgsFeature()
myFeature2.setGeometry(QgsGeometry.fromPolyline([
Expand All @@ -274,7 +274,7 @@ def testClipping(self):
QgsPoint(40,40),
]
))
myFeature2.setAttributes([QVariant('Be')])
myFeature2.setAttributes(['Be'])

myFeature3 = QgsFeature()
myFeature3.setGeometry(QgsGeometry.fromPolyline([
Expand All @@ -285,7 +285,7 @@ def testClipping(self):
]
))

myFeature3.setAttributes([QVariant('Good')])
myFeature3.setAttributes(['Good'])

myResult, myFeatures = myProvider.addFeatures(
[myFeature1, myFeature2, myFeature3])
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/test_qgsissue7244.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import os
import random
import qgis

from qgis.core import *
from qgis.gui import *
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/test_qgslogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import tempfile
import os
import qgis
from qgis.core import QgsLogger
from utilities import (TestCase,
unittest
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/test_qgspallabeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
__revision__ = '$Format:%H$'

import os
import qgis
from PyQt4.QtCore import *
from PyQt4.QtGui import *

Expand Down
1 change: 1 addition & 0 deletions tests/src/python/test_qgspoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
__revision__ = '$Format:%H$'

import os
import qgis

from qgis.core import QgsPoint

Expand Down
1 change: 1 addition & 0 deletions tests/src/python/test_qgsrasterfilewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import os
import glob
import qgis

from PyQt4.QtCore import (QTemporaryFile,
QDir)
Expand Down
10 changes: 5 additions & 5 deletions tests/src/python/test_qgsrasterlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

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,
Expand Down Expand Up @@ -60,7 +61,7 @@ def testIdentify(self):

# 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)
Expand All @@ -71,8 +72,7 @@ def testIdentify(self):
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)
Expand Down Expand Up @@ -140,7 +140,7 @@ def testTransparency(self):

myMapRenderer = QgsMapRenderer()

myLayers = QStringList()
myLayers = []
myLayers.append(myRasterLayer.id())
myMapRenderer.setLayerSet(myLayers)
myMapRenderer.setExtent(myRasterLayer.extent())
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/test_qgsrectangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# 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)

Expand Down
1 change: 1 addition & 0 deletions tests/src/python/test_qgsspatialindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
__revision__ = '$Format:%H$'

import unittest
import qgis

from qgis.core import (QgsSpatialIndex,
QgsFeature,
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/test_qgsspatialiteprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import os
import tempfile
import qgis

from qgis.core import *

Expand Down
7 changes: 3 additions & 4 deletions tests/src/python/test_qgsvectorfilewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
__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,
Expand Down Expand Up @@ -51,9 +52,7 @@ def testWrite(self):

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
Expand Down
28 changes: 15 additions & 13 deletions tests/src/python/test_qgszonalstatistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
# 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 *
Expand All @@ -33,6 +34,7 @@ def testStatistics(self):
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")
Expand All @@ -44,30 +46,30 @@ def testStatistics(self):
# 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()
7 changes: 4 additions & 3 deletions tests/src/python/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import os
import sys
import qgis
from PyQt4 import QtGui, QtCore
from qgis.core import (QgsApplication,
QgsCoordinateReferenceSystem,
Expand Down Expand Up @@ -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()
Expand Down