Skip to content
Permalink
Browse files

Added from uri test for mem provider. Simplified the vector writer test.

  • Loading branch information
timlinux committed Nov 9, 2012
1 parent 5817ad1 commit 3f72a6a59372398c268bd9c91be66c1ee9a88b61
Showing with 25 additions and 9 deletions.
  1. +12 −0 tests/src/python/test_qgsmemoryprovider.py
  2. +13 −9 tests/src/python/test_qgsvectorfilewriter.py
@@ -98,5 +98,17 @@ def testAddFeatures(self):

assert str(geom.exportToWkt()) == "POINT(10.0 10.0)", myMessage

def testFromUri(self):
"""Test we can construct the mem provider from a uri"""
myMemoryLayer = QgsVectorLayer(
('Point?crs=epsg:4326&field=name:string(20)&'
'field=age:integer&field=size:double&index=yes'),
'test',
'memory')

assert myMemoryLayer is not None, 'Provider not initialised'
myProvider = myMemoryLayer.dataProvider()
assert myProvider is not None

if __name__ == '__main__':
unittest.main()
@@ -38,20 +38,24 @@ class TestQgsVectorLayer(TestCase):
mMemoryLayer = None

def setUp(self):
self.mMemoryLayer = QgsVectorLayer("Point", "test", "memory")
myProvider = self.mMemoryLayer.dataProvider()
self.mMemoryLayer = QgsVectorLayer(
('Point?crs=epsg:4326&field=name:string(20)&'
'field=age:integer&field=size:double&index=yes'),
'test',
'memory')

myProvider.addAttributes([
QgsField("name", QVariant.String),
QgsField("age", QVariant.Int),
QgsField("size", QVariant.Double)])
assert self.mMemoryLayer is not None, 'Provider not initialised'
myProvider = self.mMemoryLayer.dataProvider()
assert myProvider is not None

ft = QgsFeature()
ft.setGeometry(QgsGeometry.fromPoint(QgsPoint(10,10)))
ft.setAttributeMap({0 : QVariant("Johny"),
ft.setAttributeMap({0 : QVariant('Johny'),
1 : QVariant(20),
2 : QVariant(0.3)})
myProvider.addFeatures([ft])
myResult, myFeatures = myProvider.addFeatures([ft])
assert myResult == True
assert len(myFeatures) > 0


def testWrite(self):
@@ -72,7 +76,7 @@ def testWrite(self):
myFileName,
'utf-8',
myGeoCrs,
"ESRI Shapefile",
'ESRI Shapefile',
mySelectedOnlyFlag,
myErrorMessage,
myOptions,

0 comments on commit 3f72a6a

Please sign in to comment.
You can’t perform that action at this time.