-
Notifications
You must be signed in to change notification settings - Fork 1
Settings context #7
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
11 commits
Select commit
Hold shift + click to select a range
5faccc6
Add settings module to offer using various test settings as context m…
pawtom 769a744
Extend README
pawtom 67b506c
Add custom SquishCapability exception
pawtom c889214
Add missing docstring for _ctx_settings
pawtom 0131af5
Add default values to some settings functions
pawtom f8ba7ca
Remove logScreenshotonError as it was impossible to make it working c…
pawtom f2075fb
Dont yield value returned by _ctx_settings
pawtom bd2d542
Add examples to docstrings
pawtom 9f1987d
Change exception name to SquishCapabilityError
pawtom cb0cf0c
Improve function signatures where default value is provided
pawtom 5bdcdf0
Add more examples to doc strings
pawtom 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # -*- 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. |
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 @@ | ||
| # -*- 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. | ||
|
|
||
|
|
||
| class SquishCapabilityError(Exception): | ||
| """ | ||
| Indicate that squape functionality cannot be used | ||
| because it is not supported by Squish version in use. | ||
| """ | ||
|
|
||
| def __init__(self, message): | ||
| super().__init__(message) |
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,332 @@ | ||
| # -*- 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 | ||
| from squape.internal.exceptions import SquishCapabilityError | ||
|
|
||
|
|
||
| @contextmanager | ||
| def _ctx_settings(setting_name, value): | ||
| """ | ||
| A context manager that temporarily sets a Squish testSettings to a given value. | ||
|
|
||
| Args: | ||
| setting_name (str): The name of the Squish testSettings to set. | ||
| value (Any): The value to set the Squish test setting to. | ||
|
|
||
| Raises: | ||
| SquishCapability: If the Squish version does not support the given test setting. | ||
|
|
||
| """ | ||
| try: | ||
| current_value = getattr(squish.testSettings, setting_name) | ||
| setattr(squish.testSettings, setting_name, value) | ||
| except AttributeError: | ||
| raise SquishCapabilityError( | ||
| f"Your Squish version does not support test setting {setting_name}" | ||
| ) | ||
|
|
||
| try: | ||
| yield | ||
| except Exception: | ||
| raise | ||
| finally: | ||
| setattr(squish.testSettings, setting_name, current_value) | ||
|
|
||
|
|
||
| @contextmanager | ||
| def logScreenshotOnPass(enabled: bool = True) -> None: | ||
| """Allows using logScreenshotOnPass test setting as context managers. | ||
| https://doc.qt.io/squish/squish-api.html#bool-testsettings-logscreenshotonpass | ||
|
|
||
| Args: | ||
| enabled (bool): A boolean value indicating whether to enable logging | ||
| of screenshots on PASS test result. Defaulting to True. | ||
|
|
||
| Example: | ||
| with logScreenshotOnPass(): | ||
| # code with verifications | ||
| """ | ||
| with _ctx_settings("logScreenshotOnPass", enabled): | ||
| yield | ||
|
|
||
|
|
||
| @contextmanager | ||
| def logScreenshotOnFail(enabled: bool = True) -> None: | ||
| """Allows using logScreenshotOnFail test setting as context managers. | ||
| https://doc.qt.io/squish/squish-api.html#bool-testsettings-logscreenshotonfail | ||
|
|
||
| Args: | ||
| enabled (bool): A boolean value indicating whether to enable logging | ||
| of screenshots on FAIL test result. Defaulting to True. | ||
|
|
||
| Example: | ||
| with logScreenshotOnFail(): | ||
| # code with verifications | ||
| """ | ||
|
|
||
| with _ctx_settings("logScreenshotOnFail", enabled): | ||
| yield | ||
|
|
||
|
|
||
| @contextmanager | ||
| def logScreenshotOnWarning(enabled: bool = True) -> None: | ||
| """Allows using logScreenshotOnWarning test setting as context managers. | ||
| https://doc.qt.io/squish/squish-api.html#bool-testsettings-logscreenshotonwarning | ||
|
|
||
| Args: | ||
| enabled (bool): A boolean value indicating whether to enable logging | ||
| of screenshots on warning log entry. Defaulting to True. | ||
|
|
||
| Example: | ||
| with logScreenshotOnWarning(): | ||
| # code where warning messages might happen | ||
| """ | ||
| with _ctx_settings("logScreenshotOnWarning", enabled): | ||
| yield | ||
|
|
||
|
|
||
| @contextmanager | ||
| def silentVerifications(enabled: bool = True) -> None: | ||
| """Allows using silentVerifications test setting as context managers. | ||
| https://doc.qt.io/squish/squish-api.html#bool-testsettings-silentverifications | ||
|
|
||
| Args: | ||
| enabled (bool): Whether silent verifications are enabled. Defaulting to True | ||
|
|
||
| Example: | ||
| with silentVerifications(): | ||
| # code with test.vp statements | ||
| """ | ||
| with _ctx_settings("silentVerifications", enabled): | ||
| yield | ||
|
|
||
|
|
||
| @contextmanager | ||
| def imageSearchTolerant(enabled: bool = True) -> None: | ||
| """Allows using imageSearchTolerant test setting as context managers. | ||
| https://doc.qt.io/squish/squish-api.html#bool-testsettings-imagesearchtolerant | ||
|
|
||
| Args: | ||
| enabled (bool): Whether image search with tolerance is enabled. | ||
| Defaulting to True. | ||
|
|
||
| Example: | ||
| with imageSearchTolerant(), imageSearchThreshold(95): | ||
| test.imagePresent() | ||
|
|
||
| """ | ||
| with _ctx_settings("imageSearchTolerant", enabled): | ||
| yield | ||
|
|
||
|
|
||
| @contextmanager | ||
| def imageSearchThreshold(threshold: float) -> None: | ||
| """Allows using imageSearchThreshold test setting as context managers. | ||
| https://doc.qt.io/squish/squish-api.html#number-testsettings-imagesearchthreshold | ||
|
|
||
| Args: | ||
| threshold (float): the threshold for image search. | ||
|
|
||
| Example: | ||
| with imageSearchTolerant(), imageSearchThreshold(95): | ||
| test.imagePresent("image.png") | ||
| """ | ||
| with _ctx_settings("imageSearchThreshold", threshold): | ||
| yield | ||
|
|
||
|
|
||
| @contextmanager | ||
| def imageSearchMultiscale(enabled: bool = True) -> None: | ||
| """Allows using imageSearchMultiscale test setting as context managers. | ||
| https://doc.qt.io/squish/squish-api.html#bool-testsettings-imagesearchmultiscale | ||
|
|
||
| Args: | ||
| enabled (bool): Whether multi-scale image search is enabled. Defaulting to True | ||
|
|
||
| Example: | ||
| with imageSearchMultiscale(), imageSearchMaxScale(150): | ||
| test.imagePresent("image1.png") | ||
| test.imagePresent("image2.png") | ||
|
|
||
| """ | ||
| with _ctx_settings("imageSearchMultiscale", enabled): | ||
| yield | ||
|
|
||
|
|
||
| @contextmanager | ||
| def imageSearchMinScale(min_scale: float) -> None: | ||
| """Allows using imageSearchMinScale test setting as context managers. | ||
| https://doc.qt.io/squish/squish-api.html#number-testsettings-imagesearchminscale | ||
|
|
||
| Args: | ||
| min_scale (float): A float value indicating the minimum scale for image search. | ||
|
|
||
| Example: | ||
| with imageSearchMultiscale(), imageSearchMinScale(75): | ||
| test.imagePresent("image1.png") | ||
| test.imagePresent("image2.png") | ||
| """ | ||
| with _ctx_settings("imageSearchMinScale", min_scale): | ||
| yield | ||
|
|
||
|
|
||
| @contextmanager | ||
| def imageSearchMaxScale(max_scale: float) -> None: | ||
| """Allows using imageSearchMaxScale test setting as context managers. | ||
| https://doc.qt.io/squish/squish-api.html#number-testsettings-imagesearchmaxscale | ||
|
|
||
| Args: | ||
| max_scale (float): A float value indicating the maximum scale for image search. | ||
|
|
||
| Example: | ||
| with imageSearchMultiscale(), imageSearchMaxScale(150): | ||
| test.imagePresent("image1.png") | ||
| test.imagePresent("image2.png") | ||
| """ | ||
| with _ctx_settings("imageSearchMaxScale", max_scale): | ||
| yield | ||
|
|
||
|
|
||
| @contextmanager | ||
| def waitForObjectTimeout(timeout_ms: int) -> None: | ||
| """Allows using waitForObjectTimeout test setting as context managers. | ||
| https://doc.qt.io/squish/squish-api.html#integer-testsettings-waitforobjecttimeout | ||
|
|
||
| Args: | ||
| timeout_ms (int): A integer value indicating the timeout in ms. | ||
|
|
||
| Example: | ||
| with waitForObjectTimeout(500): | ||
| waitForObject(names.obj1) | ||
| waitForObject(names.obj2) | ||
| """ | ||
| with _ctx_settings("waitForObjectTimeout", timeout_ms): | ||
| yield | ||
|
|
||
|
|
||
| @contextmanager | ||
| def objectNotFoundDebugging(enabled: bool) -> None: | ||
| """Allows using objectNotFoundDebugging test setting as context managers. | ||
| https://doc.qt.io/squish/squish-api.html#bool-testsettings-objectnotfounddebugging | ||
|
|
||
| Args: | ||
| enabled (bool): Whether to enable debugging when object is not found. | ||
|
|
||
| Example: | ||
| with objectNotFoundDebugging(False): | ||
| waitForObject(names.obj1) | ||
| waitForObject(names.obj2) | ||
| """ | ||
| with _ctx_settings("objectNotFoundDebugging", enabled): | ||
| yield | ||
|
|
||
|
|
||
| @contextmanager | ||
| def imageNotFoundDebugging(enabled: bool) -> None: | ||
| """Allows using imageNotFoundDebugging test setting as context managers. | ||
| https://doc.qt.io/squish/squish-api.html#bool-testsettings-imagenotfounddebugging | ||
|
|
||
| Args: | ||
| enabled (bool): Whether to enable debugging when image is not found. | ||
|
|
||
| Example: | ||
| with imageNotFoundDebugging(False): | ||
| waitForImage("image1.png") | ||
| waitForImage("image2.png") | ||
| """ | ||
| with _ctx_settings("imageNotFoundDebugging", enabled): | ||
| yield | ||
|
|
||
|
|
||
| @contextmanager | ||
| def textNotFoundDebugging(enabled: bool) -> None: | ||
| """Allows using textNotFoundDebugging test setting as context managers. | ||
| https://doc.qt.io/squish/squish-api.html#bool-testsettings-textnotfounddebugging | ||
|
|
||
| Args: | ||
| enabled (bool): Whether to enable debugging when a OCR Text is not found. | ||
|
|
||
| Example: | ||
| with textNotFoundDebugging(False): | ||
| waitForOcrText("Frog") | ||
| waitForOcrText("Alpaca") | ||
| """ | ||
| with _ctx_settings("textNotFoundDebugging", enabled): | ||
| yield | ||
|
|
||
|
|
||
| @contextmanager | ||
| def defaultOcrLanguage(language: str) -> None: | ||
| """Allows using defaultOcrLanguage test setting as context managers. | ||
| https://doc.qt.io/squish/squish-api.html#bool-testsettings-defaultocrlanguage | ||
|
|
||
| Args: | ||
| language (str): string text representing the Language to be used | ||
| for OCR Text search | ||
|
|
||
| Example: | ||
| with defaultOcrLanguage("Polish"): | ||
| waitForOcrText("Dom") | ||
| waitForOcrText("Miasto") | ||
| """ | ||
| with _ctx_settings("defaultOcrLanguage", language): | ||
| yield | ||
|
|
||
|
|
||
| @contextmanager | ||
| def breakOnFailure(enabled: bool = True) -> None: | ||
| """Allows using breakOnFailure test setting as context managers. | ||
| https://doc.qt.io/squish/squish-api.html#bool-testsettings-breakonfailure | ||
|
|
||
| Args: | ||
| enabled (bool): Whether to enable the debugger to stop | ||
| on every failed verification | ||
|
|
||
| Example: | ||
| with breakOnFailure(): | ||
| # code with verifications | ||
| """ | ||
| with _ctx_settings("breakOnFailure", enabled): | ||
| yield | ||
|
|
||
|
|
||
| @contextmanager | ||
| def throwOnFailure(enabled: bool) -> None: | ||
| """Allows using throwOnFailure test setting as context managers. | ||
| https://doc.qt.io/squish/squish-api.html#bool-testsettings-throwonfailure | ||
|
|
||
| Args: | ||
| enabled (bool): Whether to enable to raise a script error | ||
| on every failed verification | ||
|
|
||
| Example: | ||
| with throwOnFailure(): | ||
| # code with verifications | ||
|
|
||
| """ | ||
| with _ctx_settings("throwOnFailure", enabled): | ||
| yield | ||
|
|
||
|
|
||
| @contextmanager | ||
| def retryDuration(duration_ms: int) -> None: | ||
| """Allows using retryDuration test setting as context managers. | ||
| https://doc.qt.io/squish/squish-api.html#integer-testsettings-retryduration | ||
|
|
||
| Args: | ||
| duration_ms (int): The duration in milliseconds after which | ||
| the verification fails | ||
|
|
||
| Example: | ||
| with retryDuration(5000): | ||
| test.vp("VP1") | ||
|
|
||
| """ | ||
| with _ctx_settings("retryDuration", duration_ms): | ||
| yield | ||
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.
Uh oh!
There was an error while loading. Please reload this page.