Skip to content
Permalink
Browse files
fix PyQgsMemoryProvider test
  • Loading branch information
alexbruy committed Jul 17, 2013
1 parent c04a130 commit f1e0498dd071601ba2b04d1d21c9cb56aac07176
Showing with 26 additions and 25 deletions.
  1. +26 −25 tests/src/python/test_qgsmemoryprovider.py
@@ -12,15 +12,18 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from PyQt4.QtCore import QVariant
import qgis

from PyQt4.QtCore import *

from qgis.core import (QGis,
QgsVectorLayer,
QgsFeature,
QgsFeatureRequest,
QgsField,
QgsGeometry,
QgsPoint)
QgsVectorLayer,
QgsFeature,
QgsFeatureRequest,
QgsField,
QgsGeometry,
QgsPoint
)

from utilities import (getQgisTestApp,
TestCase,
@@ -63,9 +66,9 @@ def testAddFeatures(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 ])
res, t = provider.addFeatures([ft])

assert res, "Failed to add feature"
@@ -75,21 +78,20 @@ def testAddFeatures(self):
assert provider.featureCount() == 1, myMessage

for f in provider.getFeatures(QgsFeatureRequest()):
attrs = f.attributes()
myMessage = ('Expected: %s\nGot: %s\n' %
("Johny", str(attrs[0].toString())))
("Johny", f[0]))

assert str(attrs[0].toString()) == "Johny", myMessage
assert f[0] == "Johny", myMessage

myMessage = ('Expected: %s\nGot: %s\n' %
(20, attrs[1].toInt()[0]))
(20, f[1]))

assert attrs[1].toInt()[0] == 20, myMessage
assert f[1] == 20, myMessage

myMessage = ('Expected: %s\nGot: %s\n' %
(0.3, attrs[2].toFloat()[0]))
(0.3, f[2]))

assert (attrs[0].toFloat()[0] - 0.3) < 0.0000001, myMessage
assert (f[2] - 0.3) < 0.0000001, myMessage

geom = f.geometry()

@@ -103,26 +105,25 @@ def testGetFields(self):
provider = layer.dataProvider()

provider.addAttributes([QgsField("name", QVariant.String,),
QgsField("age", QVariant.Int),
QgsField("size", QVariant.Double)])
QgsField("age", QVariant.Int),
QgsField("size", QVariant.Double)])
myMessage = ('Expected: %s\nGot: %s\n' %
(3, len(provider.fields())))

assert len(provider.fields()) == 3, myMessage

ft = QgsFeature()
ft.setGeometry(QgsGeometry.fromPoint(QgsPoint(10,10)))
ft.setAttributes([QVariant("Johny"),
QVariant(20),
QVariant(0.3)])
ft.setAttributes(["Johny",
20,
0.3])
provider.addFeatures([ft])

for f in provider.getFeatures(QgsFeatureRequest()):
myMessage = ('Expected: %s\nGot: %s\n' %
("Johny", str(f['name'].toString())))

self.assertEqual(str(f["name"].toString()), "Johny", myMessage)
("Johny", f['name']))

self.assertEqual(f["name"], "Johny", myMessage)

def testFromUri(self):
"""Test we can construct the mem provider from a uri"""

0 comments on commit f1e0498

Please sign in to comment.