Skip to content
Permalink
Browse files

Migrate more tests to Python3

  • Loading branch information
m-kuhn committed May 13, 2016
1 parent 7dfc696 commit af1de6e3e04e538c2392e2019366cb519e3410d5
@@ -459,7 +459,7 @@ def testExtent(self):
QgsRectangle(-71.123, 66.33, -65.32, 78.3))
provider_extent = QgsGeometry.fromRect(self.provider.extent())

assert QgsGeometry.compare(provider_extent.asPolygon(), reference.asPolygon(), 0.00001), 'Expected {}, got {}'.format(reference.exportToWkt(), provider_extent.exportToWkt())
self.assertTrue(QgsGeometry.compare(provider_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001))

def testUnique(self):
self.assertEqual(set(self.provider.uniqueValues(1)), set([-200, 100, 200, 300, 400]))
@@ -6,6 +6,7 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
from builtins import next
__author__ = 'Matthias Kuhn'
__date__ = '2015-04-23'
__copyright__ = 'Copyright 2015, The QGIS Project'
@@ -159,8 +160,7 @@ def test_unique(features, num_features):
def testSignedIdentifiers(self):
def test_query_attribute(dbconn, query, att, val, fidval):
ql = QgsVectorLayer('%s table="%s" (g) key=\'%s\' sql=' % (dbconn, query.replace('"', '\\"'), att), "testgeom", "postgres")
print(query, att)
assert(ql.isValid())
self.assertTrue(ql.isValid())
features = ql.getFeatures()
att_idx = ql.fieldNameIndex(att)
count = 0
@@ -224,7 +224,7 @@ def testDomainTypes(self):
expected['fld_text_domain'] = {'type': QVariant.String, 'typeName': 'qgis_test.text_domain', 'length': -1}
expected['fld_numeric_domain'] = {'type': QVariant.Double, 'typeName': 'qgis_test.numeric_domain', 'length': 10, 'precision': 4}

for f, e in expected.iteritems():
for f, e in expected.items():
self.assertEqual(fields.at(fields.indexFromName(f)).type(), e['type'])
self.assertEqual(fields.at(fields.indexFromName(f)).typeName(), e['typeName'])
self.assertEqual(fields.at(fields.indexFromName(f)).length(), e['length'])
@@ -12,6 +12,9 @@
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()
__author__ = 'Larry Shaffer'
__date__ = '2014/02/16'
__copyright__ = 'Copyright 2014, The QGIS Project'
@@ -21,7 +24,6 @@
import os
import sys
import datetime
import StringIO
import tempfile

if os.name == 'nt':
@@ -119,7 +121,7 @@ def test_getmap(self):
chk = QgsRenderChecker()
chk.setControlName('expected_' + test_name)
# chk.setMapRenderer(None)
res = chk.compareImages(test_name, 0, str(img_path))
res = chk.compareImages(test_name, 0, img_path)
if QGIS_TEST_REPORT and not res: # don't report ok checks
TESTREPORTS[test_name] = chk.report()
msg = '\nRender check failed for "{0}"'.format(test_name)
@@ -132,7 +134,7 @@ def getmap_params(self):
'REQUEST': 'GetMap',
# 'MAP': abs path, also looks in localserver.web_dir()
'MAP': 'test-server.qgs',
# layer stacking order for rendering: bottom,to,top
# layer stacking order for rendering: bottom, to, top
'LAYERS': ['background', 'aoi'], # or 'background,aoi'
'STYLES': ',',
'CRS': 'EPSG:32613', # or QgsCoordinateReferenceSystem obj
@@ -158,19 +160,14 @@ def run_suite(module, tests):
suite = loader.loadTestsFromModule(module)
verb = 2 if 'QGIS_TEST_VERBOSE' in os.environ else 0

out = StringIO.StringIO()
res = unittest.TextTestRunner(stream=out, verbosity=verb).run(suite)
if verb:
print('\nIndividual test summary:')
print('\n' + out.getvalue())
out.close()
res = unittest.TextTestRunner(verbosity=verb).run(suite)

if QGIS_TEST_REPORT and len(TESTREPORTS) > 0:
teststamp = 'Local Server Test Report: ' + \
datetime.datetime.now().strftime('%Y-%m-%d %X')
report = '<html><head><title>{0}</title></head><body>'.format(teststamp)
report += '\n<h2>Failed Image Tests: {0}</h2>'.format(len(TESTREPORTS))
for k, v in TESTREPORTS.iteritems():
for k, v in TESTREPORTS.items():
report += '\n<h3>{0}</h3>\n{1}'.format(k, v)
report += '</body></html>'

@@ -6,6 +6,8 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
from builtins import chr
from builtins import str
__author__ = 'Matthias Kuhn'
__date__ = '4/28/2015'
__copyright__ = 'Copyright 2015, The QGIS Project'
@@ -115,7 +117,7 @@ def testFetchEncodedContent(self):
assert r.error() == QNetworkReply.NoError, r.error()

html = fetcher.contentAsString()
assert unichr(6040) in html
assert chr(6040) in html

if __name__ == "__main__":
unittest.main()
@@ -10,6 +10,9 @@
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()

__author__ = 'Larry Shaffer'
__date__ = '07/09/2013'
@@ -24,7 +27,6 @@
import datetime
import glob
import shutil
import StringIO
import tempfile

from qgis.PyQt.QtCore import QSize, qDebug
@@ -463,19 +465,14 @@ def runSuite(module, tests):
suite = loader.loadTestsFromModule(module)
verb = 2 if 'PAL_VERBOSE' in os.environ else 0

out = StringIO.StringIO()
res = unittest.TextTestRunner(stream=out, verbosity=verb).run(suite)
if verb:
print('\nIndividual test summary:')
print('\n' + out.getvalue())
out.close()
res = unittest.TextTestRunner(verbosity=verb).run(suite)

if PALREPORTS:
teststamp = 'PAL Test Report: ' + \
datetime.datetime.now().strftime('%Y-%m-%d %X')
report = '<html><head><title>{0}</title></head><body>'.format(teststamp)
report += '\n<h2>Failed Tests: {0}</h2>'.format(len(PALREPORTS))
for k, v in PALREPORTS.iteritems():
for k, v in PALREPORTS.items():
report += '\n<h3>{0}</h3>\n{1}'.format(k, v)
report += '</body></html>'

@@ -6,6 +6,7 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
from builtins import str
__author__ = 'Tim Sutton'
__date__ = '20/08/2012'
__copyright__ = 'Copyright 2012, The QGIS Project'
@@ -57,7 +58,7 @@ def testIdentify(self):
assert len(myRasterValues) > 0

# Get the name of the first band
myBand = myRasterValues.keys()[0]
myBand = list(myRasterValues.keys())[0]
# myExpectedName = 'Band 1
myExpectedBand = 1
myMessage = 'Expected "%s" got "%s" for first raster band name' % (
@@ -66,7 +67,7 @@ def testIdentify(self):

# Convert each band value to a list of ints then to a string

myValues = myRasterValues.values()
myValues = list(myRasterValues.values())
myIntValues = []
for myValue in myValues:
myIntValues.append(int(myValue))
@@ -6,6 +6,8 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
from builtins import next
from builtins import str
__author__ = 'Tim Sutton'
__date__ = '20/08/2012'
__copyright__ = 'Copyright 2012, The QGIS Project'
@@ -106,11 +108,11 @@ def testDateTimeWriteShapefile(self):
self.assertEqual(f.attributes()[date_idx], QDate(2014, 3, 5))
time_idx = created_layer.fieldNameIndex('time_f')
#shapefiles do not support time types
assert isinstance(f.attributes()[time_idx], basestring)
assert isinstance(f.attributes()[time_idx], str)
self.assertEqual(f.attributes()[time_idx], '13:45:22')
#shapefiles do not support datetime types
datetime_idx = created_layer.fieldNameIndex('dt_f')
assert isinstance(f.attributes()[datetime_idx], basestring)
assert isinstance(f.attributes()[datetime_idx], str)
self.assertEqual(f.attributes()[datetime_idx], QDateTime(QDate(2014, 3, 5), QTime(13, 45, 22)).toString("yyyy/MM/dd hh:mm:ss.zzz"))

def testDateTimeWriteTabfile(self):

0 comments on commit af1de6e

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