-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexceptions.py
More file actions
82 lines (56 loc) · 2.73 KB
/
exceptions.py
File metadata and controls
82 lines (56 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# -*- coding: utf-8 -*-
"""Custom exceptions for the AutomatedGrader class."""
from pydantic import BaseModel, Field
from .config import AGRubric
class AGExceptionModel(BaseModel):
"""A Pydantic model for the custom exceptions for the AutomatedGrader class."""
message: str = Field(..., description="The message to display to the user.")
penalty_pct: float = Field(
..., description="The percentage of the total grade to deduct for this error.", ge=0, le=1
)
class AGException(Exception):
"""A custom base exception for the AutomatedGrader class."""
message: str
penalty_pct: float
def __init__(self, ag_exception_model: AGExceptionModel):
super().__init__(ag_exception_model.message)
self.message = ag_exception_model.message
self.penalty_pct = ag_exception_model.penalty_pct
class InvalidJSONResponseError(AGException):
"""A custom exception for the AutomatedGrader class."""
def __init__(self, message):
penalty_pct = AGRubric.INVALID_JSON_RESPONSE_PENALTY_PCT
ag_exception_model = AGExceptionModel(message=message, penalty_pct=penalty_pct)
super().__init__(ag_exception_model)
class InvalidResponseStructureError(AGException):
"""A custom exception for the AutomatedGrader class."""
def __init__(self, message):
penalty_pct = AGRubric.INVALID_RESPONSE_STRUCTURE_PENALTY_PCT
ag_exception_model = AGExceptionModel(message=message, penalty_pct=penalty_pct)
super().__init__(ag_exception_model)
class IncorrectResponseValueError(AGException):
"""A custom exception for the AutomatedGrader class."""
def __init__(self, message):
penalty_pct = AGRubric.INCORRECT_RESPONSE_VALUE_PENALTY_PCT
ag_exception_model = AGExceptionModel(message=message, penalty_pct=penalty_pct)
super().__init__(ag_exception_model)
class IncorrectResponseTypeError(AGException):
"""A custom exception for the AutomatedGrader class."""
def __init__(self, message):
penalty_pct = AGRubric.INCORRECT_RESPONSE_TYPE_PENALTY_PCT
ag_exception_model = AGExceptionModel(message=message, penalty_pct=penalty_pct)
super().__init__(ag_exception_model)
class ResponseFailedError(AGException):
"""A custom exception for the AutomatedGrader class."""
def __init__(self, message):
penalty_pct = AGRubric.RESPONSE_FAILED_PENALTY_PCT
ag_exception_model = AGExceptionModel(message=message, penalty_pct=penalty_pct)
super().__init__(ag_exception_model)
VALID_MESSAGE_TYPES = [
"Success",
InvalidJSONResponseError.__name__,
IncorrectResponseTypeError.__name__,
IncorrectResponseValueError.__name__,
InvalidResponseStructureError.__name__,
ResponseFailedError.__name__,
]