Source code for guibot.errors
# Copyright 2013-2018 Intranet AG and contributors
#
# guibot is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# guibot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with guibot. If not, see <http://www.gnu.org/licenses/>.
"""
Exceptions used by all guibot interfaces and modules.
SUMMARY
------------------------------------------------------
INTERFACE
------------------------------------------------------
"""
__all__ = [
"GuiBotError",
"FileNotFoundError",
"IncompatibleTargetError",
"IncompatibleTargetFileError",
"FindError",
"NotFindError",
"UnsupportedBackendError",
"MissingHotmapError",
"UninitializedBackendError",
]
[docs]
class GuiBotError(Exception):
"""GuiBot exception base class."""
[docs]
class FileNotFoundError(GuiBotError):
"""Exception raised when a picture file cannot be found on disc."""
[docs]
class IncompatibleTargetError(GuiBotError):
"""Exception raised when a matched target is of type that cannot be handled by the finder."""
[docs]
class IncompatibleTargetFileError(GuiBotError):
"""Exception raised when a matched target is restored from a file of unsupported type."""
[docs]
class FindError(GuiBotError):
"""Exception raised when an Image cannot be found on the screen."""
def __init__(self, failed_target: "Target" = None) -> None:
"""
Build the exception possibly providing the failed target.
:param failed_target: the target that wasn't found
"""
if failed_target:
message = "The target %s could not be found on the screen" % failed_target
else:
message = "The target could not be found on the screen"
super(FindError, self).__init__(message)
[docs]
class NotFindError(GuiBotError):
"""Exception raised when an Image can be found on the screen but should not be."""
def __init__(self, failed_target: "Target" = None) -> None:
"""
Build the exception possibly providing the failed target.
:param failed_target: the target that was found
"""
if failed_target:
message = (
"The target %s was found on the screen while it was not expected"
% failed_target
)
else:
message = "The target was found on the screen while it was not expected"
super(NotFindError, self).__init__(message)
[docs]
class UnsupportedBackendError(GuiBotError):
"""Exception raised when a non-existent method is used for finding a target."""
[docs]
class MissingHotmapError(GuiBotError):
"""Exception raised when an attempt to access a non-existent hotmap in the image logger is made."""
[docs]
class UninitializedBackendError(GuiBotError):
"""Exception raised when a region is created within an empty screen (a disconnected display control backend)."""