# HG changeset patch # User Oleg Oshmyan # Date 1313603094 -10800 # Node ID 166a23999bf7e929b2ae063ce06caf887dd5bf92 # Parent 00c80bba7f13275656c558ec566593d8c6d09a80 Added confvar okexitcodemask; changed the validator protocol Callable validators now return three-tuples (number granted, bool correct, str comment) instead of two-tuples (number granted, str comment). They are still allowed to return single numbers. Callable validators must now explicitly raise upreckon.exceptions.WrongAnswer if they want the verdict to be Wrong Answer rather than Partly Correct. okexitcodemask specifies a bitmask ANDed with the exit code of the external validator to get a boolean flag showing whether the answer is to be marked as 'OK' rather than 'partly correct'. The bits covered by the bitmask are reset to zeroes before devising the number of points granted from the resulting number. diff -r 00c80bba7f13 -r 166a23999bf7 upreckon/config.py --- a/upreckon/config.py Wed Aug 17 18:48:21 2011 +0300 +++ b/upreckon/config.py Wed Aug 17 20:44:54 2011 +0300 @@ -37,6 +37,7 @@ 'dummyoutname': '', 'tester': None, 'maxexitcode': 0, + 'okexitcodeflag': 0, 'inname': '', 'ansname': '', 'force_zero_exitcode': True} diff -r 00c80bba7f13 -r 166a23999bf7 upreckon/problem.py --- a/upreckon/problem.py Wed Aug 17 18:48:21 2011 +0300 +++ b/upreckon/problem.py Wed Aug 17 20:44:54 2011 +0300 @@ -192,18 +192,17 @@ # verdict = 'unknown error [this may be a bug in Upreckon]%s' % strerror(sys.exc_info()[1]) else: try: - granted, comment = granted + granted, correct, comment = granted except TypeError: comment = '' + correct = granted >= 1 else: if comment: comment = ' (%s)' % comment - if granted >= 1: + if correct: contexts[-1].case_correct() prob.testcases.send(True) verdict = 'OK' + comment - elif not granted: - verdict = 'wrong answer' + comment else: verdict = 'partly correct' + comment granted *= case.points diff -r 00c80bba7f13 -r 166a23999bf7 upreckon/testcases.py --- a/upreckon/testcases.py Wed Aug 17 18:48:21 2011 +0300 +++ b/upreckon/testcases.py Wed Aug 17 20:44:54 2011 +0300 @@ -235,9 +235,16 @@ if case.process.returncode: raise WrongAnswer(comment) else: - return 1, comment + return 1, True, comment else: - return case.process.returncode / case.problem.config.maxexitcode, comment + if case.problem.config.okexitcodeflag: + correct = bool(case.process.returncode & case.problem.config.okexitcodeflag) + case.process.returncode &= ~case.problem.config.okexitcodeflag + else: + correct = case.process.returncode >= case.problem.config.maxexitcode + if not correct and not case.process.returncode: + raise WrongAnswer(comment) + return case.process.returncode / case.problem.config.maxexitcode, correct, comment class BatchTestCase(ValidatedTestCase):