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
def setUpClass(cls): """Run before all tests""" QCoreApplication.setOrganizationName("QGIS_Test") QCoreApplication.setOrganizationDomain("QGIS_TestPyQgsColorScheme.com") QCoreApplication.setApplicationName("QGIS_TestPyQgsColorScheme") QSettings().clear() start_app()
def setUpClass(cls): start_app() from processing.core.Processing import Processing Processing.initialize() cls.cleanup_paths = [] assert Grass7Utils.installedVersion()
def setUpClass(cls): start_app() from processing.core.Processing import Processing Processing.initialize() cls.cleanup_paths = [] cls.in_place_layers = {} cls.vector_layer_params = {}
def setUpClass(cls): """Run before all tests""" QCoreApplication.setOrganizationName("QGIS_Test") QCoreApplication.setOrganizationDomain("QGIS_TestPyQgsColorScheme.com") QCoreApplication.setApplicationName("QGIS_TestPyQgsColorScheme") QgsSettings().clear() start_app() # setup some fake connections settings = QgsSettings() key = 'qgis/connections-wms/test/' settings.setValue(key + 'url', 'aaa.bbb.com') settings.setValue(key + 'referer', 'my_ref') settings.setValue(key + 'ignoreGetMapURI', True) settings.setValue(key + 'ignoreGetFeatureInfoURI', True) settings.setValue(key + 'smoothPixmapTransform', True) settings.setValue(key + 'dpiMode', 4) settings.setValue(key + 'ignoreAxisOrientation', True) settings.setValue(key + 'invertAxisOrientation', True) key = 'qgis/connections-wfs/test/' settings.setValue(key + 'url', 'ccc.ddd.com') settings.setValue(key + 'version', '1.1.0') settings.setValue(key + 'maxnumfeatures', '47') settings.setValue(key + 'ignoreAxisOrientation', True) settings.setValue(key + 'invertAxisOrientation', True)
def setUpClass(cls): """Run before all tests""" QCoreApplication.setOrganizationName("QGIS_Test") QCoreApplication.setOrganizationDomain("QGIS_TestPyQgsWFSProviderGUI.com") QCoreApplication.setApplicationName("QGIS_TestPyQgsWFSProviderGUI") QgsSettings().clear() start_app()
def setUpClass(cls): start_app() from processing.core.Processing import Processing Processing.initialize() QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms()) cls.cleanup_paths = [] cls.in_place_layers = {} cls.vector_layer_params = {}
def setUpClass(cls): """Run before all tests""" QCoreApplication.setOrganizationName("QGIS_Test") QCoreApplication.setOrganizationDomain("QGIS_TestPyQgsColorScheme.com") QCoreApplication.setApplicationName("QGIS_TestPyQgsColorScheme") QgsSettings().clear() QLocale.setDefault(QLocale(QLocale.English)) start_app()
def setUpClass(cls): """Run before all tests""" QCoreApplication.setOrganizationName("QGIS_Test") QCoreApplication.setOrganizationDomain("QGIS_TestPyQgsNewGeoPackageLayerDialog.com") QCoreApplication.setApplicationName("QGIS_TestPyQgsNewGeoPackageLayerDialog") QgsSettings().clear() start_app() cls.basetestpath = tempfile.mkdtemp()
def setUpClass(cls): start_app() from processing.core.Processing import Processing Processing.initialize() cls.cleanup_paths = [] cls.temp_dir = tempfile.mkdtemp() cls.cleanup_paths.append(cls.temp_dir)
def setUpClass(cls): """Run before all tests""" QCoreApplication.setOrganizationName("QGIS_Test") QCoreApplication.setOrganizationDomain("QGIS_TestPyQgsWFSProviderGUI.com") QCoreApplication.setApplicationName("QGIS_TestPyQgsWFSProviderGUI") QSettings().clear() start_app() cls.basetestpath = tempfile.mkdtemp().replace('\\', '/')
def setUpClass(cls): start_app() from processing.core.Processing import Processing Processing.initialize() ProcessingConfig.setSettingValue(ModelerUtils.MODELS_FOLDER, os.path.join(os.path.dirname(__file__), 'models')) QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms()) cls.cleanup_paths = [] cls.in_place_layers = {} cls.vector_layer_params = {} cls._original_models_folder = ProcessingConfig.getSetting(ModelerUtils.MODELS_FOLDER)
def setUpClass(cls): QCoreApplication.setOrganizationName("QGIS_Test") QCoreApplication.setOrganizationDomain("QGIS_TestPyQgsFontUtils.com") QCoreApplication.setApplicationName("QGIS_TestPyQgsFontUtils") QgsSettings().clear() start_app() cls._family = getTestFontFamily() cls._has_style = QgsFontUtils.fontFamilyHasStyle
def setUpClass(cls): """Run before all tests""" QCoreApplication.setOrganizationName("QGIS_Test") QCoreApplication.setOrganizationDomain("TestPyQgsOGRProviderGpkg.com") QCoreApplication.setApplicationName("TestPyQgsOGRProviderGpkg") QgsSettings().clear() start_app() # Create test layer cls.basetestpath = tempfile.mkdtemp()
def setUpClass(cls): """Run before all tests""" # start ans setup server cls.setUpServer() # start a standalone qgis application QCoreApplication.setOrganizationName("QGIS_Test") QCoreApplication.setOrganizationDomain("TestPyQgsDBManagerPostgis.com") QCoreApplication.setApplicationName("TestPyQgsDBManagerPostgis") QgsSettings().clear() start_app()
def loadTestFonts(): start_app() global FONTSLOADED # pylint: disable=W0603 if FONTSLOADED is False: QgsFontUtils.loadStandardTestFonts(['Roman', 'Bold']) msg = getTestFontFamily() + ' base test font styles could not be loaded' res = (QgsFontUtils.fontFamilyHasStyle(getTestFontFamily(), 'Roman') and QgsFontUtils.fontFamilyHasStyle(getTestFontFamily(), 'Bold')) assert res, msg FONTSLOADED = True
def loadTestFonts(): start_app() global FONTSLOADED # pylint: disable=W0603 if FONTSLOADED is False: QgsFontUtils.loadStandardTestFonts(["Roman", "Bold"]) msg = getTestFontFamily() + " base test font styles could not be loaded" res = QgsFontUtils.fontFamilyHasStyle(getTestFontFamily(), "Roman") and QgsFontUtils.fontFamilyHasStyle( getTestFontFamily(), "Bold" ) assert res, msg FONTSLOADED = True
def setUpClass(cls): start_app() from processing.core.Processing import Processing Processing.initialize() ProcessingConfig.setSettingValue("OTB_ACTIVATE", True) ProcessingConfig.setSettingValue(OtbSettings.FOLDER, OTB_INSTALL_DIR) ProcessingConfig.setSettingValue(OtbSettings.APP_FOLDER, os.path.join(OTB_INSTALL_DIR, 'lib', 'otb', 'applications')) ProcessingConfig.readSettings() # Refresh OTB Algorithms after settings are changed. for p in QgsApplication.processingRegistry().providers(): if p.id() == "otb": p.refreshAlgorithms() cls.descrFolder = os.path.join(OTB_INSTALL_DIR, 'share', 'otb', 'description') cls.cleanup_paths = []
def setUpClass(cls): """Runs at start.""" QCoreApplication.setOrganizationName("QGIS") QCoreApplication.setOrganizationDomain("qgis.org") QCoreApplication.setApplicationName("QGIS-TEST-%s" % uuid.uuid1()) qgis_app = start_app() # Installed plugins cls.installed_plugins = { 'MetaSearch': '0.3.5', 'QuickWKT': '3.1', 'db_manager': '0.1.20', 'firstaid': '2.1.1', 'InaSAFE': '5.0.0', 'ipyconsole': '1.8', 'plugin_reloader': '0.7.4', 'processing': '2.12.99', 'qgis-geocoding': '2.18', 'qgisce': '0.9', 'redistrict': '0.1' } data_path = os.path.join(TESTDATA_PATH, 'plugindependencies_data.json') with open(data_path) as f: cls.plugin_data = json.loads(f.read())
def setUpClass(cls): """Run before all tests""" QCoreApplication.setOrganizationName("QGIS_Test") QCoreApplication.setOrganizationDomain("TestPyQgsDBManagerGpkg.com") QCoreApplication.setApplicationName("TestPyQgsDBManagerGpkg") QSettings().clear() start_app() cls.basetestpath = tempfile.mkdtemp() cls.test_gpkg = os.path.join(cls.basetestpath, 'TestPyQgsDBManagerGpkg.gpkg') ds = ogr.GetDriverByName('GPKG').CreateDataSource(cls.test_gpkg) lyr = ds.CreateLayer('testLayer', geom_type=ogr.wkbLineString, options=['SPATIAL_INDEX=NO']) cls.supportsAlterFieldDefn = lyr.TestCapability(ogr.OLCAlterFieldDefn) == 1 lyr.CreateField(ogr.FieldDefn('text_field', ogr.OFTString)) f = ogr.Feature(lyr.GetLayerDefn()) f['text_field'] = 'foo' f.SetGeometry(ogr.CreateGeometryFromWkt('LINESTRING(1 2,3 4)')) lyr.CreateFeature(f) f = None ds = None
def setUpClass(cls): """Run before all tests""" QCoreApplication.setOrganizationName("QGIS_Test") QCoreApplication.setOrganizationDomain("QGIS_TestPyQgsColorScheme.com") QCoreApplication.setApplicationName("QGIS_TestPyQgsColorScheme") QgsSettings().clear() start_app() # setup a fake connection settings = QgsSettings() key = QgsGeoNodeConnectionUtils.pathGeoNodeConnection() + '/test/' settings.setValue(key + 'wms/referer', 'my_ref') settings.setValue(key + 'wms/ignoreGetMapURI', True) settings.setValue(key + 'wms/ignoreGetFeatureInfoURI', True) settings.setValue(key + 'wms/smoothPixmapTransform', True) settings.setValue(key + 'wms/dpiMode', 4) settings.setValue(key + 'wms/ignoreAxisOrientation', True) settings.setValue(key + 'wms/invertAxisOrientation', True) settings.setValue(key + 'wfs/version', '1.1.0') settings.setValue(key + 'wfs/maxnumfeatures', '47') settings.setValue(key + 'wfs/ignoreAxisOrientation', True) settings.setValue(key + 'wfs/invertAxisOrientation', True)
def qgis_app(): """Start a QGIS application and get the iface. Mostly inspired by https://github.com/qgis/QGIS/blob/release-2_18/python/testing/mocked.py The application is returned as first argument. The QgisInterface is returned as second argument. The parent can be accessed by iface.mainWindow() The canvas can be access by iface.mapCanvas() 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. :return: The QGIS interface. :rtype: QgisInterface """ from qgis.utils import iface if iface: # We are already in QGIS. # I don't know if I can get the current QApplication. # But I guess we shouldn't use it too much. return None, iface # We are not in QGIS, we need to start an app. application = 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 application, my_iface
def setUpClass(cls): start_app() from processing.core.Processing import Processing Processing.initialize() cls.cleanup_paths = []
QgsVectorLayerUtils, QgsSettings, QgsTransactionGroup, QgsReadWriteContext, QgsRectangle, QgsDefaultValue, QgsDataSourceUri ) from qgis.gui import QgsGui from qgis.PyQt.QtCore import QDate, QTime, QDateTime, QVariant, QDir, QObject from qgis.testing import start_app, unittest from qgis.PyQt.QtXml import QDomDocument from utilities import unitTestDataPath from providertestbase import ProviderTestCase QGISAPP = start_app() TEST_DATA_DIR = unitTestDataPath() class TestPyQgsPostgresProvider(unittest.TestCase, ProviderTestCase): @classmethod def setUpClass(cls): """Run before all tests""" cls.dbconn = 'dbname=\'qgis_test\'' if 'QGIS_PGTEST_DB' in os.environ: cls.dbconn = os.environ['QGIS_PGTEST_DB'] # Create test layers cls.vl = QgsVectorLayer(cls.dbconn + ' sslmode=disable key=\'pk\' srid=4326 type=POINT table="qgis_test"."someData" (geom) sql=', 'test', 'postgres') assert cls.vl.isValid() cls.source = cls.vl.dataProvider()
) from qgis.testing import start_app, unittest from qgis.testing.mocked import get_iface from utilities import ( unitTestDataPath, getTempfilePath, renderMapToImage, loadTestFonts, getTestFont, openInBrowserTab ) start_app(sys.platform != 'darwin') # No cleanup on mac os x, it crashes the pallabellingcanvas test on exit FONTSLOADED = loadTestFonts() PALREPORT = 'PAL_REPORT' in os.environ PALREPORTS = {} # noinspection PyPep8Naming,PyShadowingNames class TestQgsPalLabeling(unittest.TestCase): _TestDataDir = unitTestDataPath() _PalDataDir = os.path.join(_TestDataDir, 'labeling') _PalFeaturesDb = os.path.join(_PalDataDir, 'pal_features_v3.sqlite') _TestFont = getTestFont() # Roman at 12 pt """:type: QFont""" _MapRegistry = None
from qgis.core import (QgsCoordinateReferenceSystem, QgsCoordinateTransform, QgsDataSourceUri, QgsGeometry, QgsLabelingEngineSettings, QgsProject, QgsMapSettings, QgsPalLabeling, QgsPalLayerSettings, QgsProviderRegistry, QgsStringReplacementCollection, QgsVectorLayer, QgsVectorLayerSimpleLabeling, QgsMultiRenderChecker, QgsUnitTypes) from qgis.testing import start_app, unittest from qgis.testing.mocked import get_iface from utilities import (unitTestDataPath, getTempfilePath, renderMapToImage, loadTestFonts, getTestFont, openInBrowserTab) start_app( sys.platform != 'darwin' ) # No cleanup on mac os x, it crashes the pallabelingcanvas test on exit FONTSLOADED = loadTestFonts() PALREPORT = 'PAL_REPORT' in os.environ PALREPORTS = {} # noinspection PyPep8Naming,PyShadowingNames class TestQgsPalLabeling(unittest.TestCase): _TestDataDir = unitTestDataPath() _PalDataDir = os.path.join(_TestDataDir, 'labeling') _PalFeaturesDb = os.path.join(_PalDataDir, 'pal_features_v3.sqlite') _TestFont = getTestFont() # Roman at 12 pt """:type: QFont"""
# This will get replaced with a git SHA1 when you do a git archive __revision__ = '61137dc8bf7bc7d8a5e7401442e2af6bd88c19e0' QGIS_POSTGRES_SERVER_PORT = os.environ.get('QGIS_POSTGRES_SERVER_PORT', '55432') QGIS_POSTGRES_EXECUTABLE_PATH = os.environ.get('QGIS_POSTGRES_EXECUTABLE_PATH', '/usr/lib/postgresql/9.4/bin') assert os.path.exists(QGIS_POSTGRES_EXECUTABLE_PATH) QGIS_AUTH_DB_DIR_PATH = tempfile.mkdtemp() # Postgres test path QGIS_PG_TEST_PATH = tempfile.mkdtemp() os.environ['QGIS_AUTH_DB_DIR_PATH'] = QGIS_AUTH_DB_DIR_PATH qgis_app = start_app() QGIS_POSTGRES_CONF_TEMPLATE = """ hba_file = '%(tempfolder)s/pg_hba.conf' listen_addresses = '*' port = %(port)s max_connections = 100 unix_socket_directories = '%(tempfolder)s' ssl = true ssl_ciphers = 'DEFAULT:!LOW:!EXP:!MD5:@STRENGTH' # allowed SSL ciphers ssl_cert_file = '%(server_cert)s' ssl_key_file = '%(server_key)s' ssl_ca_file = '%(sslrootcert_path)s' password_encryption = on """
QgsDataProvider, QgsReadWriteContext, QgsCoordinateReferenceSystem, ) from qgis.gui import (QgsLayerTreeMapCanvasBridge, QgsMapCanvas) from qgis.PyQt.QtGui import QFont, QColor from qgis.PyQt.QtTest import QSignalSpy from qgis.PyQt.QtCore import QT_VERSION_STR, QTemporaryDir, QSize from qgis.PyQt.QtXml import QDomDocument, QDomNode from qgis.testing import start_app, unittest from utilities import (unitTestDataPath, renderMapToImage) from shutil import copyfile app = start_app() TEST_DATA_DIR = unitTestDataPath() class TestQgsProjectBadLayers(unittest.TestCase): def setUp(self): p = QgsProject.instance() p.removeAllMapLayers() @classmethod def getBaseMapSettings(cls): """ :rtype: QgsMapSettings """ ms = QgsMapSettings() crs = QgsCoordinateReferenceSystem()
__author__ = 'Nyall Dawson' __date__ = '04/06/2017' __copyright__ = 'Copyright 2017, The QGIS Project' # This will get replaced with a git SHA1 when you do a git archive __revision__ = 'f4599f13f179ac2d36bcc44468d3d0b918c2bb77' import qgis # NOQA from qgis.core import QgsTextFormat from qgis.gui import QgsFontButton, QgsMapCanvas from qgis.testing import start_app, unittest from qgis.PyQt.QtGui import QColor, QFont from qgis.PyQt.QtTest import QSignalSpy from utilities import getTestFont start_app() class TestQgsFontButton(unittest.TestCase): def testGettersSetters(self): button = QgsFontButton() canvas = QgsMapCanvas() button.setDialogTitle('test title') self.assertEqual(button.dialogTitle(), 'test title') button.setMapCanvas(canvas) self.assertEqual(button.mapCanvas(), canvas) def testSetGetFormat(self): button = QgsFontButton()
QgsRectangle, QgsTextFormat, QgsVectorLayer, QgsVectorLayerSimpleLabeling, QgsFeature, QgsGeometry, QgsMapSettings, QgsPointXY) from qgis.testing import start_app, unittest from qgis.PyQt.QtCore import QSize, QThreadPool from qgis.PyQt.QtGui import QPainter, QImage from qgis.PyQt.QtTest import QSignalSpy from random import uniform app = start_app() class TestQgsMapRenderer(unittest.TestCase): def setUp(self): pass def tearDown(self): # avoid crash on finish, probably related to https://bugreports.qt.io/browse/QTBUG-35760 QThreadPool.globalInstance().waitForDone() def checkRendererUseCachedLabels(self, job_type): layer = QgsVectorLayer("Point?field=fldtxt:string", "layer1", "memory")
def setUpClass(cls): """Run before all tests""" QCoreApplication.setOrganizationName("QGIS_Test") QCoreApplication.setOrganizationDomain("TestPyQgsAFSProvider.com") QCoreApplication.setApplicationName("TestPyQgsAFSProvider") QgsSettings().clear() start_app() # On Windows we must make sure that any backslash in the path is # replaced by a forward slash so that QUrl can process it cls.basetestpath = tempfile.mkdtemp().replace('\\', '/') endpoint = cls.basetestpath + '/fake_qgis_http_endpoint' with open(sanitize(endpoint, '?f=json'), 'wb') as f: f.write(""" {"currentVersion":10.22,"id":1,"name":"QGIS Test","type":"Feature Layer","description": "QGIS Provider Test Layer.\n","geometryType":"esriGeometryPoint","copyrightText":"","parentLayer":{"id":0,"name":"QGIS Tests"},"subLayers":[], "minScale":72225,"maxScale":0, "defaultVisibility":true, "extent":{"xmin":-71.123,"ymin":66.33,"xmax":-65.32,"ymax":78.3, "spatialReference":{"wkid":4326,"latestWkid":4326}}, "hasAttachments":false,"htmlPopupType":"esriServerHTMLPopupTypeAsHTMLText", "displayField":"LABEL","typeIdField":null, "fields":[{"name":"OBJECTID","type":"esriFieldTypeOID","alias":"OBJECTID","domain":null}, {"name":"pk","type":"esriFieldTypeInteger","alias":"pk","domain":null}, {"name":"cnt","type":"esriFieldTypeInteger","alias":"cnt","domain":null}, {"name":"name","type":"esriFieldTypeString","alias":"name","length":100,"domain":null}, {"name":"name2","type":"esriFieldTypeString","alias":"name2","length":100,"domain":null}, {"name":"num_char","type":"esriFieldTypeString","alias":"num_char","length":100,"domain":null}, {"name":"Shape","type":"esriFieldTypeGeometry","alias":"Shape","domain":null}], "relationships":[],"canModifyLayer":false,"canScaleSymbols":false,"hasLabels":false, "capabilities":"Map,Query,Data","maxRecordCount":1000,"supportsStatistics":true, "supportsAdvancedQueries":true,"supportedQueryFormats":"JSON, AMF", "ownershipBasedAccessControlForFeatures":{"allowOthersToQuery":true},"useStandardizedQueries":true}""" .encode('UTF-8')) with open( sanitize( endpoint, '/query?f=json_where=OBJECTID=OBJECTID_returnIdsOnly=true' ), 'wb') as f: f.write(""" { "objectIdFieldName": "OBJECTID", "objectIds": [ 5, 3, 1, 2, 4 ] } """.encode('UTF-8')) # Create test layer cls.vl = QgsVectorLayer( "url='http://" + endpoint + "' crs='epsg:4326'", 'test', 'arcgisfeatureserver') assert cls.vl.isValid() cls.source = cls.vl.dataProvider() with open( sanitize( endpoint, '/query?f=json&objectIds=5,3,1,2,4&inSR=4326&outSR=4326&returnGeometry=true&outFields=OBJECTID,pk,cnt,name,name2,num_char&returnM=false&returnZ=false' ), 'wb') as f: f.write(""" { "displayFieldName": "name", "fieldAliases": { "name": "name" }, "geometryType": "esriGeometryPoint", "spatialReference": { "wkid": 4326, "latestWkid": 4326 }, "fields":[{"name":"OBJECTID","type":"esriFieldTypeOID","alias":"OBJECTID","domain":null}, {"name":"pk","type":"esriFieldTypeInteger","alias":"pk","domain":null}, {"name":"cnt","type":"esriFieldTypeInteger","alias":"cnt","domain":null}, {"name":"name","type":"esriFieldTypeString","alias":"name","length":100,"domain":null}, {"name":"name2","type":"esriFieldTypeString","alias":"name2","length":100,"domain":null}, {"name":"num_char","type":"esriFieldTypeString","alias":"num_char","length":100,"domain":null}, {"name":"Shape","type":"esriFieldTypeGeometry","alias":"Shape","domain":null}], "features": [ { "attributes": { "OBJECTID": 5, "pk": 5, "cnt": -200, "name": null, "name2":"NuLl", "num_char":"5" }, "geometry": { "x": -71.123, "y": 78.23 } }, { "attributes": { "OBJECTID": 3, "pk": 3, "cnt": 300, "name": "Pear", "name2":"PEaR", "num_char":"3" }, "geometry": null }, { "attributes": { "OBJECTID": 1, "pk": 1, "cnt": 100, "name": "Orange", "name2":"oranGe", "num_char":"1" }, "geometry": { "x": -70.332, "y": 66.33 } }, { "attributes": { "OBJECTID": 2, "pk": 2, "cnt": 200, "name": "Apple", "name2":"Apple", "num_char":"2" }, "geometry": { "x": -68.2, "y": 70.8 } }, { "attributes": { "OBJECTID": 4, "pk": 4, "cnt": 400, "name": "Honey", "name2":"Honey", "num_char":"4" }, "geometry": { "x": -65.32, "y": 78.3 } } ] }""".encode('UTF-8')) with open( sanitize( endpoint, '/query?f=json&objectIds=5,3,1,2,4&inSR=4326&outSR=4326&returnGeometry=true&outFields=OBJECTID,pk,cnt,name,name2,num_char&returnM=false&returnZ=false&geometry=-71.123000,66.330000,-65.320000,78.300000&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelEnvelopeIntersects' ), 'wb') as f: f.write(""" { "displayFieldName": "name", "fieldAliases": { "name": "name" }, "geometryType": "esriGeometryPoint", "spatialReference": { "wkid": 4326, "latestWkid": 4326 }, "fields":[{"name":"OBJECTID","type":"esriFieldTypeOID","alias":"OBJECTID","domain":null}, {"name":"pk","type":"esriFieldTypeInteger","alias":"pk","domain":null}, {"name":"cnt","type":"esriFieldTypeInteger","alias":"cnt","domain":null}, {"name":"name","type":"esriFieldTypeString","alias":"name","length":100,"domain":null}, {"name":"name2","type":"esriFieldTypeString","alias":"name2","length":100,"domain":null}, {"name":"num_char","type":"esriFieldTypeString","alias":"num_char","length":100,"domain":null}, {"name":"Shape","type":"esriFieldTypeGeometry","alias":"Shape","domain":null}], "features": [ { "attributes": { "OBJECTID": 5, "pk": 5, "cnt": -200, "name": null, "name2":"NuLl", "num_char":"5" }, "geometry": { "x": -71.123, "y": 78.23 } }, { "attributes": { "OBJECTID": 3, "pk": 3, "cnt": 300, "name": "Pear", "name2":"PEaR", "num_char":"3" }, "geometry": null }, { "attributes": { "OBJECTID": 1, "pk": 1, "cnt": 100, "name": "Orange", "name2":"oranGe", "num_char":"1" }, "geometry": { "x": -70.332, "y": 66.33 } }, { "attributes": { "OBJECTID": 2, "pk": 2, "cnt": 200, "name": "Apple", "name2":"Apple", "num_char":"2" }, "geometry": { "x": -68.2, "y": 70.8 } }, { "attributes": { "OBJECTID": 4, "pk": 4, "cnt": 400, "name": "Honey", "name2":"Honey", "num_char":"4" }, "geometry": { "x": -65.32, "y": 78.3 } } ] }""".encode('UTF-8')) with open( sanitize( endpoint, '/query?f=json&where=OBJECTID=OBJECTID&returnIdsOnly=true&geometry=-70.000000,67.000000,-60.000000,80.000000&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelEnvelopeIntersects' ), 'wb') as f: f.write(""" { "objectIdFieldName": "OBJECTID", "objectIds": [ 2, 4 ] } """.encode('UTF-8')) with open( sanitize( endpoint, '/query?f=json&where=OBJECTID=OBJECTID&returnIdsOnly=true&geometry=-73.000000,70.000000,-63.000000,80.000000&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelEnvelopeIntersects' ), 'wb') as f: f.write(""" { "objectIdFieldName": "OBJECTID", "objectIds": [ 2, 4 ] } """.encode('UTF-8')) with open( sanitize( endpoint, '/query?f=json&where=OBJECTID=OBJECTID&returnIdsOnly=true&geometry=-68.721119,68.177676,-64.678700,79.123755&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelEnvelopeIntersects' ), 'wb') as f: f.write(""" { "objectIdFieldName": "OBJECTID", "objectIds": [ 2, 4 ] } """.encode('UTF-8'))
QgsProject, QgsFieldConstraints, QgsVectorLayerUtils, QgsSettings, QgsDefaultValue, QgsWkbTypes) from qgis.testing import start_app, unittest from utilities import unitTestDataPath from providertestbase import ProviderTestCase from qgis.PyQt.QtCore import QObject, QVariant from qgis.utils import spatialite_connect # Pass no_exit=True: for some reason this crashes sometimes on exit on Travis start_app(True) TEST_DATA_DIR = unitTestDataPath() def count_opened_filedescriptors(filename_to_test): count = -1 if sys.platform.startswith('linux'): count = 0 open_files_dirname = '/proc/%d/fd' % os.getpid() filenames = os.listdir(open_files_dirname) for filename in filenames: full_filename = open_files_dirname + '/' + filename if os.path.exists(full_filename): link = os.readlink(full_filename) if os.path.basename(link) == os.path.basename(filename_to_test): count += 1
# This will get replaced with a git SHA1 when you do a git archive __revision__ = '74d30b95b968b386c4bad257206acb14c59efd5c' QGIS_POSTGRES_SERVER_PORT = os.environ.get('QGIS_POSTGRES_SERVER_PORT', '55432') QGIS_POSTGRES_EXECUTABLE_PATH = os.environ.get('QGIS_POSTGRES_EXECUTABLE_PATH', '/usr/lib/postgresql/9.4/bin') assert os.path.exists(QGIS_POSTGRES_EXECUTABLE_PATH) QGIS_AUTH_DB_DIR_PATH = tempfile.mkdtemp() # Postgres test path QGIS_PG_TEST_PATH = tempfile.mkdtemp() os.environ['QGIS_AUTH_DB_DIR_PATH'] = QGIS_AUTH_DB_DIR_PATH qgis_app = start_app() QGIS_POSTGRES_CONF_TEMPLATE = """ hba_file = '%(tempfolder)s/pg_hba.conf' listen_addresses = '*' port = %(port)s max_connections = 100 unix_socket_directories = '%(tempfolder)s' ssl = true ssl_ciphers = 'DEFAULT:!LOW:!EXP:!MD5:@STRENGTH' # allowed SSL ciphers ssl_cert_file = '%(server_cert)s' ssl_key_file = '%(server_key)s' ssl_ca_file = '%(sslrootcert_path)s' password_encryption = on """
def setUpClass(cls): """Run before all tests""" QCoreApplication.setOrganizationName("QGIS_Test") QCoreApplication.setOrganizationDomain("TestPyQgsAFSProvider.com") QCoreApplication.setApplicationName("TestPyQgsAFSProvider") QgsSettings().clear() start_app() # On Windows we must make sure that any backslash in the path is # replaced by a forward slash so that QUrl can process it cls.basetestpath = tempfile.mkdtemp().replace('\\', '/') endpoint = cls.basetestpath + '/fake_qgis_http_endpoint' with open(sanitize(endpoint, '?f=json'), 'wb') as f: f.write(""" {"currentVersion":10.22,"id":1,"name":"QGIS Test","type":"Feature Layer","description": "QGIS Provider Test Layer.\n","geometryType":"esriGeometryPoint","copyrightText":"","parentLayer":{"id":0,"name":"QGIS Tests"},"subLayers":[], "minScale":72225,"maxScale":0, "defaultVisibility":true, "extent":{"xmin":-71.123,"ymin":66.33,"xmax":-65.32,"ymax":78.3, "spatialReference":{"wkid":4326,"latestWkid":4326}}, "hasAttachments":false,"htmlPopupType":"esriServerHTMLPopupTypeAsHTMLText", "displayField":"LABEL","typeIdField":null, "fields":[{"name":"OBJECTID","type":"esriFieldTypeOID","alias":"OBJECTID","domain":null}, {"name":"pk","type":"esriFieldTypeInteger","alias":"pk","domain":null}, {"name":"cnt","type":"esriFieldTypeInteger","alias":"cnt","domain":null}, {"name":"name","type":"esriFieldTypeString","alias":"name","length":100,"domain":null}, {"name":"name2","type":"esriFieldTypeString","alias":"name2","length":100,"domain":null}, {"name":"num_char","type":"esriFieldTypeString","alias":"num_char","length":100,"domain":null}, {"name":"Shape","type":"esriFieldTypeGeometry","alias":"Shape","domain":null}], "relationships":[],"canModifyLayer":false,"canScaleSymbols":false,"hasLabels":false, "capabilities":"Map,Query,Data","maxRecordCount":1000,"supportsStatistics":true, "supportsAdvancedQueries":true,"supportedQueryFormats":"JSON, AMF", "ownershipBasedAccessControlForFeatures":{"allowOthersToQuery":true},"useStandardizedQueries":true}""".encode('UTF-8')) with open(sanitize(endpoint, '/query?f=json_where=OBJECTID=OBJECTID_returnIdsOnly=true'), 'wb') as f: f.write(""" { "objectIdFieldName": "OBJECTID", "objectIds": [ 5, 3, 1, 2, 4 ] } """.encode('UTF-8')) # Create test layer cls.vl = QgsVectorLayer("url='http://" + endpoint + "' crs='epsg:4326'", 'test', 'arcgisfeatureserver') assert cls.vl.isValid() cls.source = cls.vl.dataProvider() with open(sanitize(endpoint, '/query?f=json&objectIds=5,3,1,2,4&inSR=4326&outSR=4326&returnGeometry=true&outFields=OBJECTID,pk,cnt,name,name2,num_char&returnM=false&returnZ=false'), 'wb') as f: f.write(""" { "displayFieldName": "name", "fieldAliases": { "name": "name" }, "geometryType": "esriGeometryPoint", "spatialReference": { "wkid": 4326, "latestWkid": 4326 }, "fields":[{"name":"OBJECTID","type":"esriFieldTypeOID","alias":"OBJECTID","domain":null}, {"name":"pk","type":"esriFieldTypeInteger","alias":"pk","domain":null}, {"name":"cnt","type":"esriFieldTypeInteger","alias":"cnt","domain":null}, {"name":"name","type":"esriFieldTypeString","alias":"name","length":100,"domain":null}, {"name":"name2","type":"esriFieldTypeString","alias":"name2","length":100,"domain":null}, {"name":"num_char","type":"esriFieldTypeString","alias":"num_char","length":100,"domain":null}, {"name":"Shape","type":"esriFieldTypeGeometry","alias":"Shape","domain":null}], "features": [ { "attributes": { "OBJECTID": 5, "pk": 5, "cnt": -200, "name": null, "name2":"NuLl", "num_char":"5" }, "geometry": { "x": -71.123, "y": 78.23 } }, { "attributes": { "OBJECTID": 3, "pk": 3, "cnt": 300, "name": "Pear", "name2":"PEaR", "num_char":"3" }, "geometry": null }, { "attributes": { "OBJECTID": 1, "pk": 1, "cnt": 100, "name": "Orange", "name2":"oranGe", "num_char":"1" }, "geometry": { "x": -70.332, "y": 66.33 } }, { "attributes": { "OBJECTID": 2, "pk": 2, "cnt": 200, "name": "Apple", "name2":"Apple", "num_char":"2" }, "geometry": { "x": -68.2, "y": 70.8 } }, { "attributes": { "OBJECTID": 4, "pk": 4, "cnt": 400, "name": "Honey", "name2":"Honey", "num_char":"4" }, "geometry": { "x": -65.32, "y": 78.3 } } ] }""".encode('UTF-8')) with open(sanitize(endpoint, '/query?f=json&objectIds=5,3,1,2,4&inSR=4326&outSR=4326&returnGeometry=true&outFields=OBJECTID,pk,cnt,name,name2,num_char&returnM=false&returnZ=false&geometry=-71.123000,66.330000,-65.320000,78.300000&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelEnvelopeIntersects'), 'wb') as f: f.write(""" { "displayFieldName": "name", "fieldAliases": { "name": "name" }, "geometryType": "esriGeometryPoint", "spatialReference": { "wkid": 4326, "latestWkid": 4326 }, "fields":[{"name":"OBJECTID","type":"esriFieldTypeOID","alias":"OBJECTID","domain":null}, {"name":"pk","type":"esriFieldTypeInteger","alias":"pk","domain":null}, {"name":"cnt","type":"esriFieldTypeInteger","alias":"cnt","domain":null}, {"name":"name","type":"esriFieldTypeString","alias":"name","length":100,"domain":null}, {"name":"name2","type":"esriFieldTypeString","alias":"name2","length":100,"domain":null}, {"name":"num_char","type":"esriFieldTypeString","alias":"num_char","length":100,"domain":null}, {"name":"Shape","type":"esriFieldTypeGeometry","alias":"Shape","domain":null}], "features": [ { "attributes": { "OBJECTID": 5, "pk": 5, "cnt": -200, "name": null, "name2":"NuLl", "num_char":"5" }, "geometry": { "x": -71.123, "y": 78.23 } }, { "attributes": { "OBJECTID": 3, "pk": 3, "cnt": 300, "name": "Pear", "name2":"PEaR", "num_char":"3" }, "geometry": null }, { "attributes": { "OBJECTID": 1, "pk": 1, "cnt": 100, "name": "Orange", "name2":"oranGe", "num_char":"1" }, "geometry": { "x": -70.332, "y": 66.33 } }, { "attributes": { "OBJECTID": 2, "pk": 2, "cnt": 200, "name": "Apple", "name2":"Apple", "num_char":"2" }, "geometry": { "x": -68.2, "y": 70.8 } }, { "attributes": { "OBJECTID": 4, "pk": 4, "cnt": 400, "name": "Honey", "name2":"Honey", "num_char":"4" }, "geometry": { "x": -65.32, "y": 78.3 } } ] }""".encode('UTF-8')) with open(sanitize(endpoint, '/query?f=json&objectIds=2,4&inSR=4326&outSR=4326&returnGeometry=true&outFields=OBJECTID,pk,cnt,name,name2,num_char&returnM=false&returnZ=false'), 'wb') as f: f.write(""" { "displayFieldName": "name", "fieldAliases": { "name": "name" }, "geometryType": "esriGeometryPoint", "spatialReference": { "wkid": 4326, "latestWkid": 4326 }, "fields":[{"name":"OBJECTID","type":"esriFieldTypeOID","alias":"OBJECTID","domain":null}, {"name":"pk","type":"esriFieldTypeInteger","alias":"pk","domain":null}, {"name":"cnt","type":"esriFieldTypeInteger","alias":"cnt","domain":null}, {"name":"name","type":"esriFieldTypeString","alias":"name","length":100,"domain":null}, {"name":"name2","type":"esriFieldTypeString","alias":"name2","length":100,"domain":null}, {"name":"num_char","type":"esriFieldTypeString","alias":"num_char","length":100,"domain":null}, {"name":"Shape","type":"esriFieldTypeGeometry","alias":"Shape","domain":null}], "features": [ { "attributes": { "OBJECTID": 2, "pk": 2, "cnt": 200, "name": "Apple", "name2":"Apple", "num_char":"2" }, "geometry": { "x": -68.2, "y": 70.8 } }, { "attributes": { "OBJECTID": 4, "pk": 4, "cnt": 400, "name": "Honey", "name2":"Honey", "num_char":"4" }, "geometry": { "x": -65.32, "y": 78.3 } } ] }""".encode('UTF-8')) with open(sanitize(endpoint, '/query?f=json&where=OBJECTID=OBJECTID&returnIdsOnly=true&geometry=-70.000000,67.000000,-60.000000,80.000000&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelEnvelopeIntersects'), 'wb') as f: f.write(""" { "objectIdFieldName": "OBJECTID", "objectIds": [ 2, 4 ] } """.encode('UTF-8')) with open(sanitize(endpoint, '/query?f=json&where=OBJECTID=OBJECTID&returnIdsOnly=true&geometry=-73.000000,70.000000,-63.000000,80.000000&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelEnvelopeIntersects'), 'wb') as f: f.write(""" { "objectIdFieldName": "OBJECTID", "objectIds": [ 2, 4 ] } """.encode('UTF-8')) with open(sanitize(endpoint, '/query?f=json&where=OBJECTID=OBJECTID&returnIdsOnly=true&geometry=-68.721119,68.177676,-64.678700,79.123755&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelEnvelopeIntersects'), 'wb') as f: f.write(""" { "objectIdFieldName": "OBJECTID", "objectIds": [ 2, 4 ] } """.encode('UTF-8'))
# This will get replaced with a git SHA1 when you do a git archive __revision__ = '3fef9cd19637b0e37f8fc1cf5350776d68ce0401' from qgis.testing import start_app, unittest from qgis.core import (QgsProcessingModelAlgorithm, QgsProcessingModelParameter, QgsProcessingParameterString, QgsProcessingParameterNumber, QgsProcessingParameterDistance, QgsProcessingParameterField, QgsProcessingParameterFile) from processing.modeler.ModelerParametersDialog import (ModelerParametersDialog) start_app() class ModelerTest(unittest.TestCase): def testModelerParametersDialogAvailableValuesOfType(self): # test getAvailableValuesOfType from ModelerParametersDialog m = QgsProcessingModelAlgorithm() string_param_1 = QgsProcessingModelParameter('string') m.addModelParameter(QgsProcessingParameterString('string'), string_param_1) string_param_2 = QgsProcessingModelParameter('string2') m.addModelParameter(QgsProcessingParameterString('string2'), string_param_2)
def setUpClass(cls): """Run before all tests""" QCoreApplication.setOrganizationName("QGIS_Test") QCoreApplication.setOrganizationDomain(cls.__name__) QCoreApplication.setApplicationName(cls.__name__) start_app()