From 160e4d4c807d073942df2e3aaa80660f246fc28f Mon Sep 17 00:00:00 2001 From: Adakar Date: Mon, 20 Mar 2023 06:29:40 +0100 Subject: [PATCH 01/16] Add squape-report package The package containing reporting utilities for Squish GUI Tester --- squape-report/pyproject.toml | 17 ++++++++++++++++ squape-report/squape/messages.py | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 squape-report/pyproject.toml create mode 100644 squape-report/squape/messages.py diff --git a/squape-report/pyproject.toml b/squape-report/pyproject.toml new file mode 100644 index 0000000..95f12ee --- /dev/null +++ b/squape-report/pyproject.toml @@ -0,0 +1,17 @@ +# squape-report/pyproject.toml + +[build-system] +requires = ["setuptools", "setuptools-scm"] +build-backend = "setuptools.build_meta" + +[tool.setuptools.packages.find] +where = ["."] +include = ["squape"] +namespaces = true + +[project] +name = "squape-report" +version = "1.0.0" +requires-python = ">=3.6" +description = "Reporting Utilities for the Squish GUI Tester" +license = { text = "..." } \ No newline at end of file diff --git a/squape-report/squape/messages.py b/squape-report/squape/messages.py new file mode 100644 index 0000000..5a56755 --- /dev/null +++ b/squape-report/squape/messages.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# +# Copyright (c) 2023, Cyber Alpaca +# All rights reserved. +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. +import test +from contextlib import contextmanager + + +@contextmanager +def section(title: str, description: str = "") -> None: + """Allows using sections as context managers + + https://doc.qt.io/squish/squish-api.html#test-startsection-function + Args: + title (str): the section title + description (str): the section description + Examples: + with section("Add new person"): + squish.type(squish.waitForObject(names.forename_edit), "Bob") + squish.mouseClick(squish.waitForObject(names.ok_button)) + """ + + test.fixateResultContext(2) + test.startSection(title, description) + test.restoreResultContext() + try: + yield + except Exception: + raise + finally: + test.endSection() From 04105bd8896d98484ce7a697f43a9715dc2a002a Mon Sep 17 00:00:00 2001 From: Adakar Date: Mon, 20 Mar 2023 15:31:50 +0100 Subject: [PATCH 02/16] vps module with vph_property to squape-report --- squape-report/squape/vps.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 squape-report/squape/vps.py diff --git a/squape-report/squape/vps.py b/squape-report/squape/vps.py new file mode 100644 index 0000000..8163883 --- /dev/null +++ b/squape-report/squape/vps.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# +# Copyright (c) 2023, Cyber Alpaca +# All rights reserved. +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. +import test + +import squish + + +def vph_property( + object_name: any, property_name: str, expected_value: any, msg: str +) -> None: + """The function verifies the property of the given object. + It highlights the verified object to make it standing out. + + Args: + object_name (any): symbolic name, real name, or object reference + property_name (str): name of the property to verify + expected_value (any): expected value of the verified property + msg (str): verification message + Returns: + None + """ + + obj = squish.waitForObjectExists(object_name) + property_value = getattr(obj, property_name) + squish.highlightObject(obj, 200, False) + test.compare(property_value, expected_value, msg) + squish.snooze(0.2) From af6e69718cefa77d445cf60d1d957322d34b3bd5 Mon Sep 17 00:00:00 2001 From: Adakar Date: Wed, 22 Mar 2023 22:47:39 +0100 Subject: [PATCH 03/16] Add new log entries logic and type Add log levels to the squape-report package. It allows defining LOGLEVEL that will impact which messages are visible in the report and wich are not. --- squape-report/squape/messages.py | 111 ++++++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 1 deletion(-) diff --git a/squape-report/squape/messages.py b/squape-report/squape/messages.py index 5a56755..1c84218 100644 --- a/squape-report/squape/messages.py +++ b/squape-report/squape/messages.py @@ -4,8 +4,117 @@ # All rights reserved. # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. -import test +import sys from contextlib import contextmanager +from enum import Enum + +import test + + +class LogLevel(Enum): + DEBUG = 10 + LOG = 20 + WARNING = 30 + FAIL = 40 + FATAL = 50 + + +LOGLEVEL = LogLevel.LOG + + +def __is_level_enabled(level: LogLevel) -> bool: + """Checks the given log level against the currently set LOGLEVEL + + Args: + level (LogLevel): log level to check + + Returns: + bool: True if level is higher then LOGLEVEL, False otherwise + """ + return LOGLEVEL <= level + + +def debug(msg: str, details: str = "") -> None: + """Adds a DEBUG entry to Squish's test report with the given message and detailes. + The message is in fact a LOG message with a DEBUG prefix. The message will be + visible only if the LOGLEVEL is set to DEBUG + + Args: + msg (str): Message + detail (str, optional): Details of the message. Defaults to "". + """ + if __is_level_enabled(LogLevel.DEBUG): + test.fixateResultContext(2) + try: + test.log(f"[DEBUG] {msg}", details) + finally: + test.restoreResultContext() + + +def log(msg: str, details: str = "") -> None: + """Adds a LOG entry to Squish's test report with the given message and detailes. + The message will be visible only if the LOGLEVEL is set to LOG or lower + + Args: + msg (str): Message + detail (str, optional): Details of the message. Defaults to "". + """ + if __is_level_enabled(LogLevel.LOG): + test.fixateResultContext(2) + try: + test.log(msg, details) + finally: + test.restoreResultContext() + + +def warning(msg: str, details: str = "") -> None: + """Adds a WARNING entry to Squish's test report with the given message and detailes. + The message will be visible only if the LOGLEVEL is set to WARNING or lower + + Args: + msg (str): Message + detail (str, optional): Details of the message. Defaults to "". + """ + if __is_level_enabled(LogLevel.WARNING): + test.fixateResultContext(2) + try: + test.warning(msg, details) + finally: + test.restoreResultContext() + + +def fail(msg: str, details: str = "") -> None: + """Adds a FAIL entry to Squish's test report with the given message and detailes. + The message will be visible only if the LOGLEVEL is set to FAIL or lower + + Args: + msg (str): Message + detail (str, optional): Details of the message. Defaults to "". + """ + if __is_level_enabled(LogLevel.FAIL): + test.fixateResultContext(2) + try: + test.fail(msg, details) + finally: + test.restoreResultContext() + + +def fatal(msg: str, details: str = "") -> None: + """Adds a FATAL entry to Squish's test report with the given message and detailes + then interrupts the test execution. + The message will be visible only if the LOGLEVEL is set to FATAL or lower + + Args: + msg (str): Message + detail (str, optional): Details of the message. Defaults to "". + """ + if __is_level_enabled(LogLevel.FATAL): + test.fixateResultContext(2) + try: + test.fatal(msg, details) + sys.exit(1) + finally: + test.restoreResultContext() @contextmanager From e11480d171be12ce8cb5e047a8c2903c9f1a7fb3 Mon Sep 17 00:00:00 2001 From: Adakar Date: Tue, 28 Mar 2023 23:32:04 +0200 Subject: [PATCH 04/16] Update README with installation instructions and requirements, remove documentation section --- README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 165a508..4a53688 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,16 @@ Python package that extends Squish Python API. It provides tools for everyday automated test cases development. ### Requirements -To enjoy all the features of the SQUAPE package, you have to use it with Squish version X.X.X or newer. +To enjoy all the features of the SQUAPE package, you have to use it with Squish version 7.0.0 or newer. ### Installation -TBD +The packages are available on the Python Package Index (PyPI). +- The `squape-report` package includes methods that enrich Squish reporting and verifying capabilities -### Documentation -TBD +You can install them via `pip` with the following commands: +```sh +pip install squape-report +``` ## Contribution The package is created and maintained by [Cyber Alpaca](https://cyberalpaca.com/) From a18e1f0a0c3ce52f5aa945469f13d4dbe9398b3a Mon Sep 17 00:00:00 2001 From: Adakar Date: Tue, 28 Mar 2023 23:38:00 +0200 Subject: [PATCH 05/16] Group test and squish modules together while reordering imports --- .pre-commit-config.yaml | 6 +++++- squape-report/squape/vps.py | 3 +-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 738465b..b4a3e39 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,9 +11,13 @@ repos: - id: fix-encoding-pragma - repo: https://github.com/asottile/reorder_python_imports - rev: v3.8.1 + rev: v3.9.0 hooks: - id: reorder-python-imports + args: [ + --unclassifiable-application-module, squish, + --unclassifiable-application-module, test, + ] - repo: https://github.com/psf/black rev: 22.6.0 diff --git a/squape-report/squape/vps.py b/squape-report/squape/vps.py index 8163883..1b2463a 100644 --- a/squape-report/squape/vps.py +++ b/squape-report/squape/vps.py @@ -4,9 +4,8 @@ # All rights reserved. # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. -import test - import squish +import test def vph_property( From 64456d6fb65c70d32636285dc8655cfb840299a6 Mon Sep 17 00:00:00 2001 From: Tomasz Pawlowski Date: Wed, 29 Mar 2023 12:00:07 +0200 Subject: [PATCH 06/16] Drop LogLever inharitance from Enum to ease comparision --- squape-report/squape/messages.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/squape-report/squape/messages.py b/squape-report/squape/messages.py index 1c84218..09233c8 100644 --- a/squape-report/squape/messages.py +++ b/squape-report/squape/messages.py @@ -6,12 +6,11 @@ # LICENSE file in the root directory of this source tree. import sys from contextlib import contextmanager -from enum import Enum import test -class LogLevel(Enum): +class LogLevel(): DEBUG = 10 LOG = 20 WARNING = 30 From 59fd433c452819288161414eb46af290be69b413 Mon Sep 17 00:00:00 2001 From: Tomasz Pawlowski Date: Wed, 29 Mar 2023 12:06:30 +0200 Subject: [PATCH 07/16] Use fixateResultContext(1) in messages.py --- squape-report/squape/messages.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/squape-report/squape/messages.py b/squape-report/squape/messages.py index 09233c8..e566645 100644 --- a/squape-report/squape/messages.py +++ b/squape-report/squape/messages.py @@ -43,7 +43,7 @@ def debug(msg: str, details: str = "") -> None: detail (str, optional): Details of the message. Defaults to "". """ if __is_level_enabled(LogLevel.DEBUG): - test.fixateResultContext(2) + test.fixateResultContext(1) try: test.log(f"[DEBUG] {msg}", details) finally: @@ -59,7 +59,7 @@ def log(msg: str, details: str = "") -> None: detail (str, optional): Details of the message. Defaults to "". """ if __is_level_enabled(LogLevel.LOG): - test.fixateResultContext(2) + test.fixateResultContext(1) try: test.log(msg, details) finally: @@ -75,7 +75,7 @@ def warning(msg: str, details: str = "") -> None: detail (str, optional): Details of the message. Defaults to "". """ if __is_level_enabled(LogLevel.WARNING): - test.fixateResultContext(2) + test.fixateResultContext(1) try: test.warning(msg, details) finally: @@ -91,7 +91,7 @@ def fail(msg: str, details: str = "") -> None: detail (str, optional): Details of the message. Defaults to "". """ if __is_level_enabled(LogLevel.FAIL): - test.fixateResultContext(2) + test.fixateResultContext(1) try: test.fail(msg, details) finally: @@ -108,7 +108,7 @@ def fatal(msg: str, details: str = "") -> None: detail (str, optional): Details of the message. Defaults to "". """ if __is_level_enabled(LogLevel.FATAL): - test.fixateResultContext(2) + test.fixateResultContext(1) try: test.fatal(msg, details) sys.exit(1) @@ -130,7 +130,7 @@ def section(title: str, description: str = "") -> None: squish.mouseClick(squish.waitForObject(names.ok_button)) """ - test.fixateResultContext(2) + test.fixateResultContext(1) test.startSection(title, description) test.restoreResultContext() try: From c4c5fcb2974eead53b68bd43e258b12d5e2eb7c2 Mon Sep 17 00:00:00 2001 From: Tomasz Pawlowski Date: Wed, 29 Mar 2023 12:17:39 +0200 Subject: [PATCH 08/16] For fatal messages use testSettings.throwOnFailure functionality --- squape-report/squape/messages.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/squape-report/squape/messages.py b/squape-report/squape/messages.py index e566645..3c80191 100644 --- a/squape-report/squape/messages.py +++ b/squape-report/squape/messages.py @@ -8,6 +8,7 @@ from contextlib import contextmanager import test +import squish class LogLevel(): @@ -110,8 +111,8 @@ def fatal(msg: str, details: str = "") -> None: if __is_level_enabled(LogLevel.FATAL): test.fixateResultContext(1) try: + squish.testSettings.throwOnFailure = True test.fatal(msg, details) - sys.exit(1) finally: test.restoreResultContext() From cdfa53bc63390733204ca0545e2d7b144d283044 Mon Sep 17 00:00:00 2001 From: Tomasz Pawlowski Date: Wed, 29 Mar 2023 12:23:05 +0200 Subject: [PATCH 09/16] Renamed messages module to report --- squape-report/squape/{messages.py => report.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename squape-report/squape/{messages.py => report.py} (100%) diff --git a/squape-report/squape/messages.py b/squape-report/squape/report.py similarity index 100% rename from squape-report/squape/messages.py rename to squape-report/squape/report.py From 58393be47096d93ce01090ea9d06a9f0da8f50eb Mon Sep 17 00:00:00 2001 From: Adakar Date: Fri, 7 Apr 2023 10:11:57 +0200 Subject: [PATCH 10/16] Add and update README and LICENSE files. Update references, required Squish version, package version, and others --- README.md | 7 +++++-- squape-report/LICENSE | 27 +++++++++++++++++++++++++++ squape-report/README.md | 16 ++++++++++++++++ squape-report/pyproject.toml | 4 ++-- 4 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 squape-report/LICENSE create mode 100644 squape-report/README.md diff --git a/README.md b/README.md index 4a53688..9e7d925 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Python package that extends Squish Python API. It provides tools for everyday automated test cases development. ### Requirements -To enjoy all the features of the SQUAPE package, you have to use it with Squish version 7.0.0 or newer. +To enjoy all the features of the SQUAPE package, you have to use it with Squish version 6.7.0 or newer. ### Installation The packages are available on the Python Package Index (PyPI). @@ -19,6 +19,9 @@ Pull requests for any issues are welcome. In case where you would like to introduce a new feature or a major change, please open an issue first and discuss it with our team. ## License -The packages are available under the BSD license +The packages are available under The 3-Clause BSD License + +## References +- [Squish by the Qt Group](https://www.qt.io/product/quality-assurance/squish) [![Cyber Alpaca](https://cyberalpaca.com/static/media/cyberalpaca-logo.60f51a65.svg)](https://cyberalpaca.com) diff --git a/squape-report/LICENSE b/squape-report/LICENSE new file mode 100644 index 0000000..06486e3 --- /dev/null +++ b/squape-report/LICENSE @@ -0,0 +1,27 @@ +Copyright (c) 2023, Cyber Alpaca Pawłowski Topolski sp.j. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/squape-report/README.md b/squape-report/README.md new file mode 100644 index 0000000..ea4ec83 --- /dev/null +++ b/squape-report/README.md @@ -0,0 +1,16 @@ +# SQUAPE - Report +Python package with features that enrich Squish reporting and verifying capabilities + +### Installation +```sh +pip install squape-report +``` + +## License +The packages are available under The 3-Clause BSD License + +## References +- [SQUAPE - Squish API Python Extension](https://github.com/CyberAlpaca/squish-api-python-extension) +- [Squish by the Qt Group](https://www.qt.io/product/quality-assurance/squish) + +[![Cyber Alpaca](https://cyberalpaca.com/static/media/cyberalpaca-logo.60f51a65.svg)](https://cyberalpaca.com) diff --git a/squape-report/pyproject.toml b/squape-report/pyproject.toml index 95f12ee..ce32586 100644 --- a/squape-report/pyproject.toml +++ b/squape-report/pyproject.toml @@ -11,7 +11,7 @@ namespaces = true [project] name = "squape-report" -version = "1.0.0" -requires-python = ">=3.6" +version = "0.1.0" +requires-python = ">=3.8" description = "Reporting Utilities for the Squish GUI Tester" license = { text = "..." } \ No newline at end of file From e3f46d71a87d9bd950ee527c6c117a453b72c983 Mon Sep 17 00:00:00 2001 From: Adakar Date: Fri, 7 Apr 2023 18:46:26 +0200 Subject: [PATCH 11/16] Update squape-report packaging configuration --- squape-report/pyproject.toml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/squape-report/pyproject.toml b/squape-report/pyproject.toml index ce32586..53a581f 100644 --- a/squape-report/pyproject.toml +++ b/squape-report/pyproject.toml @@ -12,6 +12,18 @@ namespaces = true [project] name = "squape-report" version = "0.1.0" +authors = [ + { name="Cyber Alpaca", email="contact@cyberalpaca.com" }, +] requires-python = ">=3.8" +readme = "README.md" description = "Reporting Utilities for the Squish GUI Tester" -license = { text = "..." } \ No newline at end of file +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: BSD License", + "Operating System :: OS Independent", +] + +[project.urls] +"Homepage" = "https://github.com/CyberAlpaca/squish-api-python-extension" +"Cyber Alpaca" = "https://cyberalpaca.com" \ No newline at end of file From 77cac46192d3429211cd1c38a690303a9830ff35 Mon Sep 17 00:00:00 2001 From: Adakar Date: Fri, 7 Apr 2023 19:32:01 +0200 Subject: [PATCH 12/16] Improve squape-report docstrings --- squape-report/squape/report.py | 100 ++++++++++++++++++++++++--------- 1 file changed, 72 insertions(+), 28 deletions(-) diff --git a/squape-report/squape/report.py b/squape-report/squape/report.py index 3c80191..91f455f 100644 --- a/squape-report/squape/report.py +++ b/squape-report/squape/report.py @@ -4,14 +4,13 @@ # All rights reserved. # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. -import sys from contextlib import contextmanager -import test import squish +import test -class LogLevel(): +class LogLevel: DEBUG = 10 LOG = 20 WARNING = 30 @@ -35,13 +34,22 @@ def __is_level_enabled(level: LogLevel) -> bool: def debug(msg: str, details: str = "") -> None: - """Adds a DEBUG entry to Squish's test report with the given message and detailes. - The message is in fact a LOG message with a DEBUG prefix. The message will be - visible only if the LOGLEVEL is set to DEBUG + """Adds a DEBUG-level log entry with the given message and details to a test report. + + This function adds a log message to Squish's test report at the DEBUG log level, + which allows for detailed debugging information to be recorded. + The log message will include the given message and details provided as arguments. + The message will be prefixed with the string 'DEBUG: ' to indicate its log level. + + The log message will only be visible if the LOGLEVEL is set to DEBUG. + Otherwise, it will be ignored and not included in the test report. Args: - msg (str): Message - detail (str, optional): Details of the message. Defaults to "". + - msg (str): The message to include in the log entry. + - details (str): Optional additional details to include in the log entry. + + Returns: + None """ if __is_level_enabled(LogLevel.DEBUG): test.fixateResultContext(1) @@ -52,12 +60,21 @@ def debug(msg: str, details: str = "") -> None: def log(msg: str, details: str = "") -> None: - """Adds a LOG entry to Squish's test report with the given message and detailes. - The message will be visible only if the LOGLEVEL is set to LOG or lower + """Adds a log entry with the given message and details to a test report. + + This function adds a log message to Squish's test report at the LOG log level + or lower, depending on the current log level setting. + The log message will include the given message and details provided as arguments. + + The log message will only be visible if the LOGLEVEL is set to LOG or lower. + Otherwise, it will be ignored and not included in the test report. Args: - msg (str): Message - detail (str, optional): Details of the message. Defaults to "". + - msg (str): The message to include in the log entry. + - details (str): Optional additional details to include in the log entry. + + Returns: + None """ if __is_level_enabled(LogLevel.LOG): test.fixateResultContext(1) @@ -68,12 +85,22 @@ def log(msg: str, details: str = "") -> None: def warning(msg: str, details: str = "") -> None: - """Adds a WARNING entry to Squish's test report with the given message and detailes. - The message will be visible only if the LOGLEVEL is set to WARNING or lower + """Adds a warning entry with the given message and details to a test report. + + This function adds a warning message to Squish's test report at the WARNING + log level or lower, depending on the current log level setting. + The warning message will include the given message and details provided + as arguments. + + The warning message will only be visible if the LOGLEVEL is set to WARNING or lower. + Otherwise, it will be ignored and not included in the test report. Args: - msg (str): Message - detail (str, optional): Details of the message. Defaults to "". + - msg (str): The message to include in the warning entry. + - details (str): Optional additional details to include in the warning entry. + + Returns: + None """ if __is_level_enabled(LogLevel.WARNING): test.fixateResultContext(1) @@ -84,12 +111,21 @@ def warning(msg: str, details: str = "") -> None: def fail(msg: str, details: str = "") -> None: - """Adds a FAIL entry to Squish's test report with the given message and detailes. - The message will be visible only if the LOGLEVEL is set to FAIL or lower + """Adds a fail entry with the given message and details to a test report. + + This function adds a fail message to Squish's test report at the FAIL log level + or lower, depending on the current log level setting. + The fail message will include the given message and details provided as arguments. + + The fail message will only be visible if the LOGLEVEL is set to FAIL or lower. + Otherwise, it will be ignored and not included in the test report. Args: - msg (str): Message - detail (str, optional): Details of the message. Defaults to "". + - msg (str): The message to include in the fail entry. + - details (str): Optional additional details to include in the fail entry. + + Returns: + None """ if __is_level_enabled(LogLevel.FAIL): test.fixateResultContext(1) @@ -100,13 +136,21 @@ def fail(msg: str, details: str = "") -> None: def fatal(msg: str, details: str = "") -> None: - """Adds a FATAL entry to Squish's test report with the given message and detailes - then interrupts the test execution. - The message will be visible only if the LOGLEVEL is set to FATAL or lower + """Adds a fatal entry with the given message and details to a test report. + + This function adds a fatal message to Squish's test report at the FATAL log level + or lower, depending on the current log level setting. + The fatal message will include the given message and details provided as arguments. + + The fatal message will only be visible if the LOGLEVEL is set to FATAL or lower. + Otherwise, it will be ignored and not included in the test report. Args: - msg (str): Message - detail (str, optional): Details of the message. Defaults to "". + - msg (str): The message to include in the fatal entry. + - details (str): Optional additional details to include in the fatal entry. + + Returns: + None """ if __is_level_enabled(LogLevel.FATAL): test.fixateResultContext(1) @@ -119,12 +163,12 @@ def fatal(msg: str, details: str = "") -> None: @contextmanager def section(title: str, description: str = "") -> None: - """Allows using sections as context managers + """Allows using Squish's sections as context managers https://doc.qt.io/squish/squish-api.html#test-startsection-function Args: - title (str): the section title - description (str): the section description + title (str): Section title + description (str): Optional additional description of the section Examples: with section("Add new person"): squish.type(squish.waitForObject(names.forename_edit), "Bob") From 7ef30982ff6f01408b6a98e2bec870f88cdff38e Mon Sep 17 00:00:00 2001 From: Adakar Date: Fri, 7 Apr 2023 19:33:28 +0200 Subject: [PATCH 13/16] Fix typo in pre-commit configuration --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b4a3e39..41cb119 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,4 @@ -default_languages_version: +default_language_version: python: python3.8 repos: - repo: https://github.com/pre-commit/pre-commit-hooks From 78afe9753e853594f66620596b4be0fe19745b4a Mon Sep 17 00:00:00 2001 From: Adakar Date: Fri, 7 Apr 2023 20:26:48 +0200 Subject: [PATCH 14/16] Function adding LOGLEVEL support to the Squish 'test' module --- squape-report/squape/report.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/squape-report/squape/report.py b/squape-report/squape/report.py index 91f455f..ffd00bb 100644 --- a/squape-report/squape/report.py +++ b/squape-report/squape/report.py @@ -161,6 +161,39 @@ def fatal(msg: str, details: str = "") -> None: test.restoreResultContext() +def enable_loglevel_in_test_module(): + """Adds support for log levels to the Squish 'test' module. + + DISCLAIMER: This function uses monkeypathching + https://en.wikipedia.org/wiki/Monkey_patch + + This function overwrites some of the existing functions in the 'test' module + to support logging at different log levels. + Furthermore, it enhances the functionality of the 'test' module by adding + a new test.debug(...) function. + + By default, the 'test' module does not support LOGLEVEL at all. + However, this function adds support for setting the log level to a higher + or lower level, depending on the needs of the developer. + + After calling this function, the following 'test' module's functions will support + LOGLEVEL report setting: + - test.debug(...) + - test.log(...) + - test.warning(...) + - test.fail(...) + - test.fatal(...) + + Returns: + None + """ + test.debug = debug + test.log = log + test.warning = warning + test.fail = fail + test.fatal = fatal + + @contextmanager def section(title: str, description: str = "") -> None: """Allows using Squish's sections as context managers From 1e1b19416cb0d73c61a59e574ce5827cbba84799 Mon Sep 17 00:00:00 2001 From: Adakar Date: Wed, 12 Apr 2023 20:42:56 +0200 Subject: [PATCH 15/16] Improve report.fatal(...) documentation --- squape-report/squape/report.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/squape-report/squape/report.py b/squape-report/squape/report.py index ffd00bb..b27e892 100644 --- a/squape-report/squape/report.py +++ b/squape-report/squape/report.py @@ -136,7 +136,8 @@ def fail(msg: str, details: str = "") -> None: def fatal(msg: str, details: str = "") -> None: - """Adds a fatal entry with the given message and details to a test report. + """Adds a fatal entry with the given message and details to a test report, + then aborts the test case execution. This function adds a fatal message to Squish's test report at the FATAL log level or lower, depending on the current log level setting. @@ -145,6 +146,8 @@ def fatal(msg: str, details: str = "") -> None: The fatal message will only be visible if the LOGLEVEL is set to FATAL or lower. Otherwise, it will be ignored and not included in the test report. + After adding the fatal message, the function aborts the test case execution. + Args: - msg (str): The message to include in the fatal entry. - details (str): Optional additional details to include in the fatal entry. From 8f5def1f18da0c5f6c121471f74730ecd12b0cc4 Mon Sep 17 00:00:00 2001 From: Adakar Date: Wed, 12 Apr 2023 21:03:05 +0200 Subject: [PATCH 16/16] Improvements in vps.vph_property(...) --- squape-report/squape/vps.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/squape-report/squape/vps.py b/squape-report/squape/vps.py index 1b2463a..c71bd47 100644 --- a/squape-report/squape/vps.py +++ b/squape-report/squape/vps.py @@ -10,9 +10,10 @@ def vph_property( object_name: any, property_name: str, expected_value: any, msg: str -) -> None: - """The function verifies the property of the given object. - It highlights the verified object to make it standing out. +) -> bool: + """ "Highlights the object then verifies its property. + The object remains highlighted during verification to make it easier to identify + on potential screenshots. Args: object_name (any): symbolic name, real name, or object reference @@ -20,11 +21,12 @@ def vph_property( expected_value (any): expected value of the verified property msg (str): verification message Returns: - None + bool: True if verification is positive, False otherwise """ obj = squish.waitForObjectExists(object_name) property_value = getattr(obj, property_name) squish.highlightObject(obj, 200, False) - test.compare(property_value, expected_value, msg) + result = test.compare(property_value, expected_value, msg) squish.snooze(0.2) + return result