Plugin generated via plugin builder
This commit is contained in:
2
test/__init__.py
Normal file
2
test/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# import qgis libs so that ve set the correct sip api version
|
||||
import qgis # pylint: disable=W0611 # NOQA
|
205
test/qgis_interface.py
Normal file
205
test/qgis_interface.py
Normal file
@@ -0,0 +1,205 @@
|
||||
# coding=utf-8
|
||||
"""QGIS plugin implementation.
|
||||
|
||||
.. note:: 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.
|
||||
|
||||
.. note:: This source code was copied from the 'postgis viewer' application
|
||||
with original authors:
|
||||
Copyright (c) 2010 by Ivan Mincik, ivan.mincik@gista.sk
|
||||
Copyright (c) 2011 German Carrillo, geotux_tuxman@linuxmail.org
|
||||
Copyright (c) 2014 Tim Sutton, tim@linfiniti.com
|
||||
|
||||
"""
|
||||
|
||||
__author__ = 'tim@linfiniti.com'
|
||||
__revision__ = '$Format:%H$'
|
||||
__date__ = '10/01/2011'
|
||||
__copyright__ = (
|
||||
'Copyright (c) 2010 by Ivan Mincik, ivan.mincik@gista.sk and '
|
||||
'Copyright (c) 2011 German Carrillo, geotux_tuxman@linuxmail.org'
|
||||
'Copyright (c) 2014 Tim Sutton, tim@linfiniti.com'
|
||||
)
|
||||
|
||||
import logging
|
||||
from qgis.PyQt.QtCore import QObject, pyqtSlot, pyqtSignal
|
||||
from qgis.core import QgsMapLayerRegistry
|
||||
from qgis.gui import QgsMapCanvasLayer
|
||||
LOGGER = logging.getLogger('QGIS')
|
||||
|
||||
|
||||
#noinspection PyMethodMayBeStatic,PyPep8Naming
|
||||
class QgisInterface(QObject):
|
||||
"""Class to expose QGIS objects and functions to plugins.
|
||||
|
||||
This class is here for enabling us to run unit tests only,
|
||||
so most methods are simply stubs.
|
||||
"""
|
||||
currentLayerChanged = pyqtSignal(QgsMapCanvasLayer)
|
||||
|
||||
def __init__(self, canvas):
|
||||
"""Constructor
|
||||
:param canvas:
|
||||
"""
|
||||
QObject.__init__(self)
|
||||
self.canvas = canvas
|
||||
# Set up slots so we can mimic the behaviour of QGIS when layers
|
||||
# are added.
|
||||
LOGGER.debug('Initialising canvas...')
|
||||
# noinspection PyArgumentList
|
||||
QgsMapLayerRegistry.instance().layersAdded.connect(self.addLayers)
|
||||
# noinspection PyArgumentList
|
||||
QgsMapLayerRegistry.instance().layerWasAdded.connect(self.addLayer)
|
||||
# noinspection PyArgumentList
|
||||
QgsMapLayerRegistry.instance().removeAll.connect(self.removeAllLayers)
|
||||
|
||||
# For processing module
|
||||
self.destCrs = None
|
||||
|
||||
@pyqtSlot('QStringList')
|
||||
def addLayers(self, layers):
|
||||
"""Handle layers being added to the registry so they show up in canvas.
|
||||
|
||||
:param layers: list<QgsMapLayer> list of map layers that were added
|
||||
|
||||
.. note:: The QgsInterface api does not include this method,
|
||||
it is added here as a helper to facilitate testing.
|
||||
"""
|
||||
#LOGGER.debug('addLayers called on qgis_interface')
|
||||
#LOGGER.debug('Number of layers being added: %s' % len(layers))
|
||||
#LOGGER.debug('Layer Count Before: %s' % len(self.canvas.layers()))
|
||||
current_layers = self.canvas.layers()
|
||||
final_layers = []
|
||||
for layer in current_layers:
|
||||
final_layers.append(QgsMapCanvasLayer(layer))
|
||||
for layer in layers:
|
||||
final_layers.append(QgsMapCanvasLayer(layer))
|
||||
|
||||
self.canvas.setLayerSet(final_layers)
|
||||
#LOGGER.debug('Layer Count After: %s' % len(self.canvas.layers()))
|
||||
|
||||
@pyqtSlot('QgsMapLayer')
|
||||
def addLayer(self, layer):
|
||||
"""Handle a layer being added to the registry so it shows up in canvas.
|
||||
|
||||
:param layer: list<QgsMapLayer> list of map layers that were added
|
||||
|
||||
.. note: The QgsInterface api does not include this method, it is added
|
||||
here as a helper to facilitate testing.
|
||||
|
||||
.. note: The addLayer method was deprecated in QGIS 1.8 so you should
|
||||
not need this method much.
|
||||
"""
|
||||
pass
|
||||
|
||||
@pyqtSlot()
|
||||
def removeAllLayers(self):
|
||||
"""Remove layers from the canvas before they get deleted."""
|
||||
self.canvas.setLayerSet([])
|
||||
|
||||
def newProject(self):
|
||||
"""Create new project."""
|
||||
# noinspection PyArgumentList
|
||||
QgsMapLayerRegistry.instance().removeAllMapLayers()
|
||||
|
||||
# ---------------- API Mock for QgsInterface follows -------------------
|
||||
|
||||
def zoomFull(self):
|
||||
"""Zoom to the map full extent."""
|
||||
pass
|
||||
|
||||
def zoomToPrevious(self):
|
||||
"""Zoom to previous view extent."""
|
||||
pass
|
||||
|
||||
def zoomToNext(self):
|
||||
"""Zoom to next view extent."""
|
||||
pass
|
||||
|
||||
def zoomToActiveLayer(self):
|
||||
"""Zoom to extent of active layer."""
|
||||
pass
|
||||
|
||||
def addVectorLayer(self, path, base_name, provider_key):
|
||||
"""Add a vector layer.
|
||||
|
||||
:param path: Path to layer.
|
||||
:type path: str
|
||||
|
||||
:param base_name: Base name for layer.
|
||||
:type base_name: str
|
||||
|
||||
:param provider_key: Provider key e.g. 'ogr'
|
||||
:type provider_key: str
|
||||
"""
|
||||
pass
|
||||
|
||||
def addRasterLayer(self, path, base_name):
|
||||
"""Add a raster layer given a raster layer file name
|
||||
|
||||
:param path: Path to layer.
|
||||
:type path: str
|
||||
|
||||
:param base_name: Base name for layer.
|
||||
:type base_name: str
|
||||
"""
|
||||
pass
|
||||
|
||||
def activeLayer(self):
|
||||
"""Get pointer to the active layer (layer selected in the legend)."""
|
||||
# noinspection PyArgumentList
|
||||
layers = QgsMapLayerRegistry.instance().mapLayers()
|
||||
for item in layers:
|
||||
return layers[item]
|
||||
|
||||
def addToolBarIcon(self, action):
|
||||
"""Add an icon to the plugins toolbar.
|
||||
|
||||
:param action: Action to add to the toolbar.
|
||||
:type action: QAction
|
||||
"""
|
||||
pass
|
||||
|
||||
def removeToolBarIcon(self, action):
|
||||
"""Remove an action (icon) from the plugin toolbar.
|
||||
|
||||
:param action: Action to add to the toolbar.
|
||||
:type action: QAction
|
||||
"""
|
||||
pass
|
||||
|
||||
def addToolBar(self, name):
|
||||
"""Add toolbar with specified name.
|
||||
|
||||
:param name: Name for the toolbar.
|
||||
:type name: str
|
||||
"""
|
||||
pass
|
||||
|
||||
def mapCanvas(self):
|
||||
"""Return a pointer to the map canvas."""
|
||||
return self.canvas
|
||||
|
||||
def mainWindow(self):
|
||||
"""Return a pointer to the main window.
|
||||
|
||||
In case of QGIS it returns an instance of QgisApp.
|
||||
"""
|
||||
pass
|
||||
|
||||
def addDockWidget(self, area, dock_widget):
|
||||
"""Add a dock widget to the main window.
|
||||
|
||||
:param area: Where in the ui the dock should be placed.
|
||||
:type area:
|
||||
|
||||
:param dock_widget: A dock widget to add to the UI.
|
||||
:type dock_widget: QDockWidget
|
||||
"""
|
||||
pass
|
||||
|
||||
def legendInterface(self):
|
||||
"""Get the legend."""
|
||||
return self.canvas
|
19
test/tenbytenraster.asc
Normal file
19
test/tenbytenraster.asc
Normal file
@@ -0,0 +1,19 @@
|
||||
NCOLS 10
|
||||
NROWS 10
|
||||
XLLCENTER 1535380.000000
|
||||
YLLCENTER 5083260.000000
|
||||
DX 10
|
||||
DY 10
|
||||
NODATA_VALUE -9999
|
||||
0 1 2 3 4 5 6 7 8 9
|
||||
0 1 2 3 4 5 6 7 8 9
|
||||
0 1 2 3 4 5 6 7 8 9
|
||||
0 1 2 3 4 5 6 7 8 9
|
||||
0 1 2 3 4 5 6 7 8 9
|
||||
0 1 2 3 4 5 6 7 8 9
|
||||
0 1 2 3 4 5 6 7 8 9
|
||||
0 1 2 3 4 5 6 7 8 9
|
||||
0 1 2 3 4 5 6 7 8 9
|
||||
0 1 2 3 4 5 6 7 8 9
|
||||
CRS
|
||||
NOTES
|
13
test/tenbytenraster.asc.aux.xml
Normal file
13
test/tenbytenraster.asc.aux.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<PAMDataset>
|
||||
<Metadata>
|
||||
<MDI key="AREA_OR_POINT">Point</MDI>
|
||||
</Metadata>
|
||||
<PAMRasterBand band="1">
|
||||
<Metadata>
|
||||
<MDI key="STATISTICS_MAXIMUM">9</MDI>
|
||||
<MDI key="STATISTICS_MEAN">4.5</MDI>
|
||||
<MDI key="STATISTICS_MINIMUM">0</MDI>
|
||||
<MDI key="STATISTICS_STDDEV">2.872281323269</MDI>
|
||||
</Metadata>
|
||||
</PAMRasterBand>
|
||||
</PAMDataset>
|
1
test/tenbytenraster.keywords
Normal file
1
test/tenbytenraster.keywords
Normal file
@@ -0,0 +1 @@
|
||||
title: Tenbytenraster
|
18
test/tenbytenraster.lic
Normal file
18
test/tenbytenraster.lic
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version='1.0' encoding='iso-8859-1'?>
|
||||
<ga_license_file>
|
||||
<metadata>
|
||||
<author>Tim Sutton, Linfiniti Consulting CC</author>
|
||||
</metadata>
|
||||
|
||||
<datafile>
|
||||
<filename>tenbytenraster.asc</filename>
|
||||
<checksum>2700044251</checksum>
|
||||
<publishable>Yes</publishable>
|
||||
<accountable>Tim Sutton</accountable>
|
||||
<source>Tim Sutton (QGIS Source Tree)</source>
|
||||
<IP_owner>Tim Sutton</IP_owner>
|
||||
<IP_info>This data is publicly available from QGIS Source Tree. The original
|
||||
file was created and contributed to QGIS by Tim Sutton.</IP_info>
|
||||
</datafile>
|
||||
|
||||
</ga_license_file>
|
1
test/tenbytenraster.prj
Normal file
1
test/tenbytenraster.prj
Normal file
@@ -0,0 +1 @@
|
||||
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
|
26
test/tenbytenraster.qml
Normal file
26
test/tenbytenraster.qml
Normal file
@@ -0,0 +1,26 @@
|
||||
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
|
||||
<qgis version="1.9.0-Master" minimumScale="-4.65661e-10" maximumScale="1e+08" hasScaleBasedVisibilityFlag="0">
|
||||
<pipe>
|
||||
<rasterrenderer opacity="1" alphaBand="0" classificationMax="9" classificationMinMaxOrigin="MinMaxFullExtentExact" band="1" classificationMin="0" type="singlebandpseudocolor">
|
||||
<rasterTransparency/>
|
||||
<rastershader>
|
||||
<colorrampshader colorRampType="INTERPOLATED" clip="0">
|
||||
<item alpha="255" value="0" label="0.000000" color="#d7191c"/>
|
||||
<item alpha="255" value="1" label="1.000000" color="#e75b3a"/>
|
||||
<item alpha="255" value="2" label="2.000000" color="#f89d59"/>
|
||||
<item alpha="255" value="3" label="3.000000" color="#fdc980"/>
|
||||
<item alpha="255" value="4" label="4.000000" color="#feedaa"/>
|
||||
<item alpha="255" value="5" label="5.000000" color="#ecf7b9"/>
|
||||
<item alpha="255" value="6" label="6.000000" color="#c7e8ad"/>
|
||||
<item alpha="255" value="7" label="7.000000" color="#9cd3a6"/>
|
||||
<item alpha="255" value="8" label="8.000000" color="#63abb0"/>
|
||||
<item alpha="255" value="9" label="9.000000" color="#2b83ba"/>
|
||||
</colorrampshader>
|
||||
</rastershader>
|
||||
</rasterrenderer>
|
||||
<brightnesscontrast brightness="0" contrast="0"/>
|
||||
<huesaturation colorizeGreen="128" colorizeOn="0" colorizeRed="255" colorizeBlue="128" grayscaleMode="0" saturation="0" colorizeStrength="100"/>
|
||||
<rasterresampler maxOversampling="2"/>
|
||||
</pipe>
|
||||
<blendMode>0</blendMode>
|
||||
</qgis>
|
64
test/test_init.py
Normal file
64
test/test_init.py
Normal file
@@ -0,0 +1,64 @@
|
||||
# coding=utf-8
|
||||
"""Tests QGIS plugin init."""
|
||||
|
||||
__author__ = 'Tim Sutton <tim@linfiniti.com>'
|
||||
__revision__ = '$Format:%H$'
|
||||
__date__ = '17/10/2010'
|
||||
__license__ = "GPL"
|
||||
__copyright__ = 'Copyright 2012, Australia Indonesia Facility for '
|
||||
__copyright__ += 'Disaster Reduction'
|
||||
|
||||
import os
|
||||
import unittest
|
||||
import logging
|
||||
import configparser
|
||||
|
||||
LOGGER = logging.getLogger('QGIS')
|
||||
|
||||
|
||||
class TestInit(unittest.TestCase):
|
||||
"""Test that the plugin init is usable for QGIS.
|
||||
|
||||
Based heavily on the validator class by Alessandro
|
||||
Passoti available here:
|
||||
|
||||
http://github.com/qgis/qgis-django/blob/master/qgis-app/
|
||||
plugins/validator.py
|
||||
|
||||
"""
|
||||
|
||||
def test_read_init(self):
|
||||
"""Test that the plugin __init__ will validate on plugins.qgis.org."""
|
||||
|
||||
# You should update this list according to the latest in
|
||||
# https://github.com/qgis/qgis-django/blob/master/qgis-app/
|
||||
# plugins/validator.py
|
||||
|
||||
required_metadata = [
|
||||
'name',
|
||||
'description',
|
||||
'version',
|
||||
'qgisMinimumVersion',
|
||||
'email',
|
||||
'author']
|
||||
|
||||
file_path = os.path.abspath(os.path.join(
|
||||
os.path.dirname(__file__), os.pardir,
|
||||
'metadata.txt'))
|
||||
LOGGER.info(file_path)
|
||||
metadata = []
|
||||
parser = configparser.ConfigParser()
|
||||
parser.optionxform = str
|
||||
parser.read(file_path)
|
||||
message = 'Cannot find a section named "general" in %s' % file_path
|
||||
assert parser.has_section('general'), message
|
||||
metadata.extend(parser.items('general'))
|
||||
|
||||
for expectation in required_metadata:
|
||||
message = ('Cannot find metadata "%s" in metadata source (%s).' % (
|
||||
expectation, file_path))
|
||||
|
||||
self.assertIn(expectation, dict(metadata), message)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
60
test/test_qgis_environment.py
Normal file
60
test/test_qgis_environment.py
Normal file
@@ -0,0 +1,60 @@
|
||||
# coding=utf-8
|
||||
"""Tests for QGIS functionality.
|
||||
|
||||
|
||||
.. note:: 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__ = 'tim@linfiniti.com'
|
||||
__date__ = '20/01/2011'
|
||||
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
|
||||
'Disaster Reduction')
|
||||
|
||||
import os
|
||||
import unittest
|
||||
from qgis.core import (
|
||||
QgsProviderRegistry,
|
||||
QgsCoordinateReferenceSystem,
|
||||
QgsRasterLayer)
|
||||
|
||||
from .utilities import get_qgis_app
|
||||
QGIS_APP = get_qgis_app()
|
||||
|
||||
|
||||
class QGISTest(unittest.TestCase):
|
||||
"""Test the QGIS Environment"""
|
||||
|
||||
def test_qgis_environment(self):
|
||||
"""QGIS environment has the expected providers"""
|
||||
|
||||
r = QgsProviderRegistry.instance()
|
||||
self.assertIn('gdal', r.providerList())
|
||||
self.assertIn('ogr', r.providerList())
|
||||
self.assertIn('postgres', r.providerList())
|
||||
|
||||
def test_projection(self):
|
||||
"""Test that QGIS properly parses a wkt string.
|
||||
"""
|
||||
crs = QgsCoordinateReferenceSystem()
|
||||
wkt = (
|
||||
'GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",'
|
||||
'SPHEROID["WGS_1984",6378137.0,298.257223563]],'
|
||||
'PRIMEM["Greenwich",0.0],UNIT["Degree",'
|
||||
'0.0174532925199433]]')
|
||||
crs.createFromWkt(wkt)
|
||||
auth_id = crs.authid()
|
||||
expected_auth_id = 'EPSG:4326'
|
||||
self.assertEqual(auth_id, expected_auth_id)
|
||||
|
||||
# now test for a loaded layer
|
||||
path = os.path.join(os.path.dirname(__file__), 'tenbytenraster.asc')
|
||||
title = 'TestRaster'
|
||||
layer = QgsRasterLayer(path, title)
|
||||
auth_id = layer.crs().authid()
|
||||
self.assertEqual(auth_id, expected_auth_id)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
44
test/test_resources.py
Normal file
44
test/test_resources.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# coding=utf-8
|
||||
"""Resources test.
|
||||
|
||||
.. note:: 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__ = 'info@champs-libres.coop'
|
||||
__date__ = '2021-03-26'
|
||||
__copyright__ = 'Copyright 2021, Champs-Libres'
|
||||
|
||||
import unittest
|
||||
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
|
||||
|
||||
|
||||
class WebExporterDialogTest(unittest.TestCase):
|
||||
"""Test rerources work."""
|
||||
|
||||
def setUp(self):
|
||||
"""Runs before each test."""
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
"""Runs after each test."""
|
||||
pass
|
||||
|
||||
def test_icon_png(self):
|
||||
"""Test we can click OK."""
|
||||
path = ':/plugins/WebExporter/icon.png'
|
||||
icon = QIcon(path)
|
||||
self.assertFalse(icon.isNull())
|
||||
|
||||
if __name__ == "__main__":
|
||||
suite = unittest.makeSuite(WebExporterResourcesTest)
|
||||
runner = unittest.TextTestRunner(verbosity=2)
|
||||
runner.run(suite)
|
||||
|
||||
|
||||
|
55
test/test_translations.py
Normal file
55
test/test_translations.py
Normal file
@@ -0,0 +1,55 @@
|
||||
# coding=utf-8
|
||||
"""Safe Translations Test.
|
||||
|
||||
.. note:: 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.
|
||||
|
||||
"""
|
||||
from .utilities import get_qgis_app
|
||||
|
||||
__author__ = 'ismailsunni@yahoo.co.id'
|
||||
__date__ = '12/10/2011'
|
||||
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
|
||||
'Disaster Reduction')
|
||||
import unittest
|
||||
import os
|
||||
|
||||
from qgis.PyQt.QtCore import QCoreApplication, QTranslator
|
||||
|
||||
QGIS_APP = get_qgis_app()
|
||||
|
||||
|
||||
class SafeTranslationsTest(unittest.TestCase):
|
||||
"""Test translations work."""
|
||||
|
||||
def setUp(self):
|
||||
"""Runs before each test."""
|
||||
if 'LANG' in iter(os.environ.keys()):
|
||||
os.environ.__delitem__('LANG')
|
||||
|
||||
def tearDown(self):
|
||||
"""Runs after each test."""
|
||||
if 'LANG' in iter(os.environ.keys()):
|
||||
os.environ.__delitem__('LANG')
|
||||
|
||||
def test_qgis_translations(self):
|
||||
"""Test that translations work."""
|
||||
parent_path = os.path.join(__file__, os.path.pardir, os.path.pardir)
|
||||
dir_path = os.path.abspath(parent_path)
|
||||
file_path = os.path.join(
|
||||
dir_path, 'i18n', 'af.qm')
|
||||
translator = QTranslator()
|
||||
translator.load(file_path)
|
||||
QCoreApplication.installTranslator(translator)
|
||||
|
||||
expected_message = 'Goeie more'
|
||||
real_message = QCoreApplication.translate("@default", 'Good morning')
|
||||
self.assertEqual(real_message, expected_message)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
suite = unittest.makeSuite(SafeTranslationsTest)
|
||||
runner = unittest.TextTestRunner(verbosity=2)
|
||||
runner.run(suite)
|
55
test/test_web_exporter_dialog.py
Normal file
55
test/test_web_exporter_dialog.py
Normal file
@@ -0,0 +1,55 @@
|
||||
# coding=utf-8
|
||||
"""Dialog test.
|
||||
|
||||
.. note:: 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__ = 'info@champs-libres.coop'
|
||||
__date__ = '2021-03-26'
|
||||
__copyright__ = 'Copyright 2021, Champs-Libres'
|
||||
|
||||
import unittest
|
||||
|
||||
from qgis.PyQt.QtGui import QDialogButtonBox, QDialog
|
||||
|
||||
from web_exporter_dialog import WebExporterDialog
|
||||
|
||||
from utilities import get_qgis_app
|
||||
QGIS_APP = get_qgis_app()
|
||||
|
||||
|
||||
class WebExporterDialogTest(unittest.TestCase):
|
||||
"""Test dialog works."""
|
||||
|
||||
def setUp(self):
|
||||
"""Runs before each test."""
|
||||
self.dialog = WebExporterDialog(None)
|
||||
|
||||
def tearDown(self):
|
||||
"""Runs after each test."""
|
||||
self.dialog = None
|
||||
|
||||
def test_dialog_ok(self):
|
||||
"""Test we can click OK."""
|
||||
|
||||
button = self.dialog.button_box.button(QDialogButtonBox.Ok)
|
||||
button.click()
|
||||
result = self.dialog.result()
|
||||
self.assertEqual(result, QDialog.Accepted)
|
||||
|
||||
def test_dialog_cancel(self):
|
||||
"""Test we can click cancel."""
|
||||
button = self.dialog.button_box.button(QDialogButtonBox.Cancel)
|
||||
button.click()
|
||||
result = self.dialog.result()
|
||||
self.assertEqual(result, QDialog.Rejected)
|
||||
|
||||
if __name__ == "__main__":
|
||||
suite = unittest.makeSuite(WebExporterDialogTest)
|
||||
runner = unittest.TextTestRunner(verbosity=2)
|
||||
runner.run(suite)
|
||||
|
61
test/utilities.py
Normal file
61
test/utilities.py
Normal file
@@ -0,0 +1,61 @@
|
||||
# coding=utf-8
|
||||
"""Common functionality used by regression tests."""
|
||||
|
||||
import sys
|
||||
import logging
|
||||
|
||||
|
||||
LOGGER = logging.getLogger('QGIS')
|
||||
QGIS_APP = None # Static variable used to hold hand to running QGIS app
|
||||
CANVAS = None
|
||||
PARENT = None
|
||||
IFACE = None
|
||||
|
||||
|
||||
def get_qgis_app():
|
||||
""" Start one QGIS application to test against.
|
||||
|
||||
:returns: Handle to QGIS app, canvas, iface and parent. If there are any
|
||||
errors the tuple members will be returned as None.
|
||||
:rtype: (QgsApplication, CANVAS, IFACE, PARENT)
|
||||
|
||||
If QGIS is already running the handle to that app will be returned.
|
||||
"""
|
||||
|
||||
try:
|
||||
from qgis.PyQt import QtGui, QtCore
|
||||
from qgis.core import QgsApplication
|
||||
from qgis.gui import QgsMapCanvas
|
||||
from .qgis_interface import QgisInterface
|
||||
except ImportError:
|
||||
return None, None, None, None
|
||||
|
||||
global QGIS_APP # pylint: disable=W0603
|
||||
|
||||
if QGIS_APP is None:
|
||||
gui_flag = True # All test will run qgis in gui mode
|
||||
#noinspection PyPep8Naming
|
||||
QGIS_APP = QgsApplication(sys.argv, gui_flag)
|
||||
# Make sure QGIS_PREFIX_PATH is set in your env if needed!
|
||||
QGIS_APP.initQgis()
|
||||
s = QGIS_APP.showSettings()
|
||||
LOGGER.debug(s)
|
||||
|
||||
global PARENT # pylint: disable=W0603
|
||||
if PARENT is None:
|
||||
#noinspection PyPep8Naming
|
||||
PARENT = QtGui.QWidget()
|
||||
|
||||
global CANVAS # pylint: disable=W0603
|
||||
if CANVAS is None:
|
||||
#noinspection PyPep8Naming
|
||||
CANVAS = QgsMapCanvas(PARENT)
|
||||
CANVAS.resize(QtCore.QSize(400, 400))
|
||||
|
||||
global IFACE # pylint: disable=W0603
|
||||
if IFACE is None:
|
||||
# QgisInterface is a stub implementation of the QGIS plugin interface
|
||||
#noinspection PyPep8Naming
|
||||
IFACE = QgisInterface(CANVAS)
|
||||
|
||||
return QGIS_APP, CANVAS, IFACE, PARENT
|
Reference in New Issue
Block a user