-
Notifications
You must be signed in to change notification settings - Fork 1
Squape Report #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
160e4d4
Add squape-report package
Adakar 04105bd
vps module with vph_property to squape-report
Adakar af6e697
Add new log entries logic and type
Adakar e11480d
Update README with installation instructions and requirements, remove…
Adakar a18e1f0
Group test and squish modules together while reordering imports
Adakar 64456d6
Drop LogLever inharitance from Enum to ease comparision
pawtom 59fd433
Use fixateResultContext(1) in messages.py
pawtom c4c5fcb
For fatal messages use testSettings.throwOnFailure functionality
pawtom cdfa53b
Renamed messages module to report
pawtom 58393be
Add and update README and LICENSE files.
Adakar e3f46d7
Update squape-report packaging configuration
Adakar 77cac46
Improve squape-report docstrings
Adakar 7ef3098
Fix typo in pre-commit configuration
Adakar 78afe97
Function adding LOGLEVEL support to the Squish 'test' module
Adakar 1e1b194
Improve report.fatal(...) documentation
Adakar 8f5def1
Improvements in vps.vph_property(...)
Adakar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
|
|
||
| [](https://cyberalpaca.com) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # 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 = "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" | ||
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,222 @@ | ||
| # -*- 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. | ||
| from contextlib import contextmanager | ||
|
|
||
| import squish | ||
| import test | ||
|
|
||
|
|
||
| class LogLevel: | ||
| 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-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): 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) | ||
| try: | ||
| test.log(f"[DEBUG] {msg}", details) | ||
| finally: | ||
| test.restoreResultContext() | ||
|
|
||
|
|
||
| def log(msg: str, details: str = "") -> None: | ||
| """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): 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) | ||
| try: | ||
| test.log(msg, details) | ||
| finally: | ||
| test.restoreResultContext() | ||
|
|
||
|
|
||
| def warning(msg: str, details: str = "") -> None: | ||
| """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): 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) | ||
| try: | ||
| test.warning(msg, details) | ||
| finally: | ||
| test.restoreResultContext() | ||
|
|
||
|
|
||
| def fail(msg: str, details: str = "") -> None: | ||
| """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): 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) | ||
| try: | ||
| test.fail(msg, details) | ||
| finally: | ||
| test.restoreResultContext() | ||
|
|
||
|
|
||
| def fatal(msg: str, details: str = "") -> None: | ||
| """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. | ||
| 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. | ||
|
|
||
| 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. | ||
|
|
||
| Returns: | ||
| None | ||
| """ | ||
| if __is_level_enabled(LogLevel.FATAL): | ||
| test.fixateResultContext(1) | ||
| try: | ||
| squish.testSettings.throwOnFailure = True | ||
| test.fatal(msg, details) | ||
| finally: | ||
| 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 | ||
|
|
||
| https://doc.qt.io/squish/squish-api.html#test-startsection-function | ||
| Args: | ||
| 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") | ||
| squish.mouseClick(squish.waitForObject(names.ok_button)) | ||
| """ | ||
|
|
||
| test.fixateResultContext(1) | ||
| test.startSection(title, description) | ||
| test.restoreResultContext() | ||
| try: | ||
| yield | ||
| except Exception: | ||
| raise | ||
| finally: | ||
| test.endSection() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # -*- 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 squish | ||
| import test | ||
|
|
||
|
|
||
| def vph_property( | ||
| object_name: any, property_name: str, expected_value: any, msg: str | ||
| ) -> bool: | ||
| """ "Highlights the object then verifies its property. | ||
| The object remains highlighted during verification to make it easier to identify | ||
| on potential screenshots. | ||
|
|
||
Adakar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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: | ||
| bool: True if verification is positive, False otherwise | ||
| """ | ||
|
|
||
| obj = squish.waitForObjectExists(object_name) | ||
| property_value = getattr(obj, property_name) | ||
| squish.highlightObject(obj, 200, False) | ||
| result = test.compare(property_value, expected_value, msg) | ||
| squish.snooze(0.2) | ||
| return result | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this approach putting fatal() inside the try/catch block will not terminate the test case.