|
1 | 1 | # -*- coding: utf-8 -*-
|
2 |
| -"""QGIS Unit tests for QgsMemoryProvider. |
| 2 | +"""QGIS Unit tests for the memory layer provider. |
3 | 3 |
|
4 | 4 | .. note:: This program is free software; you can redistribute it and/or modify
|
5 | 5 | it under the terms of the GNU General Public License as published by
|
6 | 6 | the Free Software Foundation; either version 2 of the License, or
|
7 | 7 | (at your option) any later version.
|
8 | 8 | """
|
9 |
| -__author__ = 'Alexander Bruy' |
10 |
| -__date__ = '20/08/2012' |
11 |
| -__copyright__ = 'Copyright 2012, The QGIS Project' |
| 9 | +__author__ = 'Matthias Kuhn' |
| 10 | +__date__ = '2015-04-23' |
| 11 | +__copyright__ = 'Copyright 2015, The QGIS Project' |
12 | 12 | # This will get replaced with a git SHA1 when you do a git archive
|
13 | 13 | __revision__ = '$Format:%H$'
|
14 | 14 |
|
15 |
| -import qgis |
| 15 | +import os |
| 16 | +import tempfile |
| 17 | +import shutil |
| 18 | +import glob |
16 | 19 |
|
17 |
| -from PyQt4.QtCore import QVariant |
18 |
| - |
19 |
| -from qgis.core import (QGis, |
20 |
| - QgsVectorLayer, |
21 |
| - QgsFeature, |
22 |
| - QgsFeatureRequest, |
23 |
| - QgsField, |
24 |
| - QgsGeometry, |
25 |
| - QgsPoint |
26 |
| - ) |
27 |
| - |
28 |
| -from utilities import (getQgisTestApp, |
29 |
| - TestCase, |
| 20 | +from qgis.core import QGis, QgsField, QgsPoint, QgsVectorLayer, QgsFeatureRequest, QgsFeature, QgsProviderRegistry, QgsGeometry, NULL |
| 21 | +from PyQt4.QtCore import QSettings |
| 22 | +from utilities import (unitTestDataPath, |
| 23 | + getQgisTestApp, |
30 | 24 | unittest,
|
| 25 | + TestCase, |
31 | 26 | compareWkt
|
32 | 27 | )
|
33 |
| -QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp() |
34 |
| - |
35 |
| - |
36 |
| -class TestQgsMemoryProvider(TestCase): |
| 28 | +from providertestbase import ProviderTestCase |
| 29 | +from PyQt4.QtCore import QVariant |
37 | 30 |
|
| 31 | +QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp() |
| 32 | +TEST_DATA_DIR = unitTestDataPath() |
| 33 | + |
| 34 | + |
| 35 | +class TestPyQgsMemoryProvider(TestCase, ProviderTestCase): |
| 36 | + @classmethod |
| 37 | + def setUpClass(cls): |
| 38 | + """Run before all tests""" |
| 39 | + # Create test layer |
| 40 | + cls.vl = QgsVectorLayer(u'Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&key=pk', u'test', u'memory') |
| 41 | + assert (cls.vl.isValid()) |
| 42 | + cls.provider = cls.vl.dataProvider() |
| 43 | + |
| 44 | + f1 = QgsFeature() |
| 45 | + f1.setAttributes( [5, -200, NULL] ) |
| 46 | + f1.setGeometry( QgsGeometry.fromWkt('Point (-71.123 78.23)')) |
| 47 | + |
| 48 | + f2 = QgsFeature() |
| 49 | + f2.setAttributes( [3, 300, 'Pear'] ) |
| 50 | + |
| 51 | + f3 = QgsFeature() |
| 52 | + f3.setAttributes( [1, 100, 'Orange'] ) |
| 53 | + f3.setGeometry( QgsGeometry.fromWkt('Point (-70.332 66.33)')) |
| 54 | + |
| 55 | + f4 = QgsFeature() |
| 56 | + f4.setAttributes( [2, 200, 'Apple'] ) |
| 57 | + f4.setGeometry( QgsGeometry.fromWkt('Point (-68.2 70.8)')) |
| 58 | + |
| 59 | + f5 = QgsFeature() |
| 60 | + f5.setAttributes( [4, 400, 'Honey'] ) |
| 61 | + f5.setGeometry( QgsGeometry.fromWkt('Point (-65.32 78.3)')) |
| 62 | + |
| 63 | + cls.provider.addFeatures( [ f1, f2, f3, f4, f5] ); |
| 64 | + |
| 65 | + |
| 66 | + @classmethod |
| 67 | + def tearDownClass(cls): |
| 68 | + """Run after all tests""" |
| 69 | + |
38 | 70 | def testPointCtor(self):
|
39 | 71 | layer = QgsVectorLayer("Point", "test", "memory")
|
40 | 72 | assert layer.isValid(), "Failed to create valid point memory layer"
|
@@ -135,7 +167,8 @@ def testFromUri(self):
|
135 | 167 |
|
136 | 168 | assert myMemoryLayer is not None, 'Provider not initialised'
|
137 | 169 | myProvider = myMemoryLayer.dataProvider()
|
138 |
| - assert myProvider is not None |
139 |
| - |
| 170 | + assert myProvider is not None |
| 171 | + |
| 172 | + |
140 | 173 | if __name__ == '__main__':
|
141 | 174 | unittest.main()
|
0 commit comments