Skip to content

Commit 0aedbca

Browse files
committed
Merge branch 'master' of https://github.com/qgis/QGIS
2 parents e25fb2d + e2ff8ed commit 0aedbca

File tree

10 files changed

+136
-57
lines changed

10 files changed

+136
-57
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ before_script:
4747
- printf "[qgis_test]\nhost=localhost\ndbname=qgis_test\nuser=postgres" > ~/.pg_service.conf
4848
- psql -c 'CREATE DATABASE qgis_test;' -U postgres
4949
- psql -c 'CREATE EXTENSION postgis;' -U postgres -d qgis_test
50-
- psql -f $TRAVIS_BUILD_DIR/tests/testdata/postgres/testdata.sql -U postgres -d qgis_test
50+
- psql -f $TRAVIS_BUILD_DIR/tests/testdata/provider/testdata.sql -U postgres -d qgis_test
5151

52-
script: xvfb-run ctest -V -E 'PyQgsPalLabelingServer|qgis_wcsprovidertest' -S ../qgis-test-travis.ctest --output-on-failure
52+
script: xvfb-run ctest -V -E 'qgis_openstreetmaptest|PyQgsPalLabelingServer|qgis_wcsprovidertest' -S ../qgis-test-travis.ctest --output-on-failure
5353

python/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,14 @@ def __eq__(self, other):
5555
def __ne__(self, other):
5656
return not isinstance(other, QPyNullVariant) and other is not None
5757

58+
def __hash__(self):
59+
return 2178309
60+
5861
QPyNullVariant.__nonzero__ = MethodType(__nonzero__, None, QPyNullVariant)
5962
QPyNullVariant.__repr__ = MethodType(__repr__, None, QPyNullVariant)
60-
QPyNullVariant.__eq__= MethodType(__eq__, None, QPyNullVariant)
61-
QPyNullVariant.__ne__= MethodType(__ne__, None, QPyNullVariant)
63+
QPyNullVariant.__eq__ = MethodType(__eq__, None, QPyNullVariant)
64+
QPyNullVariant.__ne__ = MethodType(__ne__, None, QPyNullVariant)
65+
QPyNullVariant.__hash__ = MethodType(__hash__, None, QPyNullVariant)
6266

6367
# define a dummy QPyNullVariant instance NULL in qgis.core
6468
# this is mainly used to compare against

tests/src/python/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ ADD_PYTHON_TEST(PyQgsPalLabelingCanvas test_qgspallabeling_canvas.py)
3636
ADD_PYTHON_TEST(PyQgsPalLabelingComposer test_qgspallabeling_composer.py)
3737
ADD_PYTHON_TEST(PyQgsPalLabelingServer test_qgspallabeling_server.py)
3838
ADD_PYTHON_TEST(PyQgsVectorFileWriter test_qgsvectorfilewriter.py)
39-
ADD_PYTHON_TEST(PyQgsSpatialiteProvider test_qgsspatialiteprovider.py)
4039
ADD_PYTHON_TEST(PyQgsZonalStatistics test_qgszonalstatistics.py)
4140
ADD_PYTHON_TEST(PyQgsAppStartup test_qgsappstartup.py)
4241
ADD_PYTHON_TEST(PyQgsDistanceArea test_qgsdistancearea.py)
@@ -45,6 +44,8 @@ ADD_PYTHON_TEST(PyQgsNetworkContentFetcher test_qgsnetworkcontentfetcher.py)
4544
ADD_PYTHON_TEST(PyQgsEditWidgets test_qgseditwidgets.py)
4645
ADD_PYTHON_TEST(PyQgsRangeWidgets test_qgsrangewidgets.py)
4746
ADD_PYTHON_TEST(PyQgsPostgresProvider test_provider_postgres.py)
47+
ADD_PYTHON_TEST(PyQgsSpatialiteProvider test_provider_spatialite.py)
48+
ADD_PYTHON_TEST(PyQgsSpatialiteProviderOther test_qgsspatialiteprovider.py)
4849
IF (WITH_APIDOC)
4950
ADD_PYTHON_TEST(PyQgsDocCoverage test_qgsdoccoverage.py)
5051
ENDIF (WITH_APIDOC)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# -*- coding: utf-8 -*-
2+
"""QGIS Unit test utils for provider tests.
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__ = 'Matthias Kuhn'
10+
__date__ = '2015-04-27'
11+
__copyright__ = 'Copyright 2015, The QGIS Project'
12+
# This will get replaced with a git SHA1 when you do a git archive
13+
__revision__ = '$Format:%H$'
14+
15+
from qgis.core import QgsRectangle, QgsFeatureRequest, QgsGeometry, NULL
16+
from utilities import TestCase
17+
18+
class ProviderTestCase(object):
19+
20+
def runGetFeatureTests(self, provider):
21+
assert len( [f for f in provider.getFeatures()] ) == 5
22+
assert len( [f for f in provider.getFeatures( QgsFeatureRequest().setFilterExpression( 'name IS NOT NULL' ) )] ) == 4
23+
assert len( [f for f in provider.getFeatures( QgsFeatureRequest().setFilterExpression('name LIKE \'Apple\'' ) )] ) == 1
24+
assert len( [f for f in provider.getFeatures( QgsFeatureRequest().setFilterExpression('name ILIKE \'aPple\'' ) )] ) == 1
25+
assert len( [f for f in provider.getFeatures( QgsFeatureRequest().setFilterExpression('name ILIKE \'%pp%\'' ) )] ) == 1
26+
assert len( [f for f in provider.getFeatures( QgsFeatureRequest().setFilterExpression('cnt > 0' ) ) ] ) == 4
27+
assert len( [f for f in provider.getFeatures( QgsFeatureRequest().setFilterExpression('cnt < 0' ) ) ] ) == 1
28+
assert len( [f for f in provider.getFeatures( QgsFeatureRequest().setFilterExpression('cnt >= 100' ) ) ] ) == 4
29+
assert len( [f for f in provider.getFeatures( QgsFeatureRequest().setFilterExpression('cnt <= 100' ) ) ] ) == 2
30+
assert len( [f for f in provider.getFeatures( QgsFeatureRequest().setFilterExpression('pk IN (1, 2, 4, 8)' ) )] ) == 3
31+
32+
def testGetFeaturesUncompiled(self):
33+
try:
34+
self.disableCompiler()
35+
except AttributeError:
36+
pass
37+
self.runGetFeatureTests(self.provider)
38+
39+
def testGetFeaturesCompiled(self):
40+
try:
41+
self.enableCompiler()
42+
self.runGetFeatureTests(self.provider)
43+
except AttributeError:
44+
print 'Provider does not support compiling'
45+
46+
def testGetFeaturesFilterRectTests(self):
47+
extent = QgsRectangle(-70, 67, -60, 80)
48+
features = [ f['pk'] for f in self.provider.getFeatures( QgsFeatureRequest().setFilterRect( extent ) ) ]
49+
assert set(features) == set([2L, 4L]), 'Got {} instead'.format(features)
50+
51+
def testMinValue(self):
52+
assert self.provider.minimumValue(1) == -200
53+
assert self.provider.minimumValue(2) == 'Apple'
54+
55+
def testMaxValue(self):
56+
assert self.provider.maximumValue(1) == 400
57+
assert self.provider.maximumValue(2) == 'Pear'
58+
59+
def testExtent(self):
60+
reference = QgsGeometry.fromRect(QgsRectangle(-71.1230000000000047,66.3299999999999983,-65.3199999999999932,78.2999999999999972))
61+
provider_extent=QgsGeometry.fromRect(self.provider.extent())
62+
63+
assert QgsGeometry.compare( provider_extent.asPolygon(), reference.asPolygon(), 0.000001)
64+
65+
def testUnique(self):
66+
assert set(self.provider.uniqueValues(1)) == set([-200, 100, 200, 300, 400])
67+
assert set([u'Apple', u'Honey', u'Orange', u'Pear', NULL]) == set(self.provider.uniqueValues(2)), 'Got {}'.format(set(self.provider.uniqueValues(2)))
68+
69+
def testFeatureCount(self):
70+
assert self.provider.featureCount() == 5

tests/src/python/providertestutils.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

tests/src/python/test_provider_postgres.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,32 @@
1919
from PyQt4.QtCore import QSettings
2020
from utilities import (unitTestDataPath,
2121
getQgisTestApp,
22-
TestCase,
23-
unittest
22+
unittest,
23+
TestCase
2424
)
25-
from providertestutils import * # testGetFeaturesUncompiled
25+
from providertestbase import ProviderTestCase
2626

2727
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
2828
TEST_DATA_DIR = unitTestDataPath()
2929

30-
class TestPyQgsPostgresProvider(TestCase):
30+
class TestPyQgsPostgresProvider(TestCase, ProviderTestCase):
3131
@classmethod
3232
def setUpClass(cls):
3333
"""Run before all tests"""
34-
35-
# Create test database
34+
# Create test layer
3635
cls.vl = QgsVectorLayer( u'dbname=\'qgis_test\' host=localhost port=5432 user=\'postgres\' password=\'postgres\' sslmode=disable key=\'pk\' srid=4326 type=POINT table="qgis_test"."someData" (geom) sql=', 'test', 'postgres' )
37-
36+
assert(cls.vl.isValid())
37+
cls.provider = cls.vl.dataProvider()
3838

3939
@classmethod
4040
def tearDownClass(cls):
4141
"""Run after all tests"""
4242

43-
# Delete test database
44-
45-
def testGetFeaturesUncompiled(self):
46-
QSettings().setValue( "/qgis/postgres/compileExpressions", False )
47-
runGetFeatureTests( self.vl )
48-
49-
def testGetFeaturesCompiled(self):
50-
QSettings().setValue( "/qgis/postgres/compileExpressions", True )
51-
runGetFeatureTests( self.vl )
43+
def enableCompiler(self):
44+
QSettings().setValue(u'/qgis/postgres/compileExpressions', True)
5245

53-
def testGetFeaturesFilterRectTests(self):
54-
runGetFilterRectTests( self.vl )
46+
def disableCompiler(self):
47+
QSettings().setValue(u'/qgis/postgres/compileExpressions', False)
5548

5649
if __name__ == '__main__':
5750
unittest.main()
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# -*- coding: utf-8 -*-
2+
"""QGIS Unit tests for the postgres provider.
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__ = 'Matthias Kuhn'
10+
__date__ = '2015-04-23'
11+
__copyright__ = 'Copyright 2015, 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
16+
import os
17+
18+
from qgis.core import QgsVectorLayer, QgsFeatureRequest, QgsFeature, QgsProviderRegistry
19+
from PyQt4.QtCore import QSettings
20+
from utilities import (unitTestDataPath,
21+
getQgisTestApp,
22+
unittest,
23+
TestCase
24+
)
25+
from providertestbase import ProviderTestCase
26+
27+
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
28+
TEST_DATA_DIR = unitTestDataPath()
29+
30+
class TestPyQgsPostgresProvider(TestCase, ProviderTestCase):
31+
@classmethod
32+
def setUpClass(cls):
33+
"""Run before all tests"""
34+
# Create test layer
35+
cls.vl = QgsVectorLayer( 'dbname=\'{}/provider/spatialite.db\' table="somedata" (geometry) sql='.format(TEST_DATA_DIR), 'test', 'spatialite' )
36+
assert(cls.vl.isValid())
37+
cls.provider = cls.vl.dataProvider()
38+
39+
@classmethod
40+
def tearDownClass(cls):
41+
"""Run after all tests"""
42+
43+
if __name__ == '__main__':
44+
unittest.main()

tests/src/python/test_qgsdoccoverage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
# DON'T LOWER THIS THRESHOLD UNLESS MEMBERS HAVE BEEN REMOVED FROM THE API
3333
# (changes which raise this threshold are welcomed though!)
3434

35-
ACCEPTABLE_COVERAGE = 54.5365
35+
ACCEPTABLE_COVERAGE = 54.6134
3636

3737

3838
def elemIsDocumentableClass(elem):
4.76 MB
Binary file not shown.
File renamed without changes.

0 commit comments

Comments
 (0)