Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Add shapefile provider tests
+ Fix OGR provider so it does not return features without geometry when filtering with a FilterRect
- Loading branch information
Showing
with
89 additions
and 26 deletions.
- +6 −9 src/providers/ogr/qgsogrfeatureiterator.cpp
- +3 −0 src/providers/spatialite/qgsspatialitefeatureiterator.cpp
- +1 −0 tests/src/python/CMakeLists.txt
- +23 −17 tests/src/python/providertestbase.py
- +54 −0 tests/src/python/test_provider_shapefile.py
- BIN tests/testdata/provider/shapefile.dbf
- +1 −0 tests/testdata/provider/shapefile.prj
- +1 −0 tests/testdata/provider/shapefile.qpj
- BIN tests/testdata/provider/shapefile.shp
- BIN tests/testdata/provider/shapefile.shx
@@ -0,0 +1,54 @@ | ||
# -*- coding: utf-8 -*- | ||
"""QGIS Unit tests for the postgres provider. | ||
.. 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__ = 'Matthias Kuhn' | ||
__date__ = '2015-04-23' | ||
__copyright__ = 'Copyright 2015, The QGIS Project' | ||
# This will get replaced with a git SHA1 when you do a git archive | ||
__revision__ = '$Format:%H$' | ||
|
||
import qgis | ||
import os | ||
|
||
from qgis.core import QgsVectorLayer, QgsFeatureRequest, QgsFeature, QgsProviderRegistry | ||
from PyQt4.QtCore import QSettings | ||
from utilities import (unitTestDataPath, | ||
getQgisTestApp, | ||
unittest, | ||
TestCase | ||
) | ||
from providertestbase import ProviderTestCase | ||
|
||
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp() | ||
TEST_DATA_DIR = unitTestDataPath() | ||
|
||
class TestPyQgsPostgresProvider(TestCase, ProviderTestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
"""Run before all tests""" | ||
# Create test layer | ||
cls.vl = QgsVectorLayer(u'{}/provider/shapefile.shp|layerid=0'.format(TEST_DATA_DIR), u'test', u'ogr' ) | ||
assert(cls.vl.isValid()) | ||
cls.provider = cls.vl.dataProvider() | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
"""Run after all tests""" | ||
|
||
def testUnique(self): | ||
""" | ||
Override parent method because OGR doesn't return NULL values in SELECT DISTINCT... | ||
This is only to make the tests pass, not to define this as expected behavior so if it is possible to remove this | ||
in the future even better. | ||
""" | ||
assert set(self.provider.uniqueValues(1)) == set([-200, 100, 200, 300, 400]) | ||
assert set([u'Apple', u'Honey', u'Orange', u'Pear']) == set(self.provider.uniqueValues(2)), 'Got {}'.format(set(self.provider.uniqueValues(2))) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Binary file not shown.
@@ -0,0 +1 @@ | ||
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]] |
@@ -0,0 +1 @@ | ||
GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]] |
Binary file not shown.
Binary file not shown.