Skip to content

Commit

Permalink
switch tests to pyqt wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Mar 21, 2016
1 parent 719182f commit f413046
Show file tree
Hide file tree
Showing 76 changed files with 236 additions and 384 deletions.
2 changes: 1 addition & 1 deletion python/plugins/processing/tests/GdalAlgorithmsTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

__revision__ = ':%H$'

from . import AlgorithmsTestBase
import AlgorithmsTestBase

import nose2
import shutil
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/tests/QgisAlgorithmsTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

__revision__ = ':%H$'

from . import AlgorithmsTestBase
import AlgorithmsTestBase

import nose2
import shutil
Expand Down
2 changes: 1 addition & 1 deletion python/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import difflib
import functools

from PyQt4.QtCore import QVariant
from PyQt.QtCore import QVariant
from qgis.core import QgsApplication, QgsFeatureRequest, QgsVectorLayer
from nose2.compat import unittest

Expand Down
4 changes: 2 additions & 2 deletions python/testing/mocked.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
from qgis.gui import QgisInterface, QgsMapCanvas
from qgis.core import QgsApplication

from PyQt4.QtGui import QMainWindow
from PyQt4.QtCore import QSize
from PyQt.QtWidgets import QMainWindow
from PyQt.QtCore import QSize

from qgis.testing import start_app

Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/qgis_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
'Copyright (c) 2011 German Carrillo, '
'geotux_tuxman@linuxmail.org')

import qgis # switch sip api
import qgis # NOQA
from PyQt.QtCore import QObject
from qgis.core import QgsMapLayerRegistry

Expand Down
6 changes: 3 additions & 3 deletions tests/src/python/qgscompositionchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
***************************************************************************/
'''

import qgis # switch sip api
import qgis # NOQA

from PyQt4.QtCore import QSize, QDir, QFileInfo
from PyQt4.QtGui import QImage, QPainter
from PyQt.QtCore import QSize, QDir, QFileInfo
from PyQt.QtGui import QImage, QPainter
from qgis.core import QgsMultiRenderChecker, QgsComposition


Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_provider_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
)

from providertestbase import ProviderTestCase
from PyQt4.QtCore import QVariant
from PyQt.QtCore import QVariant

start_app()
TEST_DATA_DIR = unitTestDataPath()
Expand Down
20 changes: 4 additions & 16 deletions tests/src/python/test_provider_mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,16 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import qgis # switch sip api
import qgis # NOQA

import os

from qgis.core import (
QgsVectorLayer,
QgsFeatureRequest,
)
from qgis.core import QgsVectorLayer, QgsFeatureRequest

from PyQt4.QtCore import (
QSettings,
QDate,
QTime,
QDateTime,
QVariant
)
from PyQt.QtCore import QSettings, QDate, QTime, QDateTime, QVariant

from utilities import unitTestDataPath
from qgis.testing import (
start_app,
unittest
)
from qgis.testing import start_app, unittest
from providertestbase import ProviderTestCase

start_app()
Expand Down
8 changes: 3 additions & 5 deletions tests/src/python/test_provider_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import qgis # switch sip api
import qgis # NOQA

import os
from qgis.core import NULL

from qgis.core import QgsVectorLayer, QgsFeatureRequest
from PyQt4.QtCore import QSettings, QDate, QTime, QDateTime, QVariant
from qgis.testing import (start_app,
unittest
)
from PyQt.QtCore import QSettings, QDate, QTime, QDateTime, QVariant
from qgis.testing import start_app, unittest
from utilities import unitTestDataPath
from providertestbase import ProviderTestCase

Expand Down
8 changes: 3 additions & 5 deletions tests/src/python/test_provider_shapefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import qgis # switch sip api
import qgis # NOQA

import os
import tempfile
import shutil
import glob

from qgis.core import QgsVectorLayer, QgsFeatureRequest
from PyQt4.QtCore import QSettings
from qgis.testing import (start_app,
unittest
)
from PyQt.QtCore import QSettings
from qgis.testing import start_app, unittest
from utilities import unitTestDataPath
from providertestbase import ProviderTestCase

Expand Down
12 changes: 5 additions & 7 deletions tests/src/python/test_provider_spatialite.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import qgis # switch sip api
import qgis # NOQA

import os
import tempfile

from qgis.core import QgsVectorLayer, QgsPoint, QgsFeature

from qgis.testing import (start_app,
unittest
)
from qgis.testing import start_app, unittest
from utilities import unitTestDataPath
from providertestbase import ProviderTestCase
from PyQt4.QtCore import QSettings
from PyQt.QtCore import QSettings

try:
from pyspatialite import dbapi2 as sqlite3
Expand Down Expand Up @@ -176,8 +174,8 @@ def test_queries(self):
sum_id1 = sum(f.id() for f in l.getFeatures())
# the attribute 'id' works
sum_id2 = sum(f.attributes()[0] for f in l.getFeatures())
assert(sum_id1 == 3) # 1+2
assert(sum_id2 == 32) # 11 + 21
assert(sum_id1 == 3) # 1+2
assert(sum_id2 == 32) # 11 + 21

# and now with an id declared
l = QgsVectorLayer("dbname=%s table='(select * from test_q)' (geometry) key='id'" % self.dbname, "test_pg_query1", "spatialite")
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_provider_tabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import os

from qgis.core import QgsVectorLayer, QgsFeatureRequest
from PyQt4.QtCore import QDate, QTime, QDateTime, QVariant
from PyQt.QtCore import QDate, QTime, QDateTime, QVariant
from qgis.testing import (
start_app,
unittest
Expand Down
30 changes: 14 additions & 16 deletions tests/src/python/test_provider_virtual.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import qgis # switch sip api
import qgis # NOQA
import os

from qgis.core import (QgsVectorLayer,
Expand All @@ -26,13 +26,11 @@
QgsProject
)

from qgis.testing import (start_app,
unittest
)
from qgis.testing import start_app, unittest
from utilities import unitTestDataPath

from providertestbase import ProviderTestCase
from PyQt4.QtCore import QUrl, QVariant
from PyQt.QtCore import QUrl, QVariant

try:
from pyspatialite import dbapi2 as sqlite3
Expand Down Expand Up @@ -217,7 +215,7 @@ def test_Query(self):
query = QUrl.toPercentEncoding("SELECT * FROM ww")
l2 = QgsVectorLayer("?layer_ref=%s:ww&query=%s&uid=ObJeCtId&nogeometry" % (l1.id(), query), "vtab", "virtual", False)
self.assertEqual(l2.isValid(), True)
self.assertEqual(l2.dataProvider().geometryType(), 100) # NoGeometry
self.assertEqual(l2.dataProvider().geometryType(), 100) # NoGeometry
ref_sum2 = sum(f.attributes()[0] for f in l2.getFeatures())
ref_sum3 = sum(f.id() for f in l2.getFeatures())
self.assertEqual(ref_sum, ref_sum2)
Expand Down Expand Up @@ -248,7 +246,7 @@ def test_QueryTableName(self):
query = str(QUrl.toPercentEncoding("SELECT * FROM vt"))
l2 = QgsVectorLayer("?layer_ref=%s:vt&query=%s&uid=ObJeCtId&nogeometry" % (l1.id(), query), "vtab", "virtual", False)
self.assertEqual(l2.isValid(), True)
self.assertEqual(l2.dataProvider().geometryType(), 100) # NoGeometry
self.assertEqual(l2.dataProvider().geometryType(), 100) # NoGeometry

QgsMapLayerRegistry.instance().removeMapLayer(l1.id())

Expand Down Expand Up @@ -334,7 +332,7 @@ def test_no_geometry(self):
df.setGeometryWkbType(QgsWKBTypes.NoGeometry)
l2 = QgsVectorLayer(df.toString(), "vtab2", "virtual", False)
self.assertEqual(l2.isValid(), True)
self.assertEqual(l2.dataProvider().geometryType(), 100) # NoGeometry
self.assertEqual(l2.dataProvider().geometryType(), 100) # NoGeometry

def test_reopen(self):
source = QUrl.toPercentEncoding(os.path.join(self.testDataDir, "france_parts.shp"))
Expand Down Expand Up @@ -414,7 +412,7 @@ def test_refLayers(self):
l2 = QgsVectorLayer("?layer_ref=%s:t%d&query=%s&uid=id" % (l1.id(), i, q), "vtab", "virtual", False)
QgsMapLayerRegistry.instance().addMapLayer(l2)
self.assertEqual(l2.isValid(), True)
s = sum([f.id() for f in l2.dataProvider().getFeatures()])
s = sum([f.id() for f in l2.dataProvider().getFeatures()]) # NOQA
self.assertEqual(sum([f.id() for f in l2.getFeatures()]), 21)
QgsMapLayerRegistry.instance().removeMapLayer(l2.id())

Expand Down Expand Up @@ -532,7 +530,7 @@ def test_sql_field_types(self):
self.assertEqual(l4.dataProvider().fields().at(1).type(), QVariant.String)
self.assertEqual(l4.dataProvider().fields().at(2).name(), "t4")
self.assertEqual(l4.dataProvider().fields().at(2).type(), QVariant.Int)
self.assertEqual(l4.dataProvider().geometryType(), 4) # multipoint
self.assertEqual(l4.dataProvider().geometryType(), 4) # multipoint

# test value types (!= from declared column types)
for f in l4.getFeatures():
Expand All @@ -544,7 +542,7 @@ def test_sql_field_types(self):
query = QUrl.toPercentEncoding("SELECT 1 as id /*:int*/, geomfromtext('point(0 0)',4326) as geometry/*:point:4326*/")
l4 = QgsVectorLayer("?query=%s&geometry=geometry" % query, "tt", "virtual", False)
self.assertEqual(l4.isValid(), True)
self.assertEqual(l4.dataProvider().geometryType(), 1) # point
self.assertEqual(l4.dataProvider().geometryType(), 1) # point

# with type annotations and url options (2)
query = QUrl.toPercentEncoding("SELECT 1 as id /*:int*/, 3.14 as f, geomfromtext('point(0 0)',4326) as geometry/*:point:4326*/")
Expand All @@ -554,7 +552,7 @@ def test_sql_field_types(self):
self.assertEqual(l4.dataProvider().fields().at(0).type(), QVariant.String)
self.assertEqual(l4.dataProvider().fields().at(1).name(), "f")
self.assertEqual(l4.dataProvider().fields().at(1).type(), QVariant.Double)
self.assertEqual(l4.dataProvider().geometryType(), 1) # point
self.assertEqual(l4.dataProvider().geometryType(), 1) # point

def test_sql3b(self):
query = QUrl.toPercentEncoding("SELECT GeomFromText('POINT(0 0)') as geom")
Expand Down Expand Up @@ -609,7 +607,7 @@ def test_encoding(self):
l = QgsVectorLayer("?layer=ogr:%s:fp:UTF-8" % source, "vtab", "virtual", False)
self.assertEqual(l.isValid(), True)
for f in l.getFeatures():
self.assertEqual(f.attributes()[1], u"accents \ufffd\ufffd\ufffd") # invalid unicode characters
self.assertEqual(f.attributes()[1], u"accents \ufffd\ufffd\ufffd") # invalid unicode characters

def test_rowid(self):
source = QUrl.toPercentEncoding(os.path.join(self.testDataDir, "france_parts.shp"))
Expand All @@ -626,21 +624,21 @@ def test_geometry_conversion(self):
self.assertEqual(l.isValid(), True)
for f in l.getFeatures():
self.assertEqual(f.geometry().exportToWkt().lower().startswith("multipoint"), True)
self.assertEqual("),(" in f.geometry().exportToWkt(), True) # has two points
self.assertEqual("),(" in f.geometry().exportToWkt(), True) # has two points

query = QUrl.toPercentEncoding("select geomfromtext('multipolygon(((0 0,1 0,1 1,0 1,0 0)),((0 1,1 1,1 2,0 2,0 1)))') as geom")
l = QgsVectorLayer("?query=%s&geometry=geom:multipolygon:0" % query, "tt", "virtual", False)
self.assertEqual(l.isValid(), True)
for f in l.getFeatures():
self.assertEqual(f.geometry().exportToWkt().lower().startswith("multipolygon"), True)
self.assertEqual(")),((" in f.geometry().exportToWkt(), True) # has two polygons
self.assertEqual(")),((" in f.geometry().exportToWkt(), True) # has two polygons

query = QUrl.toPercentEncoding("select geomfromtext('multilinestring((0 0,1 0,1 1,0 1,0 0),(0 1,1 1,1 2,0 2,0 1))') as geom")
l = QgsVectorLayer("?query=%s&geometry=geom:multilinestring:0" % query, "tt", "virtual", False)
self.assertEqual(l.isValid(), True)
for f in l.getFeatures():
self.assertEqual(f.geometry().exportToWkt().lower().startswith("multilinestring"), True)
self.assertEqual("),(" in f.geometry().exportToWkt(), True) # has two linestrings
self.assertEqual("),(" in f.geometry().exportToWkt(), True) # has two linestrings

def test_queryOnMemoryLayer(self):
ml = QgsVectorLayer("Point?srid=EPSG:4326&field=a:int", "mem", "memory")
Expand Down
8 changes: 3 additions & 5 deletions tests/src/python/test_qgsanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
***************************************************************************/
'''

import qgis # switch sip api
import qgis # NOQA

from qgis.testing import (start_app,
unittest
)
from qgis.testing import start_app, unittest
from utilities import unitTestDataPath

start_app()
Expand All @@ -41,7 +39,7 @@ def testSubstitutionMap(self):
"""Test that we can import zonal statistics was failing as of d5f6543
"""
try:
from qgis.analysis import QgsZonalStatistics
from qgis.analysis import QgsZonalStatistics # NOQA
except ImportError:
self.fail('Failed to import zonal statistics python module')

Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_qgsapplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import qgis # switch sip api
import qgis # NOQA
from qgis.testing import start_app, unittest


Expand Down
4 changes: 2 additions & 2 deletions tests/src/python/test_qgsatlascomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* *
***************************************************************************/
'''
import qgis # switch sip api
import qgis # NOQA
import os
import glob
import shutil
import tempfile
from qgis.testing import start_app, unittest
from utilities import unitTestDataPath
from PyQt4.QtCore import QFileInfo, QRectF, qWarning
from PyQt.QtCore import QFileInfo, QRectF, qWarning
from qgis.core import QGis, QgsVectorLayer, QgsMapLayerRegistry, QgsMapSettings, QgsCoordinateReferenceSystem, \
QgsComposition, QgsFillSymbolV2, QgsSingleSymbolRendererV2, QgsComposerLabel, QgsComposerMap, QgsFontUtils, \
QgsRectangle, QgsComposerLegend, QgsFeature, QgsGeometry, QgsPoint, QgsRendererCategoryV2, QgsCategorizedSymbolRendererV2, QgsMarkerSymbolV2
Expand Down
7 changes: 4 additions & 3 deletions tests/src/python/test_qgsauthsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
from qgis.gui import QgsAuthEditorWidgets


from PyQt4.QtCore import QFileInfo, qDebug, QSsl, QSslError, QSslSocket
from PyQt4.QtGui import QDialog, QVBoxLayout, QDialogButtonBox
from PyQt4.QtTest import QTest
from PyQt.QtCore import QFileInfo, qDebug
from PyQt.QtWidgets import QDialog, QVBoxLayout, QDialogButtonBox
from PyQt.QtTest import QTest
from PyQt.QtNetwork import QSsl, QSslError, QSslSocket

from qgis.testing import (
start_app,
Expand Down
10 changes: 4 additions & 6 deletions tests/src/python/test_qgsblendmodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import qgis # switch sip api
import qgis # NOQA

import os

from PyQt4.QtCore import QSize
from PyQt4.QtGui import QPainter, QColor
from PyQt.QtCore import QSize
from PyQt.QtGui import QPainter, QColor

from qgis.core import (QgsVectorLayer,
QgsVectorSimplifyMethod,
Expand All @@ -39,9 +39,7 @@
QgsRectangle
)

from qgis.testing import (start_app,
unittest
)
from qgis.testing import start_app, unittest

from qgis.testing.mocked import get_iface

Expand Down
Loading

0 comments on commit f413046

Please sign in to comment.