changeset 205:166a23999bf7

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.
author Oleg Oshmyan <chortos@inbox.lv>
date Wed, 17 Aug 2011 20:44:54 +0300
parents 00c80bba7f13
children 4edb6ef5a676
files upreckon/config.py upreckon/problem.py upreckon/testcases.py
diffstat 3 files changed, 13 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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}
--- 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
--- 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):