Add qgis.testing module for generic qgis test helpers

This commit is contained in:
Matthias Kuhn 2016-01-06 13:44:29 +01:00
parent a3d3ffdf02
commit c21889f945
79 changed files with 865 additions and 614 deletions

View File

@ -61,3 +61,4 @@ sudo apt-get install --force-yes --no-install-recommends --no-install-suggests \
postgresql-9.1-postgis-2.1/precise # from ubuntugis-unstable, not pgdg
sudo -H pip install autopep8 # TODO when switching to trusty or above: replace python-pip with python-autopep8
sudo -H pip install nose2 pyyaml mock

View File

@ -18,4 +18,4 @@ mkdir -p /Users/travis/Library/Python/2.7/lib/python/site-packages
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/travis/Library/Python/2.7/lib/python/site-packages/homebrew.pth
# Needed for Processing
pip install psycopg2 numpy
pip install psycopg2 numpy nose2 pyyaml mock

View File

@ -59,6 +59,7 @@ ADD_SUBDIRECTORY(console)
ADD_SUBDIRECTORY(PyQt)
ADD_SUBDIRECTORY(pyplugin_installer)
ADD_SUBDIRECTORY(ext-libs)
ADD_SUBDIRECTORY(testing)
IF(POLICY CMP0040)
CMAKE_POLICY (POP) # see PUSH above

View File

@ -0,0 +1,24 @@
# See ../CMakeLists.txt for info on staged-plugins* and clean-staged-plugins targets
SET (QGIS_PYTHON_DIR ${QGIS_DATA_DIR}/python)
SET (PYTHON_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/python)
SET(PY_FILES
__init__.py
mocked.py
)
FILE (MAKE_DIRECTORY ${QGIS_PYTHON_OUTPUT_DIRECTORY}/testing)
INSTALL(FILES ${PY_FILES} DESTINATION "${QGIS_PYTHON_DIR}/testing")
ADD_CUSTOM_TARGET(pytesting ALL)
# stage to output to make available when QGIS is run from build directory
FOREACH(pyfile ${PY_FILES})
ADD_CUSTOM_COMMAND(TARGET pytesting
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${pyfile} "${QGIS_PYTHON_OUTPUT_DIRECTORY}/testing"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${pyfile}
)
PY_COMPILE(pyutils "${QGIS_PYTHON_OUTPUT_DIRECTORY}/testing/${pyfile}")
ENDFOREACH(pyfile)

197
python/testing/__init__.py Normal file
View File

@ -0,0 +1,197 @@
# -*- coding: utf-8 -*-
"""
***************************************************************************
__init__.py
---------------------
Date : January 2016
Copyright : (C) 2016 by Matthias Kuhn
Email : matthias@opengis.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
__author__ = 'Matthias Kuhn'
__date__ = 'January 2016'
__copyright__ = '(C) 2016, Matthias Kuhn'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = ':%H$'
import os
import sys
from PyQt4.QtCore import QVariant
from qgis.core import QgsApplication, QgsFeatureRequest, QgsVectorLayer
from nose2.compat import unittest
# Get a backup, we will patch this one later
_TestCase = unittest.TestCase
class TestCase(_TestCase):
def assertLayersEqual(self, layer1, layer2, **kwargs):
"""
:param layer1: The first layer to compare
:param layer2: The second layer to compare
:param request: Optional, A feature request. This can be used to specify
an order by clause to make sure features are compared in
a given sequence if they don't match by default.
"""
try:
request = kwargs['request']
except KeyError:
request = QgsFeatureRequest()
try:
compare = kwargs['compare']
except KeyError:
compare = {}
# Compare fields
_TestCase.assertEqual(self, layer1.fields().count(), layer2.fields().count())
for fieldnum in range(layer1.fields().count()):
field1 = layer1.fields().at(fieldnum)
field2 = layer2.fields().at(fieldnum)
_TestCase.assertEqual(self, field1.name(), field2.name())
# _TestCase.assertEqual(self, field1.type(), field2.type(), 'Field "{}" is not equal: {}({}) != {}({})'.format(field1.name(), field1.typeName(), field1.type(), field2.typeName(), field2.type()))
# Compare CRS
_TestCase.assertEqual(self, layer1.dataProvider().crs().authid(), layer2.dataProvider().crs().authid())
# Compare features
_TestCase.assertEqual(self, layer1.featureCount(), layer2.featureCount())
try:
precision = compare['geometry']['precision']
except KeyError:
precision = 17
for feats in zip(layer1.getFeatures(request), layer2.getFeatures(request)):
if feats[0].geometry() is not None:
geom0 = feats[0].geometry().geometry().asWkt(precision)
else:
geom0 = None
if feats[1].geometry() is not None:
geom1 = feats[1].geometry().geometry().asWkt(precision)
else:
geom1 = None
_TestCase.assertEqual(
self,
geom0,
geom1,
'Features {}/{} differ in geometry: \n\n {}\n\n vs \n\n {}'.format(
feats[0].id(),
feats[1].id(),
geom0,
geom1
)
)
for attr0, attr1, field1, field2 in zip(feats[0].attributes(), feats[1].attributes(), layer1.fields().toList(), layer2.fields().toList()):
try:
cmp = compare['fields'][field1.name()]
except KeyError:
try:
cmp = compare['fields']['__all__']
except KeyError:
cmp = {}
# Skip field
if 'skip' in cmp:
continue
# Cast field to a given type
if 'cast' in cmp:
if cmp['cast'] == 'int':
attr0 = int(attr0) if attr0 else None
attr1 = int(attr1) if attr0 else None
if cmp['cast'] == 'float':
attr0 = float(attr0) if attr0 else None
attr1 = float(attr1) if attr0 else None
if cmp['cast'] == 'str':
attr0 = str(attr0)
attr1 = str(attr1)
# Round field (only numeric so it works with __all__)
if 'precision' in cmp and field1.type() in [QVariant.Int, QVariant.Double, QVariant.LongLong]:
attr0 = round(attr0, cmp['precision'])
attr1 = round(attr1, cmp['precision'])
_TestCase.assertEqual(
self,
attr0,
attr1,
'Features {}/{} differ in attributes\n\n * Field1: {} ({})\n * Field2: {} ({})\n\n * {} != {}'.format(feats[0].id(),
feats[1].id(),
field1.name(),
field1.typeName(),
field2.name(),
field2.typeName(),
repr(attr0),
repr(attr1)
)
)
# Patch unittest
unittest.TestCase = TestCase
def start_app():
"""
Will start a QgsApplication and call all initialization code like
registering the providers and other infrastructure. It will not load
any plugins.
You can always get the reference to a running app by calling `QgsApplication.instance()`.
The initialization will only happen once, so it is safe to call this method repeatedly.
Returns
-------
QgsApplication
A QgsApplication singleton
"""
global QGISAPP
try:
QGISAPP
except NameError:
myGuiFlag = True # All test will run qgis in gui mode
# In python3 we need to convert to a bytes object (or should
# QgsApplication accept a QString instead of const char* ?)
try:
argvb = list(map(os.fsencode, sys.argv))
except AttributeError:
argvb = sys.argv
# Note: QGIS_PREFIX_PATH is evaluated in QgsApplication -
# no need to mess with it here.
QGISAPP = QgsApplication(argvb, myGuiFlag)
QGISAPP.initQgis()
s = QGISAPP.showSettings()
print(s)
return QGISAPP
def stop_app():
"""
Cleans up and exits QGIS
"""
global QGISAPP
QGISAPP.exitQgis()
del QGISAPP

67
python/testing/mocked.py Normal file
View File

@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-
"""
***************************************************************************
mocked
---------------------
Date : January 2016
Copyright : (C) 2016 by Matthias Kuhn
Email : matthias@opengis.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
__author__ = 'Matthias Kuhn'
__date__ = 'January 2016'
__copyright__ = '(C) 2016, Matthias Kuhn'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = ':%H$'
import os
import sys
import mock
from qgis.gui import QgisInterface, QgsMapCanvas
from qgis.core import QgsApplication
from PyQt4.QtGui import QMainWindow
from PyQt4.QtCore import QSize
from qgis.testing import start_app
def get_iface():
"""
Will return a mock QgisInterface object with some methods implemented in a generic way.
You can further control its behavior
by using the mock infrastructure. Refer to https://docs.python.org/3/library/unittest.mock.html
for more details.
Returns
-------
QgisInterface
A mock QgisInterface
"""
start_app()
my_iface = mock.Mock(spec=QgisInterface)
my_iface.mainWindow.return_value = QMainWindow()
canvas = QgsMapCanvas(my_iface.mainWindow())
canvas.resize(QSize(400, 400))
my_iface.mapCanvas.return_value = canvas
return my_iface

View File

@ -17,23 +17,37 @@ import tempfile
import shutil
import glob
from qgis.core import QGis, QgsField, QgsPoint, QgsMapLayer, QgsVectorLayer, QgsFeatureRequest, QgsFeature, QgsProviderRegistry, \
QgsGeometry, NULL
from PyQt4.QtCore import QSettings
from utilities import (unitTestDataPath,
getQgisTestApp,
unittest,
TestCase,
compareWkt
)
from qgis.core import (
QGis,
QgsField,
QgsPoint,
QgsMapLayer,
QgsVectorLayer,
QgsFeatureRequest,
QgsFeature,
QgsProviderRegistry,
QgsGeometry,
NULL
)
from qgis.testing import (
start_app,
unittest
)
from utilities import (
unitTestDataPath,
compareWkt
)
from providertestbase import ProviderTestCase
from PyQt4.QtCore import QVariant
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
TEST_DATA_DIR = unitTestDataPath()
class TestPyQgsMemoryProvider(TestCase, ProviderTestCase):
class TestPyQgsMemoryProvider(unittest.TestCase, ProviderTestCase):
@classmethod
def setUpClass(cls):
@ -241,7 +255,8 @@ class TestPyQgsMemoryProvider(TestCase, ProviderTestCase):
assert f == importedFields.field(f.name())
class TestPyQgsMemoryProviderIndexed(TestCase, ProviderTestCase):
class TestPyQgsMemoryProviderIndexed(unittest.TestCase, ProviderTestCase):
"""Runs the provider test suite against an indexed memory layer"""
@classmethod

View File

@ -17,25 +17,38 @@ import os
import sys
from qgis.core import NULL
from qgis.core import QgsVectorLayer, QgsFeatureRequest, QgsFeature, QgsProviderRegistry
from PyQt4.QtCore import QSettings, QDate, QTime, QDateTime, QVariant
from utilities import (unitTestDataPath,
getQgisTestApp,
unittest,
TestCase
)
from qgis.core import (
QgsVectorLayer,
QgsFeatureRequest,
QgsFeature,
QgsProviderRegistry
from PyQt4.QtCore import (
QSettings,
QDate,
QTime,
QDateTime,
QVariant
)
from utilities import unitTestDataPath
from qgis.testing import (
start_app,
unittest
)
from providertestbase import ProviderTestCase
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
TEST_DATA_DIR = unitTestDataPath()
start_app()
TEST_DATA_DIR=unitTestDataPath()
class TestPyQgsMssqlProvider(TestCase, ProviderTestCase):
class TestPyQgsMssqlProvider(unittest.TestCase, ProviderTestCase):
@classmethod
def setUpClass(cls):
"""Run before all tests"""
cls.dbconn = u"dbname='gis' host=localhost\sqlexpress"
cls.dbconn=u"dbname='gis' host=localhost\sqlexpress"
if 'QGIS_MSSQLTEST_DB' in os.environ:
cls.dbconn = os.environ['QGIS_MSSQLTEST_DB']
# Create test layers
@ -58,23 +71,23 @@ class TestPyQgsMssqlProvider(TestCase, ProviderTestCase):
# HERE GO THE PROVIDER SPECIFIC TESTS
def testDateTimeTypes(self):
vl = QgsVectorLayer('%s table="qgis_test"."date_times" sql=' % (self.dbconn), "testdatetimes", "mssql")
vl=QgsVectorLayer('%s table="qgis_test"."date_times" sql=' % (self.dbconn), "testdatetimes", "mssql")
assert(vl.isValid())
fields = vl.dataProvider().fields()
fields=vl.dataProvider().fields()
self.assertEqual(fields.at(fields.indexFromName('date_field')).type(), QVariant.Date)
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=vl.getFeatures(QgsFeatureRequest()).next()
date_idx = vl.fieldNameIndex('date_field')
date_idx=vl.fieldNameIndex('date_field')
assert isinstance(f.attributes()[date_idx], QDate)
self.assertEqual(f.attributes()[date_idx], QDate(2004, 3, 4))
time_idx = vl.fieldNameIndex('time_field')
time_idx=vl.fieldNameIndex('time_field')
assert isinstance(f.attributes()[time_idx], QTime)
self.assertEqual(f.attributes()[time_idx], QTime(13, 41, 52))
datetime_idx = vl.fieldNameIndex('datetime_field')
datetime_idx=vl.fieldNameIndex('datetime_field')
assert isinstance(f.attributes()[datetime_idx], QDateTime)
self.assertEqual(f.attributes()[datetime_idx], QDateTime(QDate(2004, 3, 4), QTime(13, 41, 52)))

View File

@ -14,23 +14,21 @@ __revision__ = '$Format:%H$'
import qgis
import os
import sys
from qgis.core import NULL
from qgis.core import QgsVectorLayer, QgsFeatureRequest, QgsFeature, QgsProviderRegistry
from PyQt4.QtCore import QSettings, QDate, QTime, QDateTime, QVariant
from utilities import (unitTestDataPath,
getQgisTestApp,
unittest,
TestCase
)
from qgis.testing import (start_app,
unittest
)
from utilities import unitTestDataPath
from providertestbase import ProviderTestCase
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
TEST_DATA_DIR = unitTestDataPath()
class TestPyQgsPostgresProvider(TestCase, ProviderTestCase):
class TestPyQgsPostgresProvider(unittest.TestCase, ProviderTestCase):
@classmethod
def setUpClass(cls):

View File

@ -12,6 +12,7 @@ __copyright__ = 'Copyright 2015, The QGIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
import qgis
import os
import tempfile
import shutil
@ -19,18 +20,17 @@ import glob
from qgis.core import QgsVectorLayer, QgsFeatureRequest, QgsFeature, QgsProviderRegistry
from PyQt4.QtCore import QSettings
from utilities import (unitTestDataPath,
getQgisTestApp,
unittest,
TestCase
)
from qgis.testing import (start_app,
unittest
)
from utilities import unitTestDataPath
from providertestbase import ProviderTestCase
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
TEST_DATA_DIR = unitTestDataPath()
class TestPyQgsShapefileProvider(TestCase, ProviderTestCase):
class TestPyQgsShapefileProvider(unittest.TestCase, ProviderTestCase):
@classmethod
def setUpClass(cls):

View File

@ -15,15 +15,13 @@ __revision__ = '$Format:%H$'
import qgis
import os
import tempfile
import sys
from qgis.core import QgsVectorLayer, QgsPoint, QgsFeature
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest
)
from qgis.testing import (start_app,
unittest
)
from utilities import unitTestDataPath
from providertestbase import ProviderTestCase
from PyQt4.QtCore import QSettings
@ -34,7 +32,7 @@ except ImportError:
raise ImportError
# Convenience instances in case you may need them
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
TEST_DATA_DIR = unitTestDataPath()
@ -42,7 +40,7 @@ def die(error_message):
raise Exception(error_message)
class TestQgsSpatialiteProvider(TestCase, ProviderTestCase):
class TestQgsSpatialiteProvider(unittest.TestCase, ProviderTestCase):
@classmethod
def setUpClass(cls):

View File

@ -19,19 +19,19 @@ import glob
from qgis.core import QgsVectorLayer, QgsFeatureRequest, QgsFeature, QgsProviderRegistry
from PyQt4.QtCore import QSettings, QDate, QTime, QDateTime, QVariant
from utilities import (unitTestDataPath,
getQgisTestApp,
unittest,
TestCase
)
from qgis.testing import (
start_app,
unittest
)
from utilities import unitTestDataPath
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
TEST_DATA_DIR = unitTestDataPath()
# Note - doesn't implement ProviderTestCase as OGR provider is tested by the shapefile provider test
class TestPyQgsTabfileProvider(TestCase):
class TestPyQgsTabfileProvider(unittest.TestCase):
def testDateTimeFormats(self):
# check that date and time formats are correctly interpreted

View File

@ -14,8 +14,6 @@ __revision__ = '$Format:%H$'
import qgis
import os
import tempfile
import sys
from qgis.core import (QGis,
QgsVectorLayer,
@ -33,11 +31,11 @@ from qgis.core import (QGis,
QgsProject
)
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest
)
from qgis.testing import (start_app,
unittest
)
from utilities import unitTestDataPath
from providertestbase import ProviderTestCase
from PyQt4.QtCore import *
@ -50,11 +48,11 @@ except ImportError:
import tempfile
# Convenience instances in case you may need them
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
TEST_DATA_DIR = unitTestDataPath()
class TestQgsVirtualLayerProvider(TestCase, ProviderTestCase):
class TestQgsVirtualLayerProvider(unittest.TestCase, ProviderTestCase):
@classmethod
def setUpClass(cls):

View File

@ -36,21 +36,21 @@ from qgis.core import (
from qgis_local_server import getLocalServer
from utilities import (
TestCase,
getQgisTestApp,
unittest,
openInBrowserTab
from qgis.testing import (
start_app,
unittest
)
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
from utilities import openInBrowserTab
start_app()
MAPSERV = getLocalServer()
QGIS_TEST_REPORT = 'QGIS_TEST_REPORT' in os.environ
TESTREPORTS = {}
class TestQgisLocalServer(TestCase):
class TestQgisLocalServer(unittest.TestCase):
@classmethod
def setUpClass(cls):

View File

@ -14,28 +14,19 @@ test_analysis.py
* *
***************************************************************************/
'''
import unittest
import sys
import qgis
from utilities import unitTestDataPath, getQgisTestApp
from qgis.testing import (start_app,
unittest
)
from utilities import unitTestDataPath
# support python < 2.7 via unittest2
# needed for expected failure decorator
if sys.version_info[0:2] < (2, 7):
try:
from unittest2 import TestCase, expectedFailure
except ImportError:
print "You should install unittest2 to run the salt tests"
sys.exit(0)
else:
from unittest import TestCase, expectedFailure
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
TEST_DATA_DIR = unitTestDataPath()
class TestQgsZonalStatistics(TestCase):
class TestQgsZonalStatistics(unittest.TestCase):
def setUp(self):
"""Run before each test."""
@ -45,7 +36,7 @@ class TestQgsZonalStatistics(TestCase):
"""Run after each test."""
pass
#@expectedFailure
#@unittest.expectedFailure
def testSubstitutionMap(self):
"""Test that we can import zonal statistics was failing as of d5f6543
"""

View File

@ -12,10 +12,10 @@ __copyright__ = 'Copyright 2012, The QGIS Project'
__revision__ = '$Format:%H$'
import qgis
from utilities import getQgisTestApp, unittest, expectedFailure
from qgis.testing import start_app, unittest
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
QGISAPP = start_app()
class TestPyQgsApplication(unittest.TestCase):

View File

@ -26,7 +26,8 @@ import subprocess
import tempfile
import errno
from utilities import unittest, unitTestDataPath
from qgis.testing import unittest
from utilities import unitTestDataPath
print 'CTEST_FULL_OUTPUT'

View File

@ -15,19 +15,19 @@ test_qgsatlascomposition.py
***************************************************************************/
'''
import qgis
import unittest
import os
import glob
import shutil
import tempfile
from utilities import getQgisTestApp, unitTestDataPath
from qgis.testing import start_app, unittest
from utilities import unitTestDataPath
from PyQt4.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
from qgscompositionchecker import QgsCompositionChecker
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
class TestQgsAtlasComposition(unittest.TestCase):

View File

@ -15,15 +15,14 @@ __revision__ = '$Format:%H$'
from qgis.gui import QgsAttributeTableModel, QgsEditorWidgetRegistry
from qgis.core import QgsFeature, QgsGeometry, QgsPoint, QgsVectorLayer, QgsVectorLayerCache, NULL
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest
)
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
from qgis.testing import (start_app,
unittest
)
from utilities import unitTestDataPath
start_app()
class TestQgsAttributeTableModel(TestCase):
class TestQgsAttributeTableModel(unittest.TestCase):
@classmethod
def setUpClass(cls):

View File

@ -26,9 +26,8 @@ from PyQt4.QtGui import *
from PyQt4.QtNetwork import *
from PyQt4.QtTest import *
from utilities import (
TestCase,
getQgisTestApp,
from qgis.testing import (
start_app,
unittest,
expectedFailure,
unitTestDataPath,
@ -36,13 +35,13 @@ from utilities import (
AUTHDBDIR = tempfile.mkdtemp()
os.environ['QGIS_AUTH_DB_DIR_PATH'] = AUTHDBDIR
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
TESTDATA = os.path.join(unitTestDataPath(), 'auth_system')
PKIDATA = os.path.join(TESTDATA, 'certs_keys')
class TestQgsAuthManager(TestCase):
class TestQgsAuthManager(unittest.TestCase):
@classmethod
def setUpClass(cls):

View File

@ -23,7 +23,6 @@ __copyright__ = '(C) 2013, Nyall Dawson, Massimo Endrighi'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
import qgis
import os
from PyQt4.QtCore import QSize
@ -38,22 +37,26 @@ from qgis.core import (QgsVectorLayer,
QgsRectangle
)
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest
)
from qgis.testing import (start_app,
unittest
)
from qgis.testing.mocked import get_iface
from utilities import unitTestDataPath
# Convenience instances in case you may need them
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
TEST_DATA_DIR = unitTestDataPath()
class TestQgsBlendModes(TestCase):
class TestQgsBlendModes(unittest.TestCase):
def __init__(self, methodName):
"""Run once on class initialisation."""
unittest.TestCase.__init__(self, methodName)
self.iface = get_iface()
# initialize class MapRegistry, Canvas, MapRenderer, Map and PAL
self.mMapRegistry = QgsMapLayerRegistry.instance()
@ -89,7 +92,7 @@ class TestQgsBlendModes(TestCase):
self.mMapRegistry.addMapLayer(self.mRasterLayer2)
# to match blend modes test comparisons background
self.mCanvas = CANVAS
self.mCanvas = self.iface.mapCanvas()
self.mCanvas.setCanvasColor(QColor(152, 219, 249))
self.mMap = self.mCanvas.map()
self.mMap.resize(QSize(400, 400))

View File

@ -14,10 +14,9 @@ __revision__ = '$Format:%H$'
import qgis
from utilities import (unittest,
TestCase,
getQgisTestApp,
)
from qgis.testing import (unittest,
start_app,
)
from qgis.core import (QgsCategorizedSymbolRendererV2,
QgsRendererCategoryV2,
QgsMarkerSymbolV2,
@ -34,7 +33,7 @@ from PyQt4.QtCore import Qt, QVariant
from PyQt4.QtXml import QDomDocument
from PyQt4.QtGui import QColor
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
def createMarkerSymbol():
@ -46,7 +45,7 @@ def createMarkerSymbol():
return symbol
class TestQgsCategorizedSymbolRendererV2(TestCase):
class TestQgsCategorizedSymbolRendererV2(unittest.TestCase):
def testFilter(self):
"""Test filter creation"""

View File

@ -13,7 +13,7 @@ __copyright__ = 'Copyright 2014, The QGIS Project'
__revision__ = '$Format:%H$'
import qgis
from utilities import unittest, TestCase
from qgis.testing import unittest
from qgis.core import QgsColorScheme
from PyQt4.QtGui import QColor
@ -40,7 +40,7 @@ class DummyColorScheme(QgsColorScheme):
return DummyColorScheme()
class TestQgsColorScheme(TestCase):
class TestQgsColorScheme(unittest.TestCase):
def testCreateScheme(self):
"""Test creating a new color scheme"""

View File

@ -13,11 +13,11 @@ __copyright__ = 'Copyright 2014, The QGIS Project'
__revision__ = '$Format:%H$'
import qgis
from utilities import unittest, TestCase
from qgis.testing import unittest
from qgis.core import QgsColorSchemeRegistry, QgsRecentColorScheme
class TestQgsColorSchemeRegistry(TestCase):
class TestQgsColorSchemeRegistry(unittest.TestCase):
def testCreateInstance(self):
"""Test creating global color scheme registry instance"""

View File

@ -19,18 +19,17 @@ from qgis.core import (QgsComposerShape,
QgsComposition,
QgsMapRenderer
)
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest
)
from qgis.testing import (start_app,
unittest
)
from utilities import unitTestDataPath
from qgscompositionchecker import QgsCompositionChecker
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
TEST_DATA_DIR = unitTestDataPath()
class TestQgsComposerEffects(TestCase):
class TestQgsComposerEffects(unittest.TestCase):
def __init__(self, methodName):
"""Run once on class initialisation."""

View File

@ -13,7 +13,6 @@ __copyright__ = 'Copyright 2012, The QGIS Project'
__revision__ = '$Format:%H$'
import qgis
import unittest
import os
from PyQt4.QtCore import QUrl, qDebug
@ -22,22 +21,30 @@ from qgis.core import (QgsComposition,
QgsComposerHtml,
QgsComposerFrame,
QgsComposerMultiFrame,
QgsMapSettings)
QgsMapSettings
)
from qgscompositionchecker import QgsCompositionChecker
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase
)
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
from qgis.testing import (
start_app,
unittest
)
from qgis.testing.mocked import get_iface
from utilities import unitTestDataPath
start_app()
TEST_DATA_DIR = unitTestDataPath()
class TestQgsComposerHtml(TestCase):
class TestQgsComposerHtml(unittest.TestCase):
def setUp(self):
"""Run before each test."""
self.iface = get_iface()
self.mapSettings = QgsMapSettings()
self.mComposition = QgsComposition(self.mapSettings)
self.mComposition.setPaperSize(297, 210) # A4 landscape
@ -136,7 +143,7 @@ class TestQgsComposerHtml(TestCase):
def testComposerHtmlAccessor(self):
"""Test that we can retrieve the ComposerHtml instance given an item.
"""
myComposition = QgsComposition(CANVAS.mapRenderer())
myComposition = QgsComposition(self.iface.mapCanvas().mapRenderer())
mySubstitutionMap = {'replace-me': 'Foo bar'}
myFile = os.path.join(TEST_DATA_DIR, 'template.qpt')
myTemplateFile = file(myFile, 'rt')

View File

@ -15,12 +15,12 @@ test_qgscomposerlabel.py
***************************************************************************/
'''
import qgis
import unittest
from utilities import getQgisTestApp, unitTestDataPath
from qgis.testing import start_app, unittest
from PyQt4.QtCore import QFileInfo, QDate, QDateTime
from qgis.core import QgsVectorLayer, QgsMapLayerRegistry, QgsMapRenderer, QgsComposition, QgsComposerLabel, QgsFeatureRequest, QgsFeature, QgsExpression
from utilities import unitTestDataPath
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
class TestQgsComposerLabel(unittest.TestCase):

View File

@ -28,19 +28,17 @@ from qgis.core import (QgsComposerMap,
QgsMultiBandColorRenderer,
)
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest,
expectedFailure
)
from qgis.testing import (start_app,
unittest
)
from utilities import unitTestDataPath
from qgscompositionchecker import QgsCompositionChecker
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
TEST_DATA_DIR = unitTestDataPath()
class TestQgsComposerMap(TestCase):
class TestQgsComposerMap(unittest.TestCase):
def __init__(self, methodName):
"""Run once on class initialisation."""
@ -137,7 +135,7 @@ class TestQgsComposerMap(TestCase):
assert myTestResult, myMessage
# Fails because addItemsFromXML has been commented out in sip
@expectedFailure
@unittest.expectedFailure
def testuniqueId(self):
doc = QDomDocument()
documentElement = doc.createElement('ComposerItemClipboard')

View File

@ -24,18 +24,17 @@ from qgis.core import (QgsComposerMap,
QgsCoordinateReferenceSystem,
QgsFontUtils
)
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest
)
from qgis.testing import (start_app,
unittest
)
from utilities import unitTestDataPath
from qgscompositionchecker import QgsCompositionChecker
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
TEST_DATA_DIR = unitTestDataPath()
class TestQgsComposerMap(TestCase):
class TestQgsComposerMap(unittest.TestCase):
def __init__(self, methodName):
"""Run once on class initialisation."""

View File

@ -25,18 +25,17 @@ from qgis.core import (QgsComposerPicture,
QgsComposition,
QgsMapSettings
)
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest
)
from qgis.testing import (start_app,
unittest
)
from utilities import unitTestDataPath
from qgscompositionchecker import QgsCompositionChecker
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
TEST_DATA_DIR = unitTestDataPath()
class TestQgsComposerPicture(TestCase):
class TestQgsComposerPicture(unittest.TestCase):
@classmethod
def setUpClass(cls):

View File

@ -20,18 +20,17 @@ from qgis.core import (QgsComposerShape,
QgsComposition,
QgsMapSettings
)
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest
)
from qgis.testing import (start_app,
unittest
)
from utilities import unitTestDataPath
from qgscompositionchecker import QgsCompositionChecker
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
TEST_DATA_DIR = unitTestDataPath()
class TestQgsComposerShapes(TestCase):
class TestQgsComposerShapes(unittest.TestCase):
def __init__(self, methodName):
"""Run once on class initialisation."""

View File

@ -12,7 +12,6 @@ __copyright__ = 'Copyright 2012, The QGIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
import qgis
import os
from PyQt4.QtCore import QFileInfo, QDir
@ -26,22 +25,23 @@ from qgis.core import (QgsComposition,
QgsMapRenderer
)
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest
# expectedFailure
)
from qgis.testing import (start_app,
unittest
)
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
from qgis.testing.mocked import get_iface
from utilities import unitTestDataPath
start_app()
TEST_DATA_DIR = unitTestDataPath()
class TestQgsComposition(TestCase):
class TestQgsComposition(unittest.TestCase):
def setUp(self):
"""Run before each test."""
pass
self.iface = get_iface()
def tearDown(self):
"""Run after each test."""
@ -59,7 +59,7 @@ class TestQgsComposition(TestCase):
myText = 'Latitude: %s, Longitude: %s' % (myLatitude, myLongitude)
# Load the composition with the substitutions
myComposition = QgsComposition(CANVAS.mapRenderer())
myComposition = QgsComposition(self.iface.mapCanvas().mapRenderer())
mySubstitutionMap = {'replace-me': myText}
myFile = os.path.join(TEST_DATA_DIR, 'template-for-substitution.qpt')
myTemplateFile = file(myFile, 'rt')
@ -76,7 +76,7 @@ class TestQgsComposition(TestCase):
def testNoSubstitutionMap(self):
"""Test that we can get a map if we use no text substitutions."""
myComposition = QgsComposition(CANVAS.mapRenderer())
myComposition = QgsComposition(self.iface.mapCanvas().mapRenderer())
myFile = os.path.join(TEST_DATA_DIR, 'template-for-substitution.qpt')
myTemplateFile = file(myFile, 'rt')
myTemplateContent = myTemplateFile.read()

View File

@ -13,19 +13,25 @@ __copyright__ = 'Copyright 2015, The QGIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
from qgis.core import QgsConditionalStyle, QgsFeature, QgsFields, QgsField, QgsExpressionContextUtils
from qgis.core import (QgsConditionalStyle,
QgsFeature,
QgsFields,
QgsField,
QgsExpressionContextUtils
)
from qgis.testing import (start_app,
unittest,
)
from utilities import (unitTestDataPath,
getQgisTestApp,
unittest,
TestCase,
compareWkt)
compareWkt
)
from PyQt4.QtCore import QVariant
#
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
TEST_DATA_DIR = unitTestDataPath()
class TestPyQgsConditionalStyle(TestCase):
class TestPyQgsConditionalStyle(unittest.TestCase):
def new_context(self):
feature = QgsFeature()

View File

@ -18,16 +18,12 @@ from qgis.core import (QgsRectangle,
QgsCoordinateReferenceSystem,
QgsCoordinateTransform
)
from utilities import (getQgisTestApp,
TestCase,
unittest
)
# Convenience instances in case you may need them
# not used in this test
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
from qgis.testing import start_app, unittest
start_app()
class TestQgsCoordinateTransform(TestCase):
class TestQgsCoordinateTransform(unittest.TestCase):
def testTransformBoundingBox(self):
"""Test that we can transform a rectangular bbox from utm56s to LonLat"""

View File

@ -34,34 +34,38 @@ import test_qgsdelimitedtextprovider_wanted as want
rebuildTests = 'REBUILD_DELIMITED_TEXT_TESTS' in os.environ
from PyQt4.QtCore import (QCoreApplication,
QUrl,
QObject
)
import qgis
from qgis.core import (QgsProviderRegistry,
QgsVectorLayer,
QgsFeatureRequest,
QgsRectangle,
QgsMessageLog,
QGis
)
from PyQt4.QtCore import (
QCoreApplication,
QUrl,
QObject
)
from utilities import (getQgisTestApp,
TestCase,
unitTestDataPath,
unittest,
compareWkt
)
from qgis.core import (
QgsProviderRegistry,
QgsVectorLayer,
QgsFeatureRequest,
QgsRectangle,
QgsMessageLog,
QGis
)
from qgis.testing import (
start_app,
unittest
)
from utilities import (
unitTestDataPath,
compareWkt
)
from providertestbase import ProviderTestCase
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
TEST_DATA_DIR = unitTestDataPath()
import sip
sipversion = str(sip.getapi('QVariant'))
sipwanted = '2'
geomkey = "#geometry"
fidkey = "#fid"
@ -245,9 +249,6 @@ def recordDifference(record1, record2):
def runTest(file, requests, **params):
# No point doing test if haven't got the right SIP vesion
if sipversion != sipwanted:
return
testname = inspect.stack()[1][3]
verbose = not rebuildTests
if verbose:
@ -322,7 +323,7 @@ def runTest(file, requests, **params):
assert len(failures) == 0, "\n".join(failures)
class TestQgsDelimitedTextProviderXY(TestCase, ProviderTestCase):
class TestQgsDelimitedTextProviderXY(unittest.TestCase, ProviderTestCase):
@classmethod
def setUpClass(cls):
@ -349,7 +350,7 @@ class TestQgsDelimitedTextProviderXY(TestCase, ProviderTestCase):
"""Run after all tests"""
class TestQgsDelimitedTextProviderWKT(TestCase, ProviderTestCase):
class TestQgsDelimitedTextProviderWKT(unittest.TestCase, ProviderTestCase):
@classmethod
def setUpClass(cls):
@ -389,7 +390,7 @@ class TestQgsDelimitedTextProviderWKT(TestCase, ProviderTestCase):
"""Run after all tests"""
class TestQgsDelimitedTextProviderOther(TestCase):
class TestQgsDelimitedTextProviderOther(unittest.TestCase):
@classmethod
def setUpClass(cls):
@ -401,7 +402,6 @@ class TestQgsDelimitedTextProviderOther(TestCase):
registry = QgsProviderRegistry.instance()
metadata = registry.providerMetadata('delimitedtext')
assert metadata is not None, "Delimited text provider is not installed"
assert sipversion == sipwanted, "SIP version " + sipversion + " - require version " + sipwanted + " for delimited text tests"
def test_002_load_csv_file(self):
# CSV file parsing

View File

@ -19,17 +19,16 @@ from qgis.core import (QgsGeometry,
QgsDistanceArea
)
from utilities import (getQgisTestApp,
TestCase,
unittest)
from qgis.testing import (start_app,
unittest)
# Convenience instances in case you may need them
# not used in this test
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
class TestQgsDistanceArea(TestCase):
class TestQgsDistanceArea(unittest.TestCase):
def testMeasureLine(self):
# +-+

View File

@ -13,12 +13,9 @@ __copyright__ = 'Copyright 2015, The QGIS Project'
__revision__ = '$Format:%H$'
import os
from utilities import (TestCase,
unittest,
printImportant,
DoxygenParser)
from qgis.testing import unittest
from PyQt4.QtCore import qDebug
from utilities import printImportant, DoxygenParser
# DOCUMENTATION THRESHOLD
#
@ -30,7 +27,7 @@ from PyQt4.QtCore import qDebug
ACCEPTABLE_MISSING_DOCS = 3751
class TestQgsDocCoverage(TestCase):
class TestQgsDocCoverage(unittest.TestCase):
def testCoverage(self):
print 'CTEST_FULL_OUTPUT'

View File

@ -21,15 +21,16 @@ from qgis.gui import QgsEditorWidgetRegistry
from PyQt4 import QtCore
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest
)
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
from qgis.testing import (start_app,
unittest
)
from utilities import unitTestDataPath
start_app()
class TestQgsTextEditWidget(TestCase):
class TestQgsTextEditWidget(unittest.TestCase):
@classmethod
def setUpClass(cls):

View File

@ -13,12 +13,12 @@ __copyright__ = 'Copyright 2012, The QGIS Project'
__revision__ = '$Format:%H$'
import qgis
from utilities import unittest, TestCase
from qgis.testing import unittest
from qgis.utils import qgsfunction
from qgis.core import QgsExpression
class TestQgsExpressionCustomFunctions(TestCase):
class TestQgsExpressionCustomFunctions(unittest.TestCase):
@qgsfunction(1, 'testing', register=False)
def testfun(values, feature, parent):

View File

@ -16,17 +16,13 @@ import qgis
import os
from qgis.core import QgsFeature, QgsGeometry, QgsPoint, QgsVectorLayer, NULL
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest
)
from unittest import expectedFailure
from qgis.testing import start_app, unittest
from utilities import unitTestDataPath
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
class TestQgsFeature(TestCase):
class TestQgsFeature(unittest.TestCase):
def test_CreateFeature(self):
feat = QgsFeature()

View File

@ -16,16 +16,17 @@ import qgis
import os
from qgis.core import QgsVectorLayer, QgsFeatureRequest, QgsFeature
from qgis.testing import (start_app,
unittest
)
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest
compareWkt
)
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
TEST_DATA_DIR = unitTestDataPath()
class TestQgsFeatureIterator(TestCase):
class TestQgsFeatureIterator(unittest.TestCase):
def __init__(self, methodName):
"""Run once on class initialisation."""

View File

@ -16,17 +16,15 @@ import qgis
import os
from qgis.core import QgsField, QgsVectorLayer, NULL
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest
)
from unittest import expectedFailure
from qgis.testing import (start_app,
unittest
)
from utilities import unitTestDataPath
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
class TestQgsFields(TestCase):
class TestQgsFields(unittest.TestCase):
def test_expections(self):
ml = QgsVectorLayer("Point?crs=epsg:4236&field=id:integer&field=value:double",

View File

@ -14,21 +14,20 @@ __copyright__ = 'Copyright 2014, The QGIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
import qgis
from qgis.core import QgsFontUtils
from qgis.testing import (
start_app,
unittest
)
from utilities import (
TestCase,
getQgisTestApp,
unittest,
getTestFontFamily,
loadTestFonts
)
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
class TestQgsFontUtils(TestCase):
class TestQgsFontUtils(unittest.TestCase):
@classmethod
def setUpClass(cls):

View File

@ -12,35 +12,39 @@ __copyright__ = 'Copyright 2012, The QGIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
import qgis
import os
import csv
from qgis.core import (QgsGeometry,
QgsVectorLayer,
QgsFeature,
QgsPoint,
QgsCoordinateTransform,
QgsRectangle,
QgsWKBTypes,
QGis)
from qgis.core import (
QgsGeometry,
QgsVectorLayer,
QgsFeature,
QgsPoint,
QgsCoordinateTransform,
QgsRectangle,
QgsWKBTypes,
QGis
)
from utilities import (getQgisTestApp,
TestCase,
unittest,
compareWkt,
doubleNear,
unitTestDataPath,
writeShape)
from qgis.testing import (
start_app,
unittest,
)
from utilities import(
compareWkt,
doubleNear,
unitTestDataPath,
writeShape
)
# Convenience instances in case you may need them not used in this test
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
TEST_DATA_DIR = unitTestDataPath()
class TestQgsGeometry(TestCase):
class TestQgsGeometry(unittest.TestCase):
def testWktPointLoading(self):
myWKT = 'Point (10 10)'

View File

@ -16,7 +16,7 @@ import qgis
from qgis.core import QgsVectorLayer, QgsFeature, QgsGeometry, QgsProject, QgsMapLayerRegistry
from utilities import getQgisTestApp, TestCase, unittest
from qgis.testing import start_app, unittest
feat_wkt = [
@ -39,10 +39,10 @@ Incorrect result from QGIS < 2.2 (four parts):
MULTIPOLYGON(((11556863.91276544518768787 1008143.53638577624224126,11632785.85562258586287498 1005192.9078143477672711,11633693.74133687280118465 996794.96495720488019288,11623253.05562258698046207 996794.96495720488019288,11623026.08419401571154594 998156.79352863342501223,11613039.34133687242865562 1000880.45067149063106626,11612394.26464514434337616 996794.96495720488019288,11605776.25562258809804916 996794.96495720488019288,11605618.44716151989996433 993165.37035266763996333,11605393.122793298214674 993232.96766313433181494,11603539.33281490206718445 993789.104656653245911,11603620.0270511582493782 996794.96495720488019288,11597281.42645414359867573 997264.49092735419981182,11595335.56990830041468143 1000426.50781434774398804,11585348.82705115899443626 1001788.33638577628880739,11585348.82705115899443626 999405.1363857762189582,11585348.82705115899443626 992546.05981434776913375,11579916.07919318228960037 992980.67964298592414707,11580355.4556225873529911 997248.9078143477672711,11578957.31162258610129356 997448.64267149078659713,11577586.53731508925557137 997644.46757256181444973,11577745.28419401682913303 1000199.53638577624224126,11573858.94101548381149769 1000375.19031474948860705,11574000.25562258623540401 1001788.33638577628880739,11564467.4556225873529911 1004058.0506714906077832,11563869.05927479639649391 1000826.71039342461153865,11557658.3127654455602169 1001107.42210006201639771,11556863.91276544518768787 1008143.53638577624224126)),((11578337.0769300926476717 993106.99982403311878443,11577309.72997828386723995 993189.18758017767686397,11577309.72997828386723995 993189.18758017779327929,11578337.0769300926476717 993106.99982403311878443)),((11604513.11028097197413445 967742.62210006208624691,11604300.94133687205612659 962862.73638577631209046,11602712.14133687317371368 962976.22210006194654852,11602840.09838385321199894 967742.62210006208624691,11603208.23603074997663498 967742.62210006208624691,11604513.11028097197413445 967742.62210006208624691)),((11584503.3406173400580883 970315.28251079504843801,11583079.11276544444262981 965472.9078143477672711,11584280.59107660688459873 961387.88155639520846307,11575362.08419401571154594 961841.36495720490347594,11575644.1196969747543335 966380.79352863342501223,11577177.85562258772552013 966380.79352863342501223,11577674.00869971700012684 971200.56627789419144392,11584503.3406173400580883 970315.28251079504843801)))
"""
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
class TestQgsGeometryAvoidIntersections(TestCase):
class TestQgsGeometryAvoidIntersections(unittest.TestCase):
def testNoSliverPolygons(self):

View File

@ -23,37 +23,43 @@ __copyright__ = '(C) 2015, Matthias Kuhn'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
import qgis
import os
from PyQt.QtCore import QSize
from qgis.core import (QgsVectorLayer,
QgsSingleSymbolRendererV2,
QgsFillSymbolV2,
QgsLineSymbolV2,
QgsMarkerSymbolV2,
QgsMapLayerRegistry,
QgsRectangle,
QgsGeometryGeneratorSymbolLayerV2,
QgsSymbolV2,
QgsMultiRenderChecker
)
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest
)
from qgis.core import (
QgsVectorLayer,
QgsSingleSymbolRendererV2,
QgsFillSymbolV2,
QgsLineSymbolV2,
QgsMarkerSymbolV2,
QgsMapLayerRegistry,
QgsRectangle,
QgsGeometryGeneratorSymbolLayerV2,
QgsSymbolV2,
QgsMultiRenderChecker
)
from qgis.testing import (
start_app,
unittest
)
from qgis.testing.mocked import get_iface
from utilities import unitTestDataPath
# Convenience instances in case you may need them
# not used in this test
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
TEST_DATA_DIR = unitTestDataPath()
class TestQgsGeometryGeneratorSymbolLayerV2(TestCase):
class TestQgsGeometryGeneratorSymbolLayerV2(unittest.TestCase):
def setUp(self):
self.iface = get_iface()
polys_shp = os.path.join(TEST_DATA_DIR, 'polys.shp')
points_shp = os.path.join(TEST_DATA_DIR, 'points.shp')
lines_shp = os.path.join(TEST_DATA_DIR, 'lines.shp')
@ -73,7 +79,7 @@ class TestQgsGeometryGeneratorSymbolLayerV2(TestCase):
self.lines_layer.setRendererV2(QgsSingleSymbolRendererV2(sym2))
self.points_layer.setRendererV2(QgsSingleSymbolRendererV2(sym3))
self.mapsettings = CANVAS.mapSettings()
self.mapsettings = self.iface.mapCanvas().mapSettings()
self.mapsettings.setOutputSize(QSize(400, 400))
self.mapsettings.setOutputDpi(96)
self.mapsettings.setExtent(QgsRectangle(-133, 22, -70, 52))

View File

@ -14,10 +14,9 @@ __revision__ = '$Format:%H$'
import qgis
from utilities import (unittest,
TestCase,
getQgisTestApp,
)
from qgis.testing import (unittest,
start_app,
)
from qgis.core import (QgsGraduatedSymbolRendererV2,
QgsRendererRangeV2,
QgsRendererRangeV2LabelFormat,
@ -35,7 +34,7 @@ from PyQt4.QtCore import Qt
from PyQt4.QtXml import QDomDocument
from PyQt4.QtGui import QColor
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
#===========================================================
# Utility functions
@ -156,7 +155,7 @@ def dumpGraduatedRenderer(r):
# Tests
class TestQgsGraduatedSymbolRendererV2(TestCase):
class TestQgsGraduatedSymbolRendererV2(unittest.TestCase):
def testQgsRendererRangeV2_1(self):
"""Test QgsRendererRangeV2 getter/setter functions"""

View File

@ -17,22 +17,21 @@ import os
from qgis.core import QgsPoint, QgsVectorLayer
from utilities import (getQgisTestApp,
TestCase,
unittest
)
from qgis.testing import (start_app,
unittest
)
from pyspatialite import dbapi2 as sqlite3
# Convenience instances in case you may need them
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
def die(error_message):
raise Exception(error_message)
class TestQgsSpatialiteProvider(TestCase):
class TestQgsSpatialiteProvider(unittest.TestCase):
@classmethod
def setUpClass(cls):

View File

@ -20,16 +20,20 @@ from qgis.core import (QGis,
QgsLayerDefinition
)
from utilities import (TestCase, unittest, getQgisTestApp, unitTestDataPath)
from qgis.testing import (
unittest,
start_app
)
from utilities import unitTestDataPath
from PyQt4.QtCore import QVariant
from PyQt4.QtXml import QDomDocument
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
TEST_DATA_DIR = unitTestDataPath()
class TestQgsLayerDefinition(TestCase):
class TestQgsLayerDefinition(unittest.TestCase):
def testDependency(self):
inDoc = """

View File

@ -21,15 +21,15 @@ os.environ['QGIS_DEBUG'] = '2'
os.environ['QGIS_LOG_FILE'] = myFilename
from qgis.core import QgsLogger
from utilities import TestCase, unittest
from qgis.testing import TestCase, unittest
# Convenience instances in case you may need them
# not used in this test
#from utilities import getQgisTestApp
#QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
#from qgis.testing import start_app
#start_app()
class TestQgsLogger(TestCase):
class TestQgsLogger(unittest.TestCase):
def testLogger(self):
try:

View File

@ -12,8 +12,8 @@ __copyright__ = 'Copyright 2015, The QGIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
import unittest
from qgis.core import QgsMapLayerRegistry
from qgis.testing import unittest
class TestQgsMapLayerRegistry(unittest.TestCase):

View File

@ -16,10 +16,10 @@ import qgis
from qgis.core import (QgsMapUnitScale, QgsRenderContext, QgsSymbolLayerV2Utils, QgsSymbolV2, QgsMapSettings, QgsRectangle)
from PyQt4.QtCore import QSize
from utilities import (TestCase, unittest)
from qgis.testing import (TestCase, unittest)
class PyQgsMapUnitScale(TestCase):
class PyQgsMapUnitScale(unittest.TestCase):
def testConstructor(self):
# test creating QgsMapUnitScale

View File

@ -14,9 +14,10 @@ __revision__ = '$Format:%H$'
import qgis
import os
from utilities import unittest, TestCase, unitTestDataPath
from qgis.testing import unittest
from qgis.utils import qgsfunction
from qgis.core import QgsNetworkContentFetcher
from utilities import unitTestDataPath
from PyQt4.QtCore import QUrl, QCoreApplication
from PyQt4.QtNetwork import QNetworkReply
import SocketServer
@ -24,7 +25,7 @@ import threading
import SimpleHTTPServer
class TestQgsNetworkContentFetcher(TestCase):
class TestQgsNetworkContentFetcher(unittest.TestCase):
@classmethod
def setUpClass(cls):

View File

@ -41,10 +41,14 @@ from qgis.core import (
QgsMultiRenderChecker
)
from qgis.testing import (
start_app,
unittest
)
from qgis.testing.mocked import get_iface
from utilities import (
getQgisTestApp,
TestCase,
unittest,
unitTestDataPath,
getTempfilePath,
renderMapToImage,
@ -54,7 +58,7 @@ from utilities import (
)
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
FONTSLOADED = loadTestFonts()
PALREPORT = 'PAL_REPORT' in os.environ
@ -62,7 +66,7 @@ PALREPORTS = {}
# noinspection PyPep8Naming,PyShadowingNames
class TestQgsPalLabeling(TestCase):
class TestQgsPalLabeling(unittest.TestCase):
_TestDataDir = unitTestDataPath()
_PalDataDir = os.path.join(_TestDataDir, 'labeling')
@ -87,9 +91,9 @@ class TestQgsPalLabeling(TestCase):
def setUpClass(cls):
"""Run before all tests"""
# qgis instances
cls._QgisApp, cls._Canvas, cls._Iface, cls._Parent = \
QGISAPP, CANVAS, IFACE, PARENT
# qgis iface
cls._Iface = get_iface()
cls._Canvas = cls._Iface.mapCanvas()
# verify that spatialite provider is available
msg = '\nSpatialite provider not found, SKIPPING TEST SUITE'

View File

@ -24,7 +24,7 @@ from PyQt4.QtCore import Qt, QPointF, QThreadPool
from PyQt4.QtGui import QFont
from qgis.core import QgsPalLayerSettings, QgsSingleSymbolRendererV2, QgsMarkerSymbolV2
from unittest import skip
from utilities import (
svgSymbolsPath,
getTempfilePath,

View File

@ -16,12 +16,12 @@ import qgis
from qgis.core import QgsPoint
from utilities import getQgisTestApp, TestCase, unittest
from qgis.testing import start_app, unittest
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
class TestQgsPoint(TestCase):
class TestQgsPoint(unittest.TestCase):
def __init__(self, methodName):
"""Run once on class initialisation."""

View File

@ -16,12 +16,12 @@ import qgis
from qgis.core import QgsProject, QgsMessageLog
from utilities import getQgisTestApp, TestCase, unittest
from qgis.testing import start_app, unittest
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
class TestQgsProject(TestCase):
class TestQgsProject(unittest.TestCase):
def __init__(self, methodName):
"""Run once on class initialisation."""

View File

@ -21,15 +21,14 @@ from qgis.gui import QgsEditorWidgetRegistry
from PyQt4 import QtCore, QtGui
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest
)
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
from qgis.testing import (start_app,
unittest
)
from utilities import unitTestDataPath
start_app()
class TestQgsRangeWidget(TestCase):
class TestQgsRangeWidget(unittest.TestCase):
@classmethod
def setUpClass(cls):

View File

@ -23,18 +23,16 @@ from qgis.core import (QgsRasterLayer,
QgsRasterPipe,
QgsRasterFileWriter,
QgsRasterProjector)
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest
# expectedFailure
)
# Convenience instances in case you may need them
# not used in this test
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
from qgis.testing import (start_app,
unittest)
from utilities import unitTestDataPath
start_app()
class TestQgsRasterFileWriter(TestCase):
class TestQgsRasterFileWriter(unittest.TestCase):
def __init__(self, methodName):
unittest.TestCase.__init__(self, methodName)

View File

@ -14,7 +14,6 @@ __revision__ = '$Format:%H$'
import qgis
import os
import unittest
from PyQt4.QtCore import QFileInfo, QObject, SIGNAL
from PyQt4 import QtGui
@ -31,16 +30,17 @@ from qgis.core import (QgsRaster,
QgsRenderChecker,
QgsSingleBandGrayRenderer,
QgsSingleBandPseudoColorRenderer)
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase)
from utilities import unitTestDataPath
from qgis.testing import (start_app,
unittest
)
# Convenience instances in case you may need them
# not used in this test
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
class TestQgsRasterLayer(TestCase):
class TestQgsRasterLayer(unittest.TestCase):
def testIdentify(self):
myPath = os.path.join(unitTestDataPath(), 'landsat.tif')

View File

@ -16,21 +16,23 @@ import qgis
from qgis.core import QgsRectangle, QgsPoint
from utilities import (getQgisTestApp,
compareWkt,
TestCase,
unittest,
expectedFailure
)
from qgis.testing import (
start_app,
unittest
)
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
from utilities import (
compareWkt
)
start_app()
class TestQgsRectangle(TestCase):
class TestQgsRectangle(unittest.TestCase):
# Because isEmpty() is not returning expected result in 9b0fee3
@expectedFailure
@unittest.expectedFailure
def testCtor(self):
rect = QgsRectangle(5.0, 5.0, 10.0, 10.0)

View File

@ -21,12 +21,11 @@ from qgis.core import (QgsVectorLayer,
QgsPoint,
QgsMapLayerRegistry
)
from utilities import (getQgisTestApp,
TestCase,
unittest
)
from qgis.testing import (start_app,
unittest
)
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
def createReferencingLayer():
@ -70,7 +69,7 @@ def formatAttributes(attrs):
return repr([unicode(a) for a in attrs])
class TestQgsRelation(TestCase):
class TestQgsRelation(unittest.TestCase):
def setUp(self):
self.referencedLayer = createReferencedLayer()

View File

@ -53,16 +53,14 @@ from PyQt.QtGui import (
from time import sleep
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest,
expectedFailure
)
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
from qgis.testing import (start_app,
unittest
)
from utilities import unitTestDataPath
start_app()
class TestQgsRelationEditWidget(TestCase):
class TestQgsRelationEditWidget(unittest.TestCase):
@classmethod
def setUpClass(cls):
@ -147,7 +145,7 @@ class TestQgsRelationEditWidget(TestCase):
self.assertEquals(self.table_view.model().rowCount(), 4)
@expectedFailure
@unittest.expectedFailure
def test_add_feature(self):
"""
Check if a new related feature is added
@ -199,7 +197,7 @@ class TestQgsRelationEditWidget(TestCase):
self.assertEquals(self.table_view.model().rowCount(), 1)
@expectedFailure
@unittest.expectedFailure
def test_unlink_feature(self):
"""
Check if a linked feature can be unlinked

View File

@ -40,20 +40,23 @@ from qgis.core import (QgsVectorLayer,
QgsGraduatedSymbolRendererV2,
QgsRendererRangeV2
)
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest
)
from qgis.testing import (start_app,
unittest
)
from qgis.testing.mocked import get_iface
from utilities import unitTestDataPath
# Convenience instances in case you may need them
# not used in this test
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
TEST_DATA_DIR = unitTestDataPath()
class TestQgsRulebasedRenderer(TestCase):
class TestQgsRulebasedRenderer(unittest.TestCase):
def setUp(self):
self.iface = get_iface()
myShpFile = os.path.join(TEST_DATA_DIR, 'rectangles.shp')
layer = QgsVectorLayer(myShpFile, 'Points', 'ogr')
QgsMapLayerRegistry.instance().addMapLayer(layer)
@ -74,7 +77,7 @@ class TestQgsRulebasedRenderer(TestCase):
self.renderer = QgsRuleBasedRendererV2(self.rootrule)
layer.setRendererV2(self.renderer)
self.mapsettings = CANVAS.mapSettings()
self.mapsettings = self.iface.mapCanvas().mapSettings()
self.mapsettings.setOutputSize(QSize(400, 400))
self.mapsettings.setOutputDpi(96)
self.mapsettings.setExtent(QgsRectangle(-163, 22, -70, 52))

View File

@ -14,12 +14,12 @@ __revision__ = '$Format:%H$'
import os
import re
import unittest
import urllib
from mimetools import Message
from StringIO import StringIO
from qgis.server import QgsServer
from qgis.core import QgsMessageLog
from qgis.testing import unittest
from utilities import unitTestDataPath
# Strip path and content length because path may vary

View File

@ -18,7 +18,7 @@ import os
from shutil import copyfile
from math import sqrt
from subprocess import check_output
from unittest import TestCase, main
from qgis.testing import unittest
from utilities import unitTestDataPath
from osgeo import gdal
from osgeo.gdalconst import GA_ReadOnly
@ -155,7 +155,7 @@ accesscontrol = RestrictedAccessControl(server_iface)
server_iface.registerAccessControl(accesscontrol, 100)
class TestQgsServerAccessControl(TestCase):
class TestQgsServerAccessControl(unittest.TestCase):
def setUp(self):
self.testdata_path = unitTestDataPath("qgis_server_accesscontrol")
@ -1105,4 +1105,4 @@ class TestQgsServerAccessControl(TestCase):
"Wrong color in result\n%s" % response)
if __name__ == "__main__":
main()
unittest.main()

View File

@ -41,20 +41,24 @@ from qgis.core import (QgsVectorLayer,
QgsRendererRangeV2,
QgsFeatureRequest
)
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest
)
from qgis.testing import (start_app,
unittest
)
from qgis.testing.mocked import get_iface
from utilities import unitTestDataPath
# Convenience instances in case you may need them
# not used in this test
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
TEST_DATA_DIR = unitTestDataPath()
class TestQgsSingleSymbolRenderer(TestCase):
class TestQgsSingleSymbolRenderer(unittest.TestCase):
def setUp(self):
self.iface = get_iface()
myShpFile = os.path.join(TEST_DATA_DIR, 'polys_overlapping.shp')
layer = QgsVectorLayer(myShpFile, 'Polys', 'ogr')
QgsMapLayerRegistry.instance().addMapLayer(layer)
@ -66,7 +70,7 @@ class TestQgsSingleSymbolRenderer(TestCase):
layer.setRendererV2(self.renderer)
rendered_layers = [layer.id()]
self.mapsettings = CANVAS.mapSettings()
self.mapsettings = self.iface.mapCanvas().mapSettings()
self.mapsettings.setOutputSize(QSize(400, 400))
self.mapsettings.setOutputDpi(96)
self.mapsettings.setExtent(QgsRectangle(-163, 22, -70, 52))

View File

@ -13,12 +13,9 @@ __copyright__ = 'Copyright 2015, The QGIS Project'
__revision__ = '$Format:%H$'
import os
from utilities import (TestCase,
unittest,
printImportant,
DoxygenParser)
from qgis.testing import unittest
from PyQt4.QtCore import qDebug
from utilities import printImportant, DoxygenParser
# Import all the things!
from qgis.analysis import *
@ -41,7 +38,7 @@ ACCEPTABLE_MISSING_CLASSES = 0
ACCEPTABLE_MISSING_MEMBERS = 0
class TestQgsSipCoverage(TestCase):
class TestQgsSipCoverage(unittest.TestCase):
def testCoverage(self):
print 'CTEST_FULL_OUTPUT'

View File

@ -13,7 +13,6 @@ __copyright__ = 'Copyright 2012, The QGIS Project'
__revision__ = '$Format:%H$'
import qgis
import unittest
from qgis.core import (QgsSpatialIndex,
QgsFeature,
@ -21,9 +20,11 @@ from qgis.core import (QgsSpatialIndex,
QgsRectangle,
QgsPoint)
from utilities import getQgisTestApp
from qgis.testing import (start_app,
unittest
)
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
class TestQgsSpatialIndex(unittest.TestCase):

View File

@ -28,39 +28,43 @@ import os
from PyQt4.QtCore import QSize
from qgis.core import (QgsVectorLayer,
QgsMapLayerRegistry,
QgsRectangle,
QgsMultiRenderChecker,
QgsSingleSymbolRendererV2,
QgsFillSymbolV2,
QgsMarkerSymbolV2,
QgsRendererCategoryV2,
QgsCategorizedSymbolRendererV2,
QgsGraduatedSymbolRendererV2,
QgsRendererRangeV2,
QgsFeatureRequest
)
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest
)
# Convenience instances in case you may need them
# not used in this test
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
from qgis.core import (
QgsVectorLayer,
QgsMapLayerRegistry,
QgsRectangle,
QgsMultiRenderChecker,
QgsSingleSymbolRendererV2,
QgsFillSymbolV2,
QgsMarkerSymbolV2,
QgsRendererCategoryV2,
QgsCategorizedSymbolRendererV2,
QgsGraduatedSymbolRendererV2,
QgsRendererRangeV2,
QgsFeatureRequest
)
from qgis.testing import (
unittest,
start_app
)
from qgis.testing.mocked import get_iface
from utilities import unitTestDataPath
start_app()
TEST_DATA_DIR = unitTestDataPath()
class TestQgsSymbolExpressionVariables(TestCase):
class TestQgsSymbolExpressionVariables(unittest.TestCase):
def setUp(self):
myShpFile = os.path.join(TEST_DATA_DIR, 'polys.shp')
self.layer = QgsVectorLayer(myShpFile, 'Polys', 'ogr')
QgsMapLayerRegistry.instance().addMapLayer(self.layer)
self.iface = get_iface()
rendered_layers = [self.layer.id()]
self.mapsettings = CANVAS.mapSettings()
self.mapsettings = self.iface.mapCanvas().mapSettings()
self.mapsettings.setOutputSize(QSize(400, 400))
self.mapsettings.setOutputDpi(96)
self.mapsettings.setExtent(QgsRectangle(-163, 22, -70, 52))

View File

@ -50,33 +50,31 @@ from qgis.core import (QgsCentroidFillSymbolLayerV2,
QgsVectorFieldSymbolLayer,
QgsSymbolV2,
)
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest,
expectedFailure
)
from qgis.testing import (start_app,
unittest
)
from utilities import unitTestDataPath
# Convenience instances in case you may need them
# not used in this test
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
start_app()
class TestQgsSymbolLayerV2(TestCase):
class TestQgsSymbolLayerV2(unittest.TestCase):
'''
This class test the sip binding for QgsSymbolLayerV2 descendants
Every class is tested using the createFromSld implementation
An exception is done for:
- QgsLinePatternFillSymbolLayer where createFromSld implementation
returns NULL
- QgsPointPatternFillSymbolLayer where createFromSld implementation
returns NULL
- QgsVectorFieldSymbolLayer where createFromSld implementation
returns NULL
'''
"""
This class test the sip binding for QgsSymbolLayerV2 descendants
Every class is tested using the createFromSld implementation
An exception is done for:
- QgsLinePatternFillSymbolLayer where createFromSld implementation
returns NULL
- QgsPointPatternFillSymbolLayer where createFromSld implementation
returns NULL
- QgsVectorFieldSymbolLayer where createFromSld implementation
returns NULL
"""
def testBinding(self):
'''Test python bindings existance.'''
"""Test python bindings existance."""
mType = type(QgsSymbolLayerV2)
mExpectedType = pyqtWrapperType
mMessage = 'Expected "%s" got "%s"' % (mExpectedType, mType)
@ -211,8 +209,8 @@ class TestQgsSymbolLayerV2(TestCase):
assert mExpectedType == mType, mMessage
def testQgsSimpleFillSymbolLayerV2(self):
'''Create a new style from a .sld file and match test.
'''
"""Create a new style from a .sld file and match test.
"""
mTestName = 'QgsSimpleFillSymbolLayerV2'
mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.sld' % (unitTestDataPath(), mTestName))
@ -250,8 +248,8 @@ class TestQgsSymbolLayerV2(TestCase):
assert mExpectedValue == mValue, mMessage
def testQgsGradientFillSymbolLayerV2(self):
'''Test setting and getting QgsGradientFillSymbolLayerV2 properties.
'''
"""Test setting and getting QgsGradientFillSymbolLayerV2 properties.
"""
mGradientLayer = QgsGradientFillSymbolLayerV2()
mExpectedValue = type(QgsGradientFillSymbolLayerV2())
@ -332,9 +330,9 @@ class TestQgsSymbolLayerV2(TestCase):
assert mExpectedValue == mValue, mMessage
def testQgsCentroidFillSymbolLayerV2(self):
'''
"""
Create a new style from a .sld file and match test
'''
"""
mTestName = 'QgsCentroidFillSymbolLayerV2'
mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.sld' % (unitTestDataPath(), mTestName))
@ -367,9 +365,9 @@ class TestQgsSymbolLayerV2(TestCase):
assert mExpectedValue == mValue, mMessage
def testQgsLinePatternFillSymbolLayer(self):
'''
"""
Create a new style from a .sld file and match test
'''
"""
mTestName = 'QgsLinePatternFillSymbolLayer'
mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.sld' % (unitTestDataPath(), mTestName))
@ -406,11 +404,11 @@ class TestQgsSymbolLayerV2(TestCase):
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
@expectedFailure
@unittest.expectedFailure
def testQgsPointPatternFillSymbolLayer(self):
'''
"""
Create a new style from a .sld file and match test
'''
"""
# at the moment there is an empty createFromSld implementation
# that return nulls
mTestName = 'QgsPointPatternFillSymbolLayer'
@ -455,9 +453,9 @@ class TestQgsSymbolLayerV2(TestCase):
assert mExpectedValue == mValue, mMessage
def testQgsSVGFillSymbolLayer(self):
'''
"""
Create a new style from a .sld file and match test
'''
"""
mTestName = 'QgsSVGFillSymbolLayer'
mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.sld' % (unitTestDataPath(), mTestName))
@ -485,9 +483,9 @@ class TestQgsSymbolLayerV2(TestCase):
assert mExpectedValue == mValue, mMessage
def testQgsMarkerLineSymbolLayerV2(self):
'''
"""
Create a new style from a .sld file and match test
'''
"""
mTestName = 'QgsMarkerLineSymbolLayerV2'
mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.sld' % (unitTestDataPath(), mTestName))
@ -525,9 +523,9 @@ class TestQgsSymbolLayerV2(TestCase):
assert mExpectedValue == mValue, mMessage
def testQgsSimpleLineSymbolLayerV2(self):
'''
"""
Create a new style from a .sld file and match test
'''
"""
mTestName = 'QgsSimpleLineSymbolLayerV2'
mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.sld' % (unitTestDataPath(), mTestName))
@ -575,9 +573,9 @@ class TestQgsSymbolLayerV2(TestCase):
assert mExpectedValue == mValue, mMessage
def testQgsEllipseSymbolLayerV2(self):
'''
"""
Create a new style from a .sld file and match test
'''
"""
mTestName = 'QgsEllipseSymbolLayerV2'
mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.sld' % (unitTestDataPath(), mTestName))
@ -620,9 +618,9 @@ class TestQgsSymbolLayerV2(TestCase):
assert mExpectedValue == mValue, mMessage
def testQgsFontMarkerSymbolLayerV2(self):
'''
"""
Create a new style from a .sld file and match test
'''
"""
mTestName = 'QgsFontMarkerSymbolLayerV2'
mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.sld' % (unitTestDataPath(), mTestName))
@ -660,9 +658,9 @@ class TestQgsSymbolLayerV2(TestCase):
assert mExpectedValue == mValue, mMessage
def testQgsSvgMarkerSymbolLayerV2(self):
'''
"""
Create a new style from a .sld file and match test
'''
"""
mTestName = 'QgsSvgMarkerSymbolLayerV2'
mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.sld' % (unitTestDataPath(), mTestName))

View File

@ -26,12 +26,7 @@ __revision__ = '$Format:%H$'
import os
import csv
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest,
expectedFailure
)
from utilities import unitTestDataPath
from PyQt4.QtCore import QSize, QDir
from PyQt4.QtGui import QImage, QColor, QPainter
@ -48,11 +43,17 @@ from qgis.core import (QgsGeometry,
QgsRenderChecker
)
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
from qgis.testing import(
unittest,
start_app
)
start_app()
TEST_DATA_DIR = unitTestDataPath()
class TestQgsSymbolV2(TestCase):
class TestQgsSymbolV2(unittest.TestCase):
def setUp(self):
#Create some simple symbols

View File

@ -20,10 +20,10 @@ from qgis.core import (QgsVectorGradientColorRampV2,
QgsRandomColorsV2,
QgsVectorColorBrewerColorRampV2)
from PyQt4.QtGui import QColor, QGradient
from utilities import (TestCase, unittest)
from qgis.testing import (TestCase, unittest)
class PyQgsVectorColorRamp(TestCase):
class PyQgsVectorColorRamp(unittest.TestCase):
def testQgsVectorRandomColorRampV2(self):
# test gradient with only start/end color

View File

@ -24,15 +24,17 @@ from qgis.core import (QgsVectorLayer,
)
from PyQt4.QtCore import QDate, QTime, QDateTime, QVariant, QDir
import os
from utilities import (getQgisTestApp,
TestCase,
unittest,
writeShape
)
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
from qgis.testing import (
start_app,
unittest
)
from utilities import writeShape
start_app()
class TestQgsVectorLayer(TestCase):
class TestQgsVectorLayer(unittest.TestCase):
mMemoryLayer = None

View File

@ -30,12 +30,11 @@ from qgis.core import (QGis,
QgsVectorJoinInfo,
QgsSymbolV2,
QgsSingleSymbolRendererV2)
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest,
)
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
from qgis.testing import (start_app,
unittest
)
from utilities import unitTestDataPath
start_app()
def createEmptyLayer():
@ -102,7 +101,7 @@ def dumpEditBuffer(layer):
print "%d | %s" % (f.id(), f.geometry().exportToWkt())
class TestQgsVectorLayer(TestCase):
class TestQgsVectorLayer(unittest.TestCase):
def test_FeatureCount(self):
myPath = os.path.join(unitTestDataPath(), 'lines.shp')

View File

@ -21,12 +21,12 @@ from qgis.core import (QGis,
QgsVirtualLayerDefinition
)
from utilities import (TestCase, unittest)
from qgis.testing import (TestCase, unittest)
from PyQt4.QtCore import QVariant, QUrl
class TestQgsVirtualLayerDefinition(TestCase):
class TestQgsVirtualLayerDefinition(unittest.TestCase):
def test1(self):
d = QgsVirtualLayerDefinition()

View File

@ -19,16 +19,17 @@ from PyQt4.QtCore import QDir, QFile
from qgis.core import QgsVectorLayer, QgsFeature, QgsFeatureRequest
from qgis.analysis import QgsZonalStatistics
from utilities import (
unitTestDataPath,
getQgisTestApp,
TestCase,
unittest)
from qgis.testing import (
start_app,
unittest
)
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
from utilities import unitTestDataPath
start_app()
class TestQgsZonalStatistics(TestCase):
class TestQgsZonalStatistics(unittest.TestCase):
"""Tests for zonal stats class."""

View File

@ -14,10 +14,9 @@ __revision__ = '$Format:%H$'
import qgis
from utilities import (unittest,
TestCase,
getQgisTestApp
)
from qgis.testing import (unittest,
start_app
)
from qgis.core import (edit,
QgsFeature,
QgsGeometry,
@ -25,10 +24,10 @@ from qgis.core import (edit,
QgsEditError
)
getQgisTestApp()
start_app()
class TestSyntacticSugar(TestCase):
class TestSyntacticSugar(unittest.TestCase):
def testEdit(self):
"""Test `with edit(layer):` code"""

View File

@ -32,7 +32,7 @@ from qgis.core import (
QgsFontUtils
)
from qgis.gui import QgsMapCanvas
from qgis_interface import QgisInterface
from qgis.testing import start_app
import hashlib
import re
try:
@ -43,24 +43,6 @@ except ImportError:
import webbrowser
import subprocess
# Support python < 2.7 via unittest2 needed for expected failure decorator.
# Note that you should ignore unused import warnings here as these are imported
# from this module by other tests.
if sys.version_info[0:2] < (2, 7):
try:
from unittest2 import TestCase, expectedFailure
import unittest2 as unittest
except ImportError:
print("You should install unittest2 to run the salt tests")
sys.exit(0)
else:
from unittest import TestCase, expectedFailure
import unittest
QGISAPP = None # Static variable used to hold hand to running QGis app
CANVAS = None
PARENT = None
IFACE = None
GEOCRS = 4326 # constant for EPSG:GEOCRS Geographic CRS id
FONTSLOADED = False
@ -98,56 +80,6 @@ def hashForFile(theFilename):
return myHash
def getQgisTestApp():
""" Start one QGis application to test agaist
Input
NIL
Output
handle to qgis app
If QGis is already running the handle to that app will be returned
"""
global QGISAPP # pylint: disable=W0603
if QGISAPP is None:
myGuiFlag = True # All test will run qgis in gui mode
# In python3 we need to conver to a bytes object (or should
# QgsApplication accept a QString instead of const char* ?)
try:
argvb = list(map(os.fsencode, sys.argv))
except AttributeError:
argvb = sys.argv
# Note: QGIS_PREFIX_PATH is evaluated in QgsApplication -
# no need to mess with it here.
QGISAPP = QgsApplication(argvb, myGuiFlag)
QGISAPP.initQgis()
s = QGISAPP.showSettings()
print(s)
global PARENT # pylint: disable=W0603
if PARENT is None:
PARENT = QWidget()
global CANVAS # pylint: disable=W0603
if CANVAS is None:
CANVAS = QgsMapCanvas(PARENT)
CANVAS.resize(QSize(400, 400))
global IFACE # pylint: disable=W0603
if IFACE is None:
# QgisInterface is a stub implementation of the QGIS plugin interface
IFACE = QgisInterface(CANVAS)
return QGISAPP, CANVAS, IFACE, PARENT
def unitTestDataPath(theSubdir=None):
"""Return the absolute path to the QGIS unit test data dir.
@ -377,8 +309,7 @@ def getTestFont(style='Roman', size=12):
def loadTestFonts():
if QGISAPP is None:
getQgisTestApp()
start_app()
global FONTSLOADED # pylint: disable=W0603
if FONTSLOADED is False: