Skip to content
Permalink
Browse files
Permantly convert python tests to python 3
  • Loading branch information
nyalldawson committed Sep 20, 2016
1 parent 03923eb commit d49b6560553d4c741ddec218fb0aeb9453818135
Showing with 1,675 additions and 1,665 deletions.
  1. +1 −1 tests/src/python/offlineditingtestbase.py
  2. +4 −4 tests/src/python/providertestbase.py
  3. +15 −11 tests/src/python/qgis_local_server.py
  4. +3 −3 tests/src/python/qgis_wrapped_server.py
  5. +1 −1 tests/src/python/test_offline_editing_wfs.py
  6. +4 −4 tests/src/python/test_provider_db2.py
  7. +8 −8 tests/src/python/test_provider_memory.py
  8. +3 −3 tests/src/python/test_provider_mssql.py
  9. +8 −8 tests/src/python/test_provider_ogr.py
  10. +3 −3 tests/src/python/test_provider_ogr_gpkg.py
  11. +1 −1 tests/src/python/test_provider_ogr_sqlite.py
  12. +3 −3 tests/src/python/test_provider_oracle.py
  13. +8 −8 tests/src/python/test_provider_postgres.py
  14. +33 −33 tests/src/python/test_provider_shapefile.py
  15. +3 −3 tests/src/python/test_provider_spatialite.py
  16. +6 −6 tests/src/python/test_provider_tabfile.py
  17. +14 −14 tests/src/python/test_provider_virtual.py
  18. +37 −37 tests/src/python/test_provider_wfs.py
  19. +2 −2 tests/src/python/test_qgis_local_server.py
  20. +4 −4 tests/src/python/test_qgsappstartup.py
  21. +4 −4 tests/src/python/test_qgsattributeformeditorwidget.py
  22. +6 −6 tests/src/python/test_qgsattributetablemodel.py
  23. +1 −1 tests/src/python/test_qgsauthsystem.py
  24. +2 −2 tests/src/python/test_qgscomposerpicture.py
  25. +33 −32 tests/src/python/test_qgsdelimitedtextprovider.py
  26. +1,051 −1,051 tests/src/python/test_qgsdelimitedtextprovider_wanted.py
  27. +37 −37 tests/src/python/test_qgsdistancearea.py
  28. +13 −13 tests/src/python/test_qgsdoccoverage.py
  29. +3 −3 tests/src/python/test_qgsexpression.py
  30. +5 −5 tests/src/python/test_qgsfeatureiterator.py
  31. +2 −2 tests/src/python/test_qgsgeometry.py
  32. +1 −1 tests/src/python/test_qgsmaplayerregistry.py
  33. +4 −4 tests/src/python/test_qgsoptional.py
  34. +4 −3 tests/src/python/test_qgspallabeling_base.py
  35. +1 −1 tests/src/python/test_qgspallabeling_composer.py
  36. +6 −6 tests/src/python/test_qgspallabeling_placement.py
  37. +2 −2 tests/src/python/test_qgspallabeling_server.py
  38. +7 −7 tests/src/python/test_qgsproject.py
  39. +1 −1 tests/src/python/test_qgsrectangle.py
  40. +2 −2 tests/src/python/test_qgsrelation.py
  41. +1 −1 tests/src/python/test_qgsrelationeditwidget.py
  42. +1 −1 tests/src/python/test_qgsrelationmanager.py
  43. +98 −98 tests/src/python/test_qgssearchwidgetwrapper.py
  44. +21 −19 tests/src/python/test_qgsserver.py
  45. +106 −104 tests/src/python/test_qgsserver_accesscontrol.py
  46. +1 −1 tests/src/python/test_qgsserver_wfst.py
  47. +6 −6 tests/src/python/test_qgssipcoverage.py
  48. +1 −1 tests/src/python/test_qgssymbol.py
  49. +16 −16 tests/src/python/test_qgssymbollayer.py
  50. +16 −16 tests/src/python/test_qgssymbollayer_createsld.py
  51. +15 −15 tests/src/python/test_qgstabwidget.py
  52. +16 −16 tests/src/python/test_qgsunittypes.py
  53. +10 −10 tests/src/python/test_qgsvectorfilewriter.py
  54. +9 −9 tests/src/python/test_qgsvectorlayer.py
  55. +3 −3 tests/src/python/test_qgsvirtuallayerdefinition.py
  56. +7 −7 tests/src/python/test_versioncompare.py
  57. +2 −2 tests/src/python/utilities.py
@@ -18,7 +18,7 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
from __future__ import print_function

from builtins import str
from builtins import object
__author__ = 'Alessandro Pasotti'
@@ -6,7 +6,7 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
from __future__ import print_function

from builtins import str
from builtins import object
__author__ = 'Matthias Kuhn'
@@ -71,7 +71,7 @@ def testGetFeatures(self):
3: None,
4: 'Point(-65.32 78.3)',
5: 'Point(-71.123 78.23)'}
for pk, geom in expected_geometries.items():
for pk, geom in list(expected_geometries.items()):
if geom:
assert compareWkt(geom, geometries[pk]), "Geometry {} mismatch Expected:\n{}\nGot:\n{}\n".format(pk, geom, geometries[pk].exportToWkt())
else:
@@ -534,7 +534,7 @@ def testExtent(self):

def testUnique(self):
self.assertEqual(set(self.provider.uniqueValues(1)), set([-200, 100, 200, 300, 400]))
assert set([u'Apple', u'Honey', u'Orange', u'Pear', NULL]) == set(self.provider.uniqueValues(2)), 'Got {}'.format(set(self.provider.uniqueValues(2)))
assert set(['Apple', 'Honey', 'Orange', 'Pear', NULL]) == set(self.provider.uniqueValues(2)), 'Got {}'.format(set(self.provider.uniqueValues(2)))

subset = self.getSubsetString2()
self.provider.setSubsetString(subset)
@@ -574,7 +574,7 @@ def testGetFeaturesSubsetAttributes(self):
'cnt': set([-200, 300, 100, 200, 400]),
'name': set(['Pear', 'Orange', 'Apple', 'Honey', NULL]),
'name2': set(['NuLl', 'PEaR', 'oranGe', 'Apple', 'Honey'])}
for field, expected in tests.items():
for field, expected in list(tests.items()):
request = QgsFeatureRequest().setSubsetOfAttributes([field], self.provider.fields())
result = set([f[field] for f in self.provider.getFeatures(request)])
all_valid = (all(f.isValid() for f in self.provider.getFeatures(request)))
@@ -19,8 +19,12 @@
import platform
import subprocess
import time
import urllib
import urllib2
import urllib.request
import urllib.parse
import urllib.error
import urllib.request
import urllib.error
import urllib.parse
import tempfile

from utilities import (
@@ -420,7 +424,7 @@ def get_capabilities(self, params, browser=False):

url = self._fcgi_url + '?' + self.process_params(params)

res = urllib.urlopen(url)
res = urllib.request.urlopen(url)
xml = res.read()
if browser:
tmp_name = getTempfilePath('html')
@@ -483,8 +487,8 @@ def get_map(self, params, browser=False):
while time.time() - start_time < 20:
resp = None
try:
tmp_png = urllib2.urlopen(url)
except urllib2.HTTPError as resp:
tmp_png = urllib.request.urlopen(url)
except urllib.error.HTTPError as resp:
if resp.code == 503 or resp.code == 500:
time.sleep(1)
else:
@@ -493,15 +497,15 @@ def get_map(self, params, browser=False):
'Cound not connect to process: ' + str(resp.code),
resp.message
)
except urllib2.URLError as resp:
except urllib.error.URLError as resp:
raise ServerProcessError(
'Web/FCGI Process Request URLError',
'Cound not connect to process',
resp.reason
)
else:
delta = time.time() - start_time
print('Seconds elapsed for server GetMap: ' + str(delta))
print(('Seconds elapsed for server GetMap: ' + str(delta)))
break

if resp is not None:
@@ -532,11 +536,11 @@ def process_params(self, params):
# convert all convenience objects to compatible strings
self._convert_instances(params)
# encode params
return urllib.urlencode(params, True)
return urllib.parse.urlencode(params, True)

@staticmethod
def _params_to_upper(params):
return dict((k.upper(), v) for k, v in params.items())
return dict((k.upper(), v) for k, v in list(params.items()))

@staticmethod
def _convert_instances(params):
@@ -719,10 +723,10 @@ def tearDown(self):
while time.time() - start_time < 30:
time.sleep(1)
try:
res = urllib2.urlopen(srv.web_url())
res = urllib.request.urlopen(srv.web_url())
if res.getcode() == 200:
break
except urllib2.URLError:
except urllib.error.URLError:
pass
msg = 'Web server basic access to root index.html failed'
# print repr(res)
@@ -10,7 +10,7 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
from __future__ import print_function

from future import standard_library
standard_library.install_aliases()

@@ -38,7 +38,7 @@ class Handler(BaseHTTPRequestHandler):

def do_GET(self):
# CGI vars:
for k, v in self.headers.items():
for k, v in list(self.headers.items()):
qgs_server.putenv('HTTP_%s' % k.replace(' ', '-').replace('-', '_').replace(' ', '-').upper(), v)
qgs_server.putenv('SERVER_PORT', str(self.server.server_port))
qgs_server.putenv('SERVER_NAME', self.server.server_name)
@@ -50,7 +50,7 @@ def do_GET(self):
self.send_response(int(headers_dict['Status'].split(' ')[0]))
except:
self.send_response(200)
for k, v in headers_dict.items():
for k, v in list(headers_dict.items()):
self.send_header(k, v)
self.end_headers()
self.wfile.write(body)
@@ -128,7 +128,7 @@ def _getOnlineLayer(cls, type_name, layer_name=None):
#'sql': '',
}
cls.counter += 1
uri = ' '.join([("%s='%s'" % (k, v)) for k, v in parms.items()])
uri = ' '.join([("%s='%s'" % (k, v)) for k, v in list(parms.items())])
wfs_layer = QgsVectorLayer(uri, layer_name, 'WFS')
assert wfs_layer.isValid()
return wfs_layer
@@ -48,7 +48,7 @@ class TestPyQgsDb2Provider(unittest.TestCase, ProviderTestCase):
@classmethod
def setUpClass(cls):
"""Run before all tests"""
cls.dbconn = u"dbname='ostest' driver='IBM DB2 ODBC DRIVER' host=dadler.dynalias.org port=50000 user='osuser' password='osuserpw'"
cls.dbconn = "dbname='ostest' driver='IBM DB2 ODBC DRIVER' host=dadler.dynalias.org port=50000 user='osuser' password='osuserpw'"
if 'QGIS_DB2_DB' in os.environ:
cls.dbconn = os.environ['QGIS_DB2TEST_DB']
# Create test layer
@@ -65,17 +65,17 @@ def tearDownClass(cls):
"""Run after all tests"""

def setUp(self):
print ("starting " + self._testMethodName)
print(("starting " + self._testMethodName))

def getSubsetString(self):
"""Individual providers may need to override this depending on their subset string formats"""
return 'cnt > 100 and cnt < 410'

def enableCompiler(self):
QSettings().setValue(u'/qgis/compileExpressions', True)
QSettings().setValue('/qgis/compileExpressions', True)

def disableCompiler(self):
QSettings().setValue(u'/qgis/compileExpressions', False)
QSettings().setValue('/qgis/compileExpressions', False)

if __name__ == '__main__':
unittest.main()
@@ -49,8 +49,8 @@ class TestPyQgsMemoryProvider(unittest.TestCase, ProviderTestCase):
def setUpClass(cls):
"""Run before all tests"""
# Create test layer
cls.vl = QgsVectorLayer(u'Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&key=pk',
u'test', u'memory')
cls.vl = QgsVectorLayer('Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&key=pk',
'test', 'memory')
assert (cls.vl.isValid())
cls.provider = cls.vl.dataProvider()

@@ -76,8 +76,8 @@ def setUpClass(cls):
cls.provider.addFeatures([f1, f2, f3, f4, f5])

# poly layer
cls.poly_vl = QgsVectorLayer(u'Polygon?crs=epsg:4326&field=pk:integer&key=pk',
u'test', u'memory')
cls.poly_vl = QgsVectorLayer('Polygon?crs=epsg:4326&field=pk:integer&key=pk',
'test', 'memory')
assert (cls.poly_vl.isValid())
cls.poly_provider = cls.poly_vl.dataProvider()

@@ -310,8 +310,8 @@ class TestPyQgsMemoryProviderIndexed(unittest.TestCase, ProviderTestCase):
def setUpClass(cls):
"""Run before all tests"""
# Create test layer
cls.vl = QgsVectorLayer(u'Point?crs=epsg:4326&index=yes&field=pk:integer&field=cnt:int8&field=name:string(0)&field=name2:string(0)&field=num_char:string&key=pk',
u'test', u'memory')
cls.vl = QgsVectorLayer('Point?crs=epsg:4326&index=yes&field=pk:integer&field=cnt:int8&field=name:string(0)&field=name2:string(0)&field=num_char:string&key=pk',
'test', 'memory')
assert (cls.vl.isValid())
cls.provider = cls.vl.dataProvider()

@@ -337,8 +337,8 @@ def setUpClass(cls):
cls.provider.addFeatures([f1, f2, f3, f4, f5])

# poly layer
cls.poly_vl = QgsVectorLayer(u'Polygon?crs=epsg:4326&index=yes&field=pk:integer&key=pk',
u'test', u'memory')
cls.poly_vl = QgsVectorLayer('Polygon?crs=epsg:4326&index=yes&field=pk:integer&key=pk',
'test', 'memory')
assert (cls.poly_vl.isValid())
cls.poly_provider = cls.poly_vl.dataProvider()

@@ -33,7 +33,7 @@ class TestPyQgsMssqlProvider(unittest.TestCase, ProviderTestCase):
@classmethod
def setUpClass(cls):
"""Run before all tests"""
cls.dbconn = u"dbname='gis' host=localhost\sqlexpress"
cls.dbconn = "dbname='gis' host=localhost\sqlexpress"
if 'QGIS_MSSQLTEST_DB' in os.environ:
cls.dbconn = os.environ['QGIS_MSSQLTEST_DB']
# Create test layers
@@ -51,10 +51,10 @@ def tearDownClass(cls):
"""Run after all tests"""

def enableCompiler(self):
QSettings().setValue(u'/qgis/compileExpressions', True)
QSettings().setValue('/qgis/compileExpressions', True)

def disableCompiler(self):
QSettings().setValue(u'/qgis/compileExpressions', False)
QSettings().setValue('/qgis/compileExpressions', False)

# HERE GO THE PROVIDER SPECIFIC TESTS
def testDateTimeTypes(self):
@@ -72,7 +72,7 @@ def tearDownClass(cls):

def testUpdateMode(self):

vl = QgsVectorLayer(u'{}|layerid=0'.format(self.datasource), u'test', u'ogr')
vl = QgsVectorLayer('{}|layerid=0'.format(self.datasource), 'test', 'ogr')
self.assertTrue(vl.isValid())
caps = vl.dataProvider().capabilities()
self.assertTrue(caps & QgsVectorDataProvider.AddFeatures)
@@ -95,7 +95,7 @@ def testGeometryTypeKnownAtSecondFeature(self):
f.write('1,\n')
f.write('2,POINT(2 49)\n')

vl = QgsVectorLayer(u'{}|layerid=0'.format(datasource), u'test', u'ogr')
vl = QgsVectorLayer('{}|layerid=0'.format(datasource), 'test', 'ogr')
self.assertTrue(vl.isValid())
self.assertEqual(vl.wkbType(), QgsWkbTypes.Point)

@@ -110,7 +110,7 @@ def testMixOfPolygonCurvePolygon(self):
f.write('3,"MULTIPOLYGON(((0 0,0 1,1 1,0 0)))"\n')
f.write('4,"MULTISURFACE(((0 0,0 1,1 1,0 0)))"\n')

vl = QgsVectorLayer(u'{}|layerid=0'.format(datasource), u'test', u'ogr')
vl = QgsVectorLayer('{}|layerid=0'.format(datasource), 'test', 'ogr')
self.assertTrue(vl.isValid())
self.assertEqual(len(vl.dataProvider().subLayers()), 1)
self.assertEqual(vl.dataProvider().subLayers()[0], '0:testMixOfPolygonCurvePolygon:4:CurvePolygon')
@@ -127,22 +127,22 @@ def testMixOfLineStringCompoundCurve(self):
f.write('4,"MULTICURVE((0 0,0 1))"\n')
f.write('5,"CIRCULARSTRING(0 0,1 1,2 0)"\n')

vl = QgsVectorLayer(u'{}|layerid=0'.format(datasource), u'test', u'ogr')
vl = QgsVectorLayer('{}|layerid=0'.format(datasource), 'test', 'ogr')
self.assertTrue(vl.isValid())
self.assertEqual(len(vl.dataProvider().subLayers()), 1)
self.assertEqual(vl.dataProvider().subLayers()[0], '0:testMixOfLineStringCompoundCurve:5:CompoundCurve')

def testGpxElevation(self):
# GPX without elevation data
datasource = os.path.join(TEST_DATA_DIR, 'noelev.gpx')
vl = QgsVectorLayer(u'{}|layername=routes'.format(datasource), u'test', u'ogr')
vl = QgsVectorLayer('{}|layername=routes'.format(datasource), 'test', 'ogr')
self.assertTrue(vl.isValid())
f = next(vl.getFeatures())
self.assertEqual(f.geometry().geometry().wkbType(), QgsWkbTypes.LineString)

# GPX with elevation data
datasource = os.path.join(TEST_DATA_DIR, 'elev.gpx')
vl = QgsVectorLayer(u'{}|layername=routes'.format(datasource), u'test', u'ogr')
vl = QgsVectorLayer('{}|layername=routes'.format(datasource), 'test', 'ogr')
self.assertTrue(vl.isValid())
f = next(vl.getFeatures())
self.assertEqual(f.geometry().geometry().wkbType(), QgsWkbTypes.LineString25D)
@@ -159,7 +159,7 @@ def testNoDanglingFileDescriptorAfterCloseVariant1(self):
f.write('1,\n')
f.write('2,POINT(2 49)\n')

vl = QgsVectorLayer(u'{}|layerid=0'.format(datasource), u'test', u'ogr')
vl = QgsVectorLayer('{}|layerid=0'.format(datasource), 'test', 'ogr')
self.assertTrue(vl.isValid())
# The iterator will take one extra connection
myiter = vl.getFeatures()
@@ -200,7 +200,7 @@ def testNoDanglingFileDescriptorAfterCloseVariant2(self):
f.write('1,\n')
f.write('2,POINT(2 49)\n')

vl = QgsVectorLayer(u'{}|layerid=0'.format(datasource), u'test', u'ogr')
vl = QgsVectorLayer('{}|layerid=0'.format(datasource), 'test', 'ogr')
self.assertTrue(vl.isValid())
# Consume all features.
myiter = vl.getFeatures()
@@ -51,7 +51,7 @@ def testSingleToMultiPolygonPromotion(self):
lyr = ds.CreateLayer('test', geom_type=ogr.wkbMultiPolygon)
ds = None

vl = QgsVectorLayer(u'{}|layerid=0'.format(tmpfile), u'test', u'ogr')
vl = QgsVectorLayer('{}|layerid=0'.format(tmpfile), 'test', 'ogr')
f = QgsFeature()
f.setGeometry(QgsGeometry.fromWkt('POLYGON ((0 0,0 1,1 1,0 0))'))
vl.dataProvider().addFeatures([f])
@@ -69,8 +69,8 @@ def testCurveGeometryType(self):
lyr = ds.CreateLayer('test', geom_type=ogr.wkbCurvePolygon)
ds = None

vl = QgsVectorLayer(u'{}'.format(tmpfile), u'test', u'ogr')
self.assertEqual(vl.dataProvider().subLayers(), [u'0:test:0:CurvePolygon'])
vl = QgsVectorLayer('{}'.format(tmpfile), 'test', 'ogr')
self.assertEqual(vl.dataProvider().subLayers(), ['0:test:0:CurvePolygon'])
f = QgsFeature()
f.setGeometry(QgsGeometry.fromWkt('POLYGON ((0 0,0 1,1 1,0 0))'))
vl.dataProvider().addFeatures([f])
@@ -66,7 +66,7 @@ def testFidSupport(self):
f = None
ds = None

vl = QgsVectorLayer(u'{}'.format(tmpfile), u'test', u'ogr')
vl = QgsVectorLayer('{}'.format(tmpfile), 'test', 'ogr')
self.assertEqual(len(vl.fields()), 3)
got = [(f.attribute('fid'), f.attribute('strfield'), f.attribute('intfield')) for f in vl.getFeatures()]
self.assertEqual(got, [(12, 'foo', 123)])
@@ -33,7 +33,7 @@ class TestPyQgsOracleProvider(unittest.TestCase, ProviderTestCase):
@classmethod
def setUpClass(cls):
"""Run before all tests"""
cls.dbconn = u"host=localhost port=1521 user='QGIS' password='qgis'"
cls.dbconn = "host=localhost port=1521 user='QGIS' password='qgis'"
if 'QGIS_ORACLETEST_DB' in os.environ:
cls.dbconn = os.environ['QGIS_ORACLETEST_DB']
# Create test layers
@@ -51,10 +51,10 @@ def tearDownClass(cls):
"""Run after all tests"""

def enableCompiler(self):
QSettings().setValue(u'/qgis/compileExpressions', True)
QSettings().setValue('/qgis/compileExpressions', True)

def disableCompiler(self):
QSettings().setValue(u'/qgis/compileExpressions', False)
QSettings().setValue('/qgis/compileExpressions', False)

def uncompiledFilters(self):
filters = set([
Loading

0 comments on commit d49b656

Please sign in to comment.