Skip to content

Commit

Permalink
New "exception" checker, for expected exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
FherStk committed Jan 19, 2025
1 parent 315ede5 commit 8bc65de
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions dmoj/checkers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
floatsrel,
identical,
linecount,
exception,
linematches,
rstripped,
sorted,
Expand Down
1 change: 1 addition & 0 deletions dmoj/checkers/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ floatsabs: Checker
floatsrel: Checker
identical: Checker
linecount: Checker
exception: Checker
linematches: Checker
rstripped: Checker
sorted: Checker
Expand Down
30 changes: 30 additions & 0 deletions dmoj/checkers/exception.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from re import split as resplit
from typing import Union

from dmoj.result import CheckerResult
from dmoj.utils.unicode import utf8bytes

verdict = '\u2717\u2713'


def check(
process_output: bytes, judge_output: bytes, point_value: float = 1, exceptionType: str = '', **kwargs
) -> Union[CheckerResult, bool]:
found = kwargs['result'].feedback.split('.')[-1]
passed = (found == exceptionType or len(found) > 0 and len(exceptionType) == 0)

if kwargs['result'].output != '':
extended_feedback = ('Any type of exception' if exceptionType == '' else 'An exception of type "' + exceptionType) + '" was expected, but none has been raised:\nYour output: ' + kwargs['result'].output
else:
extended_feedback = None if passed else 'An exception was raised, but another exception type was expected:\nRaised: ' + found + '\nExpected: ' + exceptionType

kwargs['result'].proc_output = ''
kwargs['result'].result_flag = 0 if passed else 1

return CheckerResult(
passed=passed,
points=point_value,
extended_feedback=extended_feedback
)

check.run_on_error = True # type: ignore

0 comments on commit 8bc65de

Please sign in to comment.