Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added unit test for vector file writer as it is currently segfaulting…
… in master
- Loading branch information
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# -*- coding: utf-8 -*- | ||
"""QGIS Unit tests for QgsVectorFileWriter. | ||
.. note:: This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
""" | ||
__author__ = 'Tim Sutton' | ||
__date__ = '20/08/2012' | ||
__copyright__ = 'Copyright 2012, The Quantum GIS Project' | ||
# This will get replaced with a git SHA1 when you do a git archive | ||
__revision__ = '$Format:%H$' | ||
|
||
import os | ||
|
||
from PyQt4.QtCore import QVariant, QDir, QString, QStringList | ||
|
||
from qgis.core import (QgsVectorLayer, | ||
QgsFeature, | ||
QgsField, | ||
QgsGeometry, | ||
QgsPoint, | ||
QgsVectorFileWriter, | ||
QgsCoordinateReferenceSystem) | ||
|
||
from utilities import (unitTestDataPath, | ||
getQgisTestApp, | ||
TestCase, | ||
unittest, | ||
#expectedFailure | ||
) | ||
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp() | ||
|
||
|
||
class TestQgsVectorLayer(TestCase): | ||
|
||
mMemoryLayer = None | ||
|
||
def setUp(self): | ||
self.mMemoryLayer = QgsVectorLayer("Point", "test", "memory") | ||
myProvider = self.mMemoryLayer.dataProvider() | ||
|
||
myProvider.addAttributes([ | ||
QgsField("name", QVariant.String), | ||
QgsField("age", QVariant.Int), | ||
QgsField("size", QVariant.Double)]) | ||
|
||
ft = QgsFeature() | ||
ft.setGeometry(QgsGeometry.fromPoint(QgsPoint(10,10))) | ||
ft.setAttributeMap({0 : QVariant("Johny"), | ||
1 : QVariant(20), | ||
2 : QVariant(0.3)}) | ||
myProvider.addFeatures([ft]) | ||
|
||
|
||
def testWrite(self): | ||
"""Check we can write a vector file.""" | ||
|
||
myFileName = os.path.join(str(QDir.tempPath()), 'writetest.shp') | ||
print myFileName | ||
# Explicitly giving all options, not really needed but nice for clarity | ||
myErrorMessage = QString() | ||
myOptions = QStringList() | ||
myLayerOptions = QStringList() | ||
mySelectedOnlyFlag = False | ||
mySkipAttributesFlag = False | ||
myGeoCrs = QgsCoordinateReferenceSystem() | ||
myGeoCrs.createFromId(4326, QgsCoordinateReferenceSystem.EpsgCrsId) | ||
myResult = QgsVectorFileWriter.writeAsVectorFormat( | ||
self.mMemoryLayer, | ||
myFileName, | ||
'utf-8', | ||
myGeoCrs, | ||
"ESRI Shapefile", | ||
mySelectedOnlyFlag, | ||
myErrorMessage, | ||
myOptions, | ||
myLayerOptions, | ||
mySkipAttributesFlag) | ||
assert myResult==True | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters