diff --git a/README.md b/README.md index ec8aca05..f858a124 100644 --- a/README.md +++ b/README.md @@ -60,13 +60,18 @@ Below is a brief description of the repository contents. - [.pre-commit-config.yaml](https://github.com/IntegralEnvision/seat-qgis-plugin/blob/main/.pre-commit-config.yaml): Collection of hooks to run prior to committing the code state to Git. Hooks include linters and code formatters. - [create_zip.sh](https://github.com/IntegralEnvision/seat-qgis-plugin/blob/main/create_zip.sh): Shell script to create a zipped code archive locally, which can be imported to the QGIS plugin installer. - [seat-qgis-plugin/code](https://github.com/IntegralEnvision/seat-qgis-plugin/tree/main/code): Plugin code. - - [stressor_receptor_calc.py](https://github.com/IntegralEnvision/seat-qgis-plugin/blob/main/code/stressor_receptor_calc.py): Main plugin script doing the heavy lifting. + - [stressor_receptor_calc.py](https://github.com/IntegralEnvision/seat-qgis-plugin/blob/main/code/stressor_receptor_calc.py): Main plugin script for input and display. - [stressor_receptor_calc_dialog.py](https://github.com/IntegralEnvision/seat-qgis-plugin/blob/main/code/stressor_receptor_calc_dialog.py): Initializes the plugin GUI. - [stressor_receptor_calc_dialog_base.ui](https://github.com/IntegralEnvision/seat-qgis-plugin/blob/main/code/stressor_receptor_calc_dialog_base.ui): Interface configuration (generated with Qt Designer). - - [resources.qrc](https://github.com/IntegralEnvision/seat-qgis-plugin/blob/main/code/resources.qrc): Application resources such as icons and trnalsation files. + - [resources.qrc](https://github.com/IntegralEnvision/seat-qgis-plugin/blob/main/code/resources.qrc): Application resources such as icons and translation files. - [resources.py](https://github.com/IntegralEnvision/seat-qgis-plugin/blob/main/code/resources.py): Resource file generated from compiling resources.qrc. - [plugin_upload.py](https://github.com/IntegralEnvision/seat-qgis-plugin/blob/main/code/plugin_upload.py): Utility - upload a plugin package to the [QGIS plugin repository](https://plugins.qgis.org/plugins/). - [pb_tool.cfg](https://github.com/IntegralEnvision/seat-qgis-plugin/blob/main/code/pb_tool.cfg): Configuration file for the plugin builder tool. - [metadata.txt](https://github.com/IntegralEnvision/seat-qgis-plugin/blob/main/code/metadata.txt): Plugin metadata. - [icon.png](https://github.com/IntegralEnvision/seat-qgis-plugin/blob/main/code/icon.png): Plugin icon. - - [compile.bat](https://github.com/IntegralEnvision/seat-qgis-plugin/blob/main/code/compile.bat): Compile plugin resources (Windows). \ No newline at end of file + - [compile.bat](https://github.com/IntegralEnvision/seat-qgis-plugin/blob/main/code/compile.bat): Compile plugin resources (Windows). + - [shear_stress_module.py](https://github.com/IntegralEnvision/seat-qgis-plugin/blob/main/code/shear_stress_module.py): Calculates and generates the shear stress stressor maps and statistics files. + - [velocity_module.py](https://github.com/IntegralEnvision/seat-qgis-plugin/blob/main/code/velocity_module.py): Calculates and generates the velocity stressor maps and statistics files. + - [acoustics_module.py](https://github.com/IntegralEnvision/seat-qgis-plugin/blob/main/code/acoustics_module.py): Calculates and generates the paracousti stressor maps and statistics files. + - [power_module.py](https://github.com/IntegralEnvision/seat-qgis-plugin/blob/main/code/power_module.py): Calculates and generates the wec/cec power generated plots and statistics files. + - [stressor_utils.py](https://github.com/IntegralEnvision/seat-qgis-plugin/blob/main/code/stressor_utils.py): General processing scripts. \ No newline at end of file diff --git a/code/test/__init__.py b/code/test/__init__.py deleted file mode 100644 index 2aea0858..00000000 --- a/code/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/code/test/qgis_interface.py b/code/test/qgis_interface.py deleted file mode 100644 index 68e0bf70..00000000 --- a/code/test/qgis_interface.py +++ /dev/null @@ -1,208 +0,0 @@ -# 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.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/code/test/tenbytenraster.asc b/code/test/tenbytenraster.asc deleted file mode 100644 index 96a0ee1f..00000000 --- a/code/test/tenbytenraster.asc +++ /dev/null @@ -1,19 +0,0 @@ -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 diff --git a/code/test/tenbytenraster.asc.aux.xml b/code/test/tenbytenraster.asc.aux.xml deleted file mode 100644 index cfb15788..00000000 --- a/code/test/tenbytenraster.asc.aux.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - Point - - - - 9 - 4.5 - 0 - 2.872281323269 - - - diff --git a/code/test/tenbytenraster.keywords b/code/test/tenbytenraster.keywords deleted file mode 100644 index 8be3f615..00000000 --- a/code/test/tenbytenraster.keywords +++ /dev/null @@ -1 +0,0 @@ -title: Tenbytenraster diff --git a/code/test/tenbytenraster.lic b/code/test/tenbytenraster.lic deleted file mode 100644 index 83455332..00000000 --- a/code/test/tenbytenraster.lic +++ /dev/null @@ -1,18 +0,0 @@ - - - - Tim Sutton, Linfiniti Consulting CC - - - - tenbytenraster.asc - 2700044251 - Yes - Tim Sutton - Tim Sutton (QGIS Source Tree) - Tim Sutton - This data is publicly available from QGIS Source Tree. The original - file was created and contributed to QGIS by Tim Sutton. - - - diff --git a/code/test/tenbytenraster.prj b/code/test/tenbytenraster.prj deleted file mode 100644 index 8f73f480..00000000 --- a/code/test/tenbytenraster.prj +++ /dev/null @@ -1 +0,0 @@ -GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]] diff --git a/code/test/tenbytenraster.qml b/code/test/tenbytenraster.qml deleted file mode 100644 index 85247d44..00000000 --- a/code/test/tenbytenraster.qml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - 0 - diff --git a/code/test/test_init.py b/code/test/test_init.py deleted file mode 100644 index a513741e..00000000 --- a/code/test/test_init.py +++ /dev/null @@ -1,71 +0,0 @@ -# coding=utf-8 -"""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 - 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 "{}" in metadata source ({}).'.format( - expectation, - file_path, - ) - - self.assertIn(expectation, dict(metadata), message) - - -if __name__ == "__main__": - unittest.main() diff --git a/code/test/test_qgis_environment.py b/code/test/test_qgis_environment.py deleted file mode 100644 index 7f63b587..00000000 --- a/code/test/test_qgis_environment.py +++ /dev/null @@ -1,57 +0,0 @@ -# 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 QgsCoordinateReferenceSystem, QgsProviderRegistry, 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() diff --git a/code/test/test_resources.py b/code/test/test_resources.py deleted file mode 100644 index f9ec3c8e..00000000 --- a/code/test/test_resources.py +++ /dev/null @@ -1,42 +0,0 @@ -# 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__ = "cgrant@integral-corp.com" -__date__ = "2021-04-19" -__copyright__ = "Copyright 2021, Integral Consultsing" - -import unittest - -from qgis.PyQt.QtGui import QIcon - - -class StressorReceptorCalcDialogTest(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/StressorReceptorCalc/icon.png" - icon = QIcon(path) - self.assertFalse(icon.isNull()) - - -if __name__ == "__main__": - suite = unittest.defaultTestLoader.loadTestsFromTestCase( - StressorReceptorCalcResourcesTest, - ) - runner = unittest.TextTestRunner(verbosity=2) - runner.run(suite) diff --git a/code/test/test_stressor_receptor_calc_dialog.py b/code/test/test_stressor_receptor_calc_dialog.py deleted file mode 100644 index b008885b..00000000 --- a/code/test/test_stressor_receptor_calc_dialog.py +++ /dev/null @@ -1,55 +0,0 @@ -# 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__ = "cgrant@integral-corp.com" -__date__ = "2021-04-19" -__copyright__ = "Copyright 2021, Integral Consultsing" - -import unittest - -from qgis.PyQt.QtGui import QDialog, QDialogButtonBox -from stressor_receptor_calc_dialog import StressorReceptorCalcDialog -from utilities import get_qgis_app - -QGIS_APP = get_qgis_app() - - -class StressorReceptorCalcDialogTest(unittest.TestCase): - """Test dialog works.""" - - def setUp(self): - """Runs before each test.""" - self.dialog = StressorReceptorCalcDialog(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.defaultTestLoader.loadTestsFromTestCase( - StressorReceptorCalcDialogTest, - ) - runner = unittest.TextTestRunner(verbosity=2) - runner.run(suite) diff --git a/code/test/test_translations.py b/code/test/test_translations.py deleted file mode 100644 index 0d2075f9..00000000 --- a/code/test/test_translations.py +++ /dev/null @@ -1,56 +0,0 @@ -# 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 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.defaultTestLoader.loadTestsFromTestCase(SafeTranslationsTest) - runner = unittest.TextTestRunner(verbosity=2) - runner.run(suite) diff --git a/code/test/utilities.py b/code/test/utilities.py deleted file mode 100644 index 6326e8b8..00000000 --- a/code/test/utilities.py +++ /dev/null @@ -1,61 +0,0 @@ -# coding=utf-8 -"""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