diff --git a/travel_time_platform_plugin/main.py b/travel_time_platform_plugin/main.py index 16d0bcc..c3bab07 100644 --- a/travel_time_platform_plugin/main.py +++ b/travel_time_platform_plugin/main.py @@ -246,24 +246,49 @@ def show_config(self): self.config_dialog.exec_() def run_tests(self): + + box = QMessageBox( + QMessageBox.Question, + "Run software tests", + "You are about to run automated software tests. There is usually no reason to run them, unless you want to share a report to track down issues that you may encounter.\n\n" + "Warning:\n" + "- the current project will be closed without saving\n" + "- there may be some side-effects on your QGIS user profile\n" + "- this will use your API quota\n" + "- do not interact with QGIS while the tests run", + ) + box.setInformativeText("Do you want to proceed ?") + box.setStandardButtons(QMessageBox.Yes | QMessageBox.Cancel) + + if box.exec_() != QMessageBox.Yes: + return + with io.StringIO() as buf: with contextlib.redirect_stdout(buf): result = tests.run_suite(stream=buf) output = buf.getvalue() - log(output, "-tests") + log(tests.system_info(), "TravelTimePlatform tests output") + log(output, "TravelTimePlatform tests output") success = result.wasSuccessful() - box = QMessageBox( - QMessageBox.Question if success else QMessageBox.Critical, - "Test results", - f"Ran {result.testsRun} tests, of which {len(result.errors) + len(result.failures)} failed.", - ) - box.setInformativeText("Do you want to copy the test report ?") - box.setStandardButtons(QMessageBox.Yes | QMessageBox.Discard) + if success: + box = QMessageBox( + QMessageBox.Information, + "Success", + f"All {result.testsRun} tests succeeded.", + ) + else: + box = QMessageBox( + QMessageBox.Critical, + "Failure", + f"{len(result.errors) + len(result.failures)} tests failed out of {result.testsRun}.", + ) + box.setInformativeText("Do you want to copy the report to the clipboard ?") + box.setStandardButtons(QMessageBox.Yes | QMessageBox.No) - if box.exec_(): + if box.exec_() == QMessageBox.Yes: QGuiApplication.clipboard().setText(f"{tests.system_info()}\n{output}") def show_splash(self): diff --git a/travel_time_platform_plugin/tests/base.py b/travel_time_platform_plugin/tests/base.py index f00e2d0..75e835e 100644 --- a/travel_time_platform_plugin/tests/base.py +++ b/travel_time_platform_plugin/tests/base.py @@ -26,6 +26,9 @@ from .. import auth from ..main import TTPPlugin +# Set to true to save artifacts and add some delay for visual inspection +SHOW_OUTPUT = False + TEST_MODE = os.environ.get("TEST_MODE", "DESKTOP") # HEADLESS | HEADFULL | DESKTOP assert TEST_MODE in ["HEADLESS", "HEADFULL", "DESKTOP"] @@ -88,12 +91,16 @@ def _feedback(self, seconds=1): """Waits a little so we can see what happens when running the tests with GUI""" self.__feedback_step += 1 + QgsApplication.processEvents() + + # Unless we want to show output, nothing to do + if not SHOW_OUTPUT: + return if TEST_MODE != "HEADLESS": t = datetime.now() while (datetime.now() - t).total_seconds() < seconds: QgsApplication.processEvents() - QgsApplication.processEvents() # Save artifacts artifact_name = f"{self.__class__.__name__}-{self._testMethodName}-{self.__feedback_step:03}" diff --git a/travel_time_platform_plugin/utils.py b/travel_time_platform_plugin/utils.py index a7d42f8..d4ce898 100644 --- a/travel_time_platform_plugin/utils.py +++ b/travel_time_platform_plugin/utils.py @@ -2,6 +2,7 @@ from datetime import datetime, timedelta, timezone from qgis.core import ( + Qgis, QgsCoordinateReferenceSystem, QgsFeature, QgsGeometry, @@ -53,8 +54,8 @@ def clone_feature(request, source_layer, output_fields=None): return new_feature -def log(msg, suffix=""): - QgsMessageLog.logMessage(str(msg), f"TimeTravelPlatform{suffix}") +def log(msg, tag="TimeTravelPlatform", level=Qgis.Info): + QgsMessageLog.logMessage(str(msg), tag, level=level) def tr(string):