Coverage for exceptions / exceptions.py: 100.00%
52 statements
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-22 10:24 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-22 10:24 +0000
1# Copyright 2025 THU-BPM MarkDiffusion.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
16class LengthMismatchError(Exception):
17 """Exception raised when the expected and actual lengths do not match."""
18 def __init__(self, expected, actual):
19 message = f"Expected length: {expected}, but got {actual}."
20 super().__init__(message)
23class InvalidTextSourceModeError(ValueError):
24 """Exception raised when an invalid text source mode is provided."""
25 def __init__(self, mode):
26 message = f"'{mode}' is not a valid text source mode. Choose 'natural' or 'generated'."
27 super().__init__(message)
30class AlgorithmNameMismatchError(ValueError):
31 """Exception raised when the algorithm name in the config does not match the expected watermark algorithm class."""
32 def __init__(self, expected, actual):
33 message = f"Config algorithm name '{actual}' does not match expected algorithm name '{expected}'."
34 super().__init__(message)
37class InvalidDirectAnalyzerTypeError(Exception):
38 """Exception raised when an invalid text quality analyzer type is provided."""
39 def __init__(self, message="Analyzer must be a type of DirectTextQualityAnalyzer"):
40 super().__init__(message)
43class InvalidReferencedAnalyzerTypeError(Exception):
44 """Exception raised when an invalid referenced text quality analyzer type is provided."""
45 def __init__(self, message="Analyzer must be a type of ReferencedTextQualityAnalyzer"):
46 super().__init__(message)
49class InvalidAnswerError(ValueError):
50 """Exception raised for an invalid answer input."""
51 def __init__(self, answer):
52 super().__init__(f"Invalid answer: {answer}")
55class TypeMismatchException(Exception):
56 """Exception raised when a type mismatch is found in the data."""
57 def __init__(self, expected_type: type, found_type: type, message: str = ""):
58 self.expected_type = expected_type
59 self.found_type = found_type
60 self.message = message
61 super().__init__(self.message or f"Expected all items to be of type {self.expected_type.__name__}, but found type {self.found_type.__name__}.")
64class ConfigurationError(Exception):
65 """Exception raised for errors in the configuration of success rate calculators."""
66 def __init__(self, message: str):
67 self.message = message
68 super().__init__(self.message)
71class OpenAIModelConfigurationError(Exception):
72 """Exception raised for errors in the OpenAI model configuration."""
73 def __init__(self, message: str):
74 super().__init__(message)
77class DiversityValueError(Exception):
78 """Exception raised when the diversity values are not within the expected range."""
79 def __init__(self, diversity_type: str):
80 message = f"{diversity_type} diversity must be one of 0, 20, 40, 60, 80, 100."
81 super().__init__(message)
84class CodeExecutionError(Exception):
85 """Exception raised when there is an error in code execution during tests."""
86 def __init__(self, message="Error during code execution"):
87 self.message = message
88 super().__init__(self.message)
90class InvalidDetectModeError(Exception):
91 """Exception raised for errors in the input detect mode."""
92 def __init__(self, mode, message="Invalid detect mode configuration"):
93 self.mode = mode
94 self.message = message
95 super().__init__(f"{message}: {mode}")
97class InvalidWatermarkModeError(Exception):
98 """Exception raised for errors in the input watermark mode."""
99 def __init__(self, mode, message="Invalid watermark mode configuration"):
100 self.mode = mode
101 self.message = message
102 super().__init__(f"{message}: {mode}")