Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Migrate more tests to Python3
  • Loading branch information
m-kuhn committed May 13, 2016
1 parent 7dfc696 commit af1de6e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion tests/src/python/providertestbase.py
Expand Up @@ -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]))
Expand Down
6 changes: 3 additions & 3 deletions tests/src/python/test_provider_postgres.py
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'])
Expand Down
17 changes: 7 additions & 10 deletions tests/src/python/test_qgis_local_server.py
Expand Up @@ -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'
Expand All @@ -21,7 +24,6 @@
import os
import sys
import datetime
import StringIO
import tempfile

if os.name == 'nt':
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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>'

Expand Down
4 changes: 3 additions & 1 deletion tests/src/python/test_qgsnetworkcontentfetcher.py
Expand Up @@ -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'
Expand Down Expand Up @@ -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()
13 changes: 5 additions & 8 deletions tests/src/python/test_qgspallabeling_base.py
Expand Up @@ -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'
Expand All @@ -24,7 +27,6 @@
import datetime
import glob
import shutil
import StringIO
import tempfile

from qgis.PyQt.QtCore import QSize, qDebug
Expand Down Expand Up @@ -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>'

Expand Down
5 changes: 3 additions & 2 deletions tests/src/python/test_qgsrasterlayer.py
Expand Up @@ -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'
Expand Down Expand Up @@ -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' % (
Expand All @@ -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))
Expand Down
6 changes: 4 additions & 2 deletions tests/src/python/test_qgsvectorfilewriter.py
Expand Up @@ -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'
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit af1de6e

Please sign in to comment.