diff --git a/test/__init__.py b/test/__init__.py deleted file mode 100644 index 2aea085..0000000 --- a/test/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# import qgis libs so that ve set the correct sip api version -import qgis # pylint: disable=W0611 # NOQA diff --git a/test/qgis_interface.py b/test/qgis_interface.py deleted file mode 100644 index c5bd8fd..0000000 --- a/test/qgis_interface.py +++ /dev/null @@ -1,207 +0,0 @@ -"""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.core import QgsMapLayerRegistry -from qgis.gui import QgsMapCanvasLayer -from qgis.PyQt.QtCore import QObject, pyqtSignal, pyqtSlot - -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 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 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 diff --git a/test/test_init.py b/test/test_init.py deleted file mode 100644 index 4120b56..0000000 --- a/test/test_init.py +++ /dev/null @@ -1,67 +0,0 @@ -"""Tests QGIS plugin init.""" - -__author__ = "Tim Sutton " -__revision__ = "$Format:%H$" -__date__ = "17/10/2010" -__license__ = "GPL" -__copyright__ = "Copyright 2012, Australia Indonesia Facility for " -__copyright__ += "Disaster Reduction" - -import configparser -import logging -import os -import unittest - -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 # str = case sensitive option names - 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() diff --git a/test/test_profile_manager_dialog.py b/test/test_profile_manager_dialog.py deleted file mode 100644 index 98bf12e..0000000 --- a/test/test_profile_manager_dialog.py +++ /dev/null @@ -1,54 +0,0 @@ -"""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__ = "dominik.szill@wheregroup.com" -__date__ = "2020-03-17" -__copyright__ = "Copyright 2020, Dominik Szill / WhereGroup GmbH" - -import unittest - -from qgis.PyQt.QtGui import QDialog, QDialogButtonBox -from utilities import get_qgis_app - -from profile_manager.profile_manager_dialog import ProfileManagerDialog - -QGIS_APP = get_qgis_app() - - -class ProfileManagerDialogTest(unittest.TestCase): - """Test dialog works.""" - - def setUp(self): - """Runs before each test.""" - self.dialog = ProfileManagerDialog(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(ProfileManagerDialogTest) - runner = unittest.TextTestRunner(verbosity=2) - runner.run(suite) diff --git a/test/test_translations.py b/test/test_translations.py deleted file mode 100644 index 2faabdd..0000000 --- a/test/test_translations.py +++ /dev/null @@ -1,53 +0,0 @@ -"""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 os -import unittest - -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) diff --git a/test/utilities.py b/test/utilities.py deleted file mode 100644 index d441403..0000000 --- a/test/utilities.py +++ /dev/null @@ -1,60 +0,0 @@ -"""Common functionality used by regression tests.""" - -import logging -import sys - -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.core import QgsApplication - from qgis.gui import QgsMapCanvas - from qgis.PyQt import QtCore, QtGui - - 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