Skip to content
Permalink
Browse files

Merge pull request #3003 from m-kuhn/py3next

Enable more tests for PyQt5/Python3
  • Loading branch information
m-kuhn committed Apr 15, 2016
2 parents 78725fe + 816c322 commit 242d27413d38cd227ab0b532cd7995a65dad42ec
@@ -25,10 +25,9 @@ PyQgsPalLabelingComposer
PyQgsPalLabelingPlacement
PyQgsPalLabelingServer
PyQgsPostgresProvider
PyQgsProject
PyQgsRangeWidgets
PyQgsRasterLayer
PyQgsRelation
PyQgsRelationEditWidget
PyQgsRulebasedRenderer
PyQgsServer
PyQgsServerAccessControl
@@ -38,14 +37,10 @@ PyQgsSipCoverage
PyQgsSpatialiteProvider
PyQgsSymbolExpressionVariables
PyQgsSymbolV2
PyQgsSyntacticSugar
PyQgsTabfileProvider
PyQgsVectorFileWriter
PyQgsVectorLayer
PyQgsVirtualLayerDefinition
PyQgsVirtualLayerProvider
PyQgsWFSProvider
PyQgsZonalStatistics
qgis_composereffectstest
qgis_composerlabeltest
qgis_composermapgridtest
@@ -20,8 +20,6 @@ CLANG_WARNINGS="-Wimplicit-fallthrough"
# Include this line for debug reasons
# -DCMAKE_BUILD_TYPE=RelWithDebInfo \
#
# Server fails at the moment on Qt5 because QFtp has been removed
# -DWITH_SERVER=ON \
cmake \
-DCMAKE_PREFIX_PATH=/home/travis/osgeo4travis \
-DWITH_STAGED_PLUGINS=ON \
@@ -59,7 +59,7 @@ MACRO(PY_2TO3 TARGET_NAME RESOURCE_PATHS)
POST_BUILD
COMMAND "${PYTHON_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/scripts/2to3" --no-diffs -w ${RESOURCE_PATHS}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
COMMENT "Porting to Python 3 and Qt5"
COMMENT "Porting ${RESOURCE_PATHS} to Python 3 and Qt5"
)
ENDMACRO(PY_2TO3)

@@ -11,10 +11,11 @@ FILE(WRITE ${CMAKE_BINARY_DIR}/stagecount 0)
# The target port-plugins acts as a container for all port-plugin-XXX targets
# Each port-plugin-XXX target will run scripts/2to3 on a plugin and migrate
# Python 3 and Qt 5 code.
ADD_CUSTOM_TARGET(port-plugins)
SET (PORT_PLUGINS FALSE CACHE BOOL "Determines whether python plugins in staged or installed locations should be migrated to Python 3 and Qt 5")
IF(PORT_PLUGINS)
ADD_CUSTOM_TARGET(port-plugins-on-build ALL DEPENDS port-plugins)
ADD_CUSTOM_TARGET(port-plugins ALL)
ELSE(PORT_PLUGINS)
ADD_CUSTOM_TARGET(port-plugins)
ENDIF(PORT_PLUGINS)

MACRO (PLUGIN_INSTALL plugin subdir )
@@ -223,7 +223,7 @@ def wrapper(*args, **kwargs):
unittest.expectedFailure = expectedFailure


def start_app():
def start_app(cleanup=True):
"""
Will start a QgsApplication and call all initialization code like
registering the providers and other infrastructure. It will not load
@@ -233,6 +233,11 @@ def start_app():
The initialization will only happen once, so it is safe to call this method repeatedly.
Parameters
----------
cleanup: Do cleanup on exit. Defaults to true.
Returns
-------
QgsApplication
@@ -258,14 +263,14 @@ def start_app():
QGISAPP = QgsApplication(argvb, myGuiFlag)

QGISAPP.initQgis()
s = QGISAPP.showSettings()
print(s)
print(QGISAPP.showSettings())

import atexit
if cleanup:
import atexit

@atexit.register
def exitQgis():
QGISAPP.exitQgis()
@atexit.register
def exitQgis():
QGISAPP.exitQgis()

return QGISAPP

@@ -0,0 +1 @@
from libfuturize.fixes.fix_unicode_keep_u import FixUnicodeKeepU
@@ -70,7 +70,7 @@ def testDateTimeTypes(self):
self.assertEqual(fields.at(fields.indexFromName(
'datetime_field')).type(), QVariant.DateTime)

f = vl.getFeatures(QgsFeatureRequest()).next()
f = next(vl.getFeatures(QgsFeatureRequest()))

date_idx = vl.fieldNameIndex('date_field')
assert isinstance(f.attributes()[date_idx], QDate)
@@ -79,7 +79,7 @@ def testDateTimeTypes(self):
self.assertEqual(fields.at(fields.indexFromName('time_field')).type(), QVariant.Time)
self.assertEqual(fields.at(fields.indexFromName('datetime_field')).type(), QVariant.DateTime)

f = vl.getFeatures(QgsFeatureRequest()).next()
f = next(vl.getFeatures(QgsFeatureRequest()))

date_idx = vl.fieldNameIndex('date_field')
self.assertTrue(isinstance(f.attributes()[date_idx], QDate))
@@ -15,6 +15,7 @@
import qgis # NOQA

import os
import sys
import shutil
import tempfile

@@ -31,15 +32,11 @@
print("You should install pyspatialite to run the tests")
raise ImportError

# Convenience instances in case you may need them
start_app()
# Pass no_exit=True: for some reason this crashes on exit on Travis MacOSX
start_app(sys.platform != 'darwin')
TEST_DATA_DIR = unitTestDataPath()


def die(error_message):
raise Exception(error_message)


class TestQgsSpatialiteProvider(unittest.TestCase, ProviderTestCase):

@classmethod
@@ -144,73 +141,69 @@ def partiallyCompiledFilters(self):
def test_SplitFeature(self):
"""Create spatialite database"""
layer = QgsVectorLayer("dbname=%s table=test_pg (geometry)" % self.dbname, "test_pg", "spatialite")
assert(layer.isValid())
assert(layer.hasGeometryType())
self.assertTrue(layer.isValid())
self.assertTrue(layer.hasGeometryType())
layer.startEditing()
layer.splitFeatures([QgsPoint(0.5, -0.5), QgsPoint(0.5, 1.5)], 0) == 0 or die("error in split")
layer.splitFeatures([QgsPoint(-0.5, 0.5), QgsPoint(1.5, 0.5)], 0) == 0 or die("error in split")
if not layer.commitChanges():
die("this commit should work")
layer.featureCount() == 4 or die("we should have 4 features after 2 split")
self.assertEqual(layer.splitFeatures([QgsPoint(0.5, -0.5), QgsPoint(0.5, 1.5)], 0), 0)
self.assertEqual(layer.splitFeatures([QgsPoint(-0.5, 0.5), QgsPoint(1.5, 0.5)], 0), 0)
self.assertTrue(layer.commitChanges())
self.assertEqual(layer.featureCount(), 4)

def xtest_SplitFeatureWithFailedCommit(self):
"""Create spatialite database"""
layer = QgsVectorLayer("dbname=%s table=test_pg_mk (geometry)" % self.dbname, "test_pg_mk", "spatialite")
assert(layer.isValid())
assert(layer.hasGeometryType())
self.assertTrue(layer.isValid())
self.assertTrue(layer.hasGeometryType())
layer.startEditing()
layer.splitFeatures([QgsPoint(0.5, -0.5), QgsPoint(0.5, 1.5)], 0) == 0 or die("error in split")
layer.splitFeatures([QgsPoint(-0.5, 0.5), QgsPoint(1.5, 0.5)], 0) == 0 or die("error in split")
if layer.commitChanges():
die("this commit should fail")
self.asserEqual(layer.splitFeatures([QgsPoint(0.5, -0.5), QgsPoint(0.5, 1.5)], 0), 0)
self.asserEqual(layer.splitFeatures([QgsPoint(-0.5, 0.5), QgsPoint(1.5, 0.5)], 0), 0)
self.assertFalse(layer.commitChanges())
layer.rollBack()
feat = QgsFeature()
it = layer.getFeatures()
it.nextFeature(feat)
feat = next(layer.getFeatures())
ref = [[(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]]
res = feat.geometry().asPolygon()
for ring1, ring2 in zip(ref, res):
for p1, p2 in zip(ring1, ring2):
for c1, c2 in zip(p1, p2):
c1 == c2 or die("polygon has been altered by failed edition")
self.asserEqual(c1, c2)

def test_queries(self):
"""Test loading of query-based layers"""

# a query with a geometry, but no unique id
# the id will be autoincremented
l = QgsVectorLayer("dbname=%s table='(select * from test_q)' (geometry)" % self.dbname, "test_pg_query1", "spatialite")
assert(l.isValid())
self.assertTrue(l.isValid())
# the id() is autoincremented
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
self.assertEqual(sum_id1, 3) # 1+2
self.assertEqual(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")
assert(l.isValid())
self.assertTrue(l.isValid())
sum_id1 = sum(f.id() for f in l.getFeatures())
sum_id2 = sum(f.attributes()[0] for f in l.getFeatures())
assert(sum_id1 == 32)
assert(sum_id2 == 32)
self.assertEqual(sum_id1, 32)
self.assertEqual(sum_id2, 32)

# a query, but no geometry
l = QgsVectorLayer("dbname=%s table='(select id,name from test_q)' key='id'" % self.dbname, "test_pg_query1", "spatialite")
assert(l.isValid())
self.assertTrue(l.isValid())
sum_id1 = sum(f.id() for f in l.getFeatures())
sum_id2 = sum(f.attributes()[0] for f in l.getFeatures())
assert(sum_id1 == 32)
assert(sum_id2 == 32)
self.assertEqual(sum_id1, 32)
self.assertEqual(sum_id2, 32)

def test_case(self):
"""Test case sensitivity issues"""
l = QgsVectorLayer("dbname=%s table='test_n' (geometry) key='id'" % self.dbname, "test_n1", "spatialite")
assert(l.isValid())
assert(l.dataProvider().fields().count() == 2)
self.assertTrue(l.isValid())
self.assertEqual(l.dataProvider().fields().count(), 2)
fields = [f.name() for f in l.dataProvider().fields()]
assert('Geometry' not in fields)
self.assertTrue('Geometry' not in fields)

def test_invalid_iterator(self):
""" Test invalid iterator """
@@ -40,7 +40,7 @@ def testDateTimeFormats(self):
self.assertEqual(fields.at(fields.indexFromName('time')).type(), QVariant.Time)
self.assertEqual(fields.at(fields.indexFromName('date_time')).type(), QVariant.DateTime)

f = vl.getFeatures(QgsFeatureRequest()).next()
f = next(vl.getFeatures(QgsFeatureRequest()))

date_idx = vl.fieldNameIndex('date')
assert isinstance(f.attributes()[date_idx], QDate)
@@ -15,7 +15,7 @@
import qgis # NOQA

import os
import SocketServer
import socketserver
import threading
import SimpleHTTPServer
from PyQt.QtCore import QRectF
@@ -40,7 +40,7 @@ def setUpClass(cls):
os.chdir(unitTestDataPath() + '')
handler = SimpleHTTPServer.SimpleHTTPRequestHandler

cls.httpd = SocketServer.TCPServer(('localhost', 0), handler)
cls.httpd = socketserver.TCPServer(('localhost', 0), handler)
cls.port = cls.httpd.server_address[1]

cls.httpd_thread = threading.Thread(target=cls.httpd.serve_forever)

0 comments on commit 242d274

Please sign in to comment.
You can’t perform that action at this time.