|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +"""QGIS Unit tests for QgsVectorLayerCache. |
| 3 | +
|
| 4 | +.. note:: This program is free software; you can redistribute it and/or modify |
| 5 | +it under the terms of the GNU General Public License as published by |
| 6 | +the Free Software Foundation; either version 2 of the License, or |
| 7 | +(at your option) any later version. |
| 8 | +""" |
| 9 | +__author__ = 'Nyall Dawson' |
| 10 | +__date__ = '08/06/2017' |
| 11 | +__copyright__ = 'Copyright 2017, The QGIS Project' |
| 12 | +# This will get replaced with a git SHA1 when you do a git archive |
| 13 | +__revision__ = '$Format:%H$' |
| 14 | + |
| 15 | +import qgis # NOQA |
| 16 | + |
| 17 | +import os |
| 18 | + |
| 19 | +from qgis.PyQt.QtCore import QVariant, Qt |
| 20 | +from qgis.PyQt.QtGui import QPainter |
| 21 | +from qgis.PyQt.QtXml import QDomDocument |
| 22 | + |
| 23 | +from qgis.core import (QgsWkbTypes, |
| 24 | + QgsVectorLayer, |
| 25 | + QgsVectorLayerCache, |
| 26 | + QgsRectangle, |
| 27 | + QgsFeature, |
| 28 | + QgsFeatureRequest, |
| 29 | + QgsGeometry, |
| 30 | + QgsPointXY, |
| 31 | + QgsField, |
| 32 | + QgsFields, |
| 33 | + QgsCoordinateReferenceSystem, |
| 34 | + QgsProject, |
| 35 | + QgsPoint, |
| 36 | + NULL) |
| 37 | +from qgis.testing import start_app, unittest |
| 38 | +from featuresourcetestbase import FeatureSourceTestCase |
| 39 | +from utilities import unitTestDataPath |
| 40 | +start_app() |
| 41 | + |
| 42 | + |
| 43 | +class TestQgsVectorLayerCache(unittest.TestCase, FeatureSourceTestCase): |
| 44 | + |
| 45 | + @classmethod |
| 46 | + def getSource(cls): |
| 47 | + cache = QgsVectorLayerCache(cls.vl, 100) |
| 48 | + return cache |
| 49 | + |
| 50 | + @classmethod |
| 51 | + def setUpClass(cls): |
| 52 | + """Run before all tests""" |
| 53 | + # Create test layer for FeatureSourceTestCase |
| 54 | + cls.vl = QgsVectorLayer( |
| 55 | + 'Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&key=pk', |
| 56 | + 'test', 'memory') |
| 57 | + assert (cls.vl.isValid()) |
| 58 | + |
| 59 | + f1 = QgsFeature(5) |
| 60 | + f1.setAttributes([5, -200, NULL, 'NuLl', '5']) |
| 61 | + f1.setGeometry(QgsGeometry.fromWkt('Point (-71.123 78.23)')) |
| 62 | + |
| 63 | + f2 = QgsFeature(3) |
| 64 | + f2.setAttributes([3, 300, 'Pear', 'PEaR', '3']) |
| 65 | + |
| 66 | + f3 = QgsFeature(1) |
| 67 | + f3.setAttributes([1, 100, 'Orange', 'oranGe', '1']) |
| 68 | + f3.setGeometry(QgsGeometry.fromWkt('Point (-70.332 66.33)')) |
| 69 | + |
| 70 | + f4 = QgsFeature(2) |
| 71 | + f4.setAttributes([2, 200, 'Apple', 'Apple', '2']) |
| 72 | + f4.setGeometry(QgsGeometry.fromWkt('Point (-68.2 70.8)')) |
| 73 | + |
| 74 | + f5 = QgsFeature(4) |
| 75 | + f5.setAttributes([4, 400, 'Honey', 'Honey', '4']) |
| 76 | + f5.setGeometry(QgsGeometry.fromWkt('Point (-65.32 78.3)')) |
| 77 | + |
| 78 | + assert cls.vl.dataProvider().addFeatures([f1, f2, f3, f4, f5]) |
| 79 | + cls.source = QgsVectorLayerCache(cls.vl, 100) |
| 80 | + |
| 81 | + def testGetFeaturesSubsetAttributes2(self): |
| 82 | + """ Override and skip this QgsFeatureSource test. We are using a memory provider, and it's actually more efficient for the memory provider to return |
| 83 | + its features as direct copies (due to implicit sharing of QgsFeature) |
| 84 | + """ |
| 85 | + pass |
| 86 | + |
| 87 | + def testGetFeaturesNoGeometry(self): |
| 88 | + """ Override and skip this QgsFeatureSource test. We are using a memory provider, and it's actually more efficient for the memory provider to return |
| 89 | + its features as direct copies (due to implicit sharing of QgsFeature) |
| 90 | + """ |
| 91 | + pass |
| 92 | + |
| 93 | + |
| 94 | +if __name__ == '__main__': |
| 95 | + unittest.main() |
0 commit comments