diff 2.00/problem.py @ 26:5bbb68833868

Output text improvements Detailed error messages are now printed in more cases and have only their first letter forced into lowercase. The description of the --update option now describes properly what it does.
author Oleg Oshmyan <chortos@inbox.lv>
date Thu, 23 Sep 2010 23:50:45 +0000
parents c23d81f4a1a3
children 2b459f9743b4
line wrap: on
line diff
--- a/2.00/problem.py	Thu Sep 23 23:05:58 2010 +0000
+++ b/2.00/problem.py	Thu Sep 23 23:50:45 2010 +0000
@@ -32,9 +32,10 @@
 
 __all__ = 'Problem',
 
-# This should no more be needed; pass all work on to the TestCase inheritance tree
-# LIBRARY and STDIO refer to interactive aka reactive problems
-#BATCH, OUTONLY, LIBRARY, STDIO, BESTOUT = xrange(5)
+def strerror(e):
+	s = getattr(e, 'strerror')
+	if not s: s = str(e)
+	return ' (%s%s)' % (s[0].lower(), s[1:]) if s else ''
 
 class Cache(object):
 	def __init__(self, mydict):
@@ -95,41 +96,19 @@
 					else:
 						verdict = 'non-zero return code %d' % e.exitcode
 				except testcases.CannotStartTestee:
-					e = sys.exc_info()[1]
-					if e.upstream.strerror:
-						verdict = 'cannot launch the program to test (%s)' % e.upstream.strerror.lower()
-					else:
-						verdict = 'cannot launch the program to test'
+					verdict = 'cannot launch the program to test%s' % strerror(sys.exc_info()[1].upstream)
 				except testcases.CannotStartValidator:
-					e = sys.exc_info()[1]
-					if e.upstream.strerror:
-						verdict = 'cannot launch the validator (%s)' % e.upstream.strerror.lower()
-					else:
-						verdict = 'cannot launch the validator'
+					verdict = 'cannot launch the validator%s' % strerror(sys.exc_info()[1].upstream)
 				except testcases.CannotReadOutputFile:
-					e = sys.exc_info()[1]
-					if e.upstream.strerror:
-						verdict = 'cannot read the output file (%s)' % e.upstream.strerror.lower()
-					else:
-						verdict = 'cannot read the output file'
+					verdict = 'cannot read the output file%s' % strerror(sys.exc_info()[1].upstream)
 				except testcases.CannotReadInputFile:
-					e = sys.exc_info()[1]
-					if e.upstream.strerror:
-						verdict = 'cannot read the input file (%s)' % e.upstream.strerror.lower()
-					else:
-						verdict = 'cannot read the input file'
+					verdict = 'cannot read the input file%s' % strerror(sys.exc_info()[1].upstream)
 				except testcases.CannotReadAnswerFile:
-					e = sys.exc_info()[1]
-					if e.upstream.strerror:
-						verdict = 'cannot read the reference output file (%s)' % e.upstream.strerror.lower()
-					else:
-						verdict = 'cannot read the reference output file'
+					verdict = 'cannot read the reference output file%s' % strerror(sys.exc_info()[1].upstream)
 				except testcases.TestCaseNotPassed:
-					e = sys.exc_info()[1]
-					verdict = 'unspecified reason [this may be a bug in test.py] (%s)' % e
+					verdict = 'unspecified reason [this may be a bug in test.py]%s' % strerror(sys.exc_info()[1])
 				#except Exception:
-				#	e = sys.exc_info()[1]
-				#	verdict = 'unknown error [this may be a bug in test.py] (%s)' % e
+				#	verdict = 'unknown error [this may be a bug in test.py]%s' % strerror(sys.exc_info()[1])
 				else:
 					if hasattr(granted, '__iter__'):
 						granted, comment = granted
@@ -145,7 +124,7 @@
 						verdict = 'wrong answer' + comment
 					else:
 						verdict = 'partly correct' + comment
-				granted *= case.points
+					granted *= case.points
 				say('%g/%g, %s' % (granted, case.points, verdict))
 				real += granted
 			weighted = real * prob.config.taskweight / max if max else 0