comparison 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
comparison
equal deleted inserted replaced
25:b500e117080e 26:5bbb68833868
30 signalnames[value] = name 30 signalnames[value] = name
31 del unixnames 31 del unixnames
32 32
33 __all__ = 'Problem', 33 __all__ = 'Problem',
34 34
35 # This should no more be needed; pass all work on to the TestCase inheritance tree 35 def strerror(e):
36 # LIBRARY and STDIO refer to interactive aka reactive problems 36 s = getattr(e, 'strerror')
37 #BATCH, OUTONLY, LIBRARY, STDIO, BESTOUT = xrange(5) 37 if not s: s = str(e)
38 return ' (%s%s)' % (s[0].lower(), s[1:]) if s else ''
38 39
39 class Cache(object): 40 class Cache(object):
40 def __init__(self, mydict): 41 def __init__(self, mydict):
41 self.__dict__ = mydict 42 self.__dict__ = mydict
42 43
93 else: 94 else:
94 verdict = 'terminated by signal %d' % -e.exitcode 95 verdict = 'terminated by signal %d' % -e.exitcode
95 else: 96 else:
96 verdict = 'non-zero return code %d' % e.exitcode 97 verdict = 'non-zero return code %d' % e.exitcode
97 except testcases.CannotStartTestee: 98 except testcases.CannotStartTestee:
98 e = sys.exc_info()[1] 99 verdict = 'cannot launch the program to test%s' % strerror(sys.exc_info()[1].upstream)
99 if e.upstream.strerror:
100 verdict = 'cannot launch the program to test (%s)' % e.upstream.strerror.lower()
101 else:
102 verdict = 'cannot launch the program to test'
103 except testcases.CannotStartValidator: 100 except testcases.CannotStartValidator:
104 e = sys.exc_info()[1] 101 verdict = 'cannot launch the validator%s' % strerror(sys.exc_info()[1].upstream)
105 if e.upstream.strerror:
106 verdict = 'cannot launch the validator (%s)' % e.upstream.strerror.lower()
107 else:
108 verdict = 'cannot launch the validator'
109 except testcases.CannotReadOutputFile: 102 except testcases.CannotReadOutputFile:
110 e = sys.exc_info()[1] 103 verdict = 'cannot read the output file%s' % strerror(sys.exc_info()[1].upstream)
111 if e.upstream.strerror:
112 verdict = 'cannot read the output file (%s)' % e.upstream.strerror.lower()
113 else:
114 verdict = 'cannot read the output file'
115 except testcases.CannotReadInputFile: 104 except testcases.CannotReadInputFile:
116 e = sys.exc_info()[1] 105 verdict = 'cannot read the input file%s' % strerror(sys.exc_info()[1].upstream)
117 if e.upstream.strerror:
118 verdict = 'cannot read the input file (%s)' % e.upstream.strerror.lower()
119 else:
120 verdict = 'cannot read the input file'
121 except testcases.CannotReadAnswerFile: 106 except testcases.CannotReadAnswerFile:
122 e = sys.exc_info()[1] 107 verdict = 'cannot read the reference output file%s' % strerror(sys.exc_info()[1].upstream)
123 if e.upstream.strerror:
124 verdict = 'cannot read the reference output file (%s)' % e.upstream.strerror.lower()
125 else:
126 verdict = 'cannot read the reference output file'
127 except testcases.TestCaseNotPassed: 108 except testcases.TestCaseNotPassed:
128 e = sys.exc_info()[1] 109 verdict = 'unspecified reason [this may be a bug in test.py]%s' % strerror(sys.exc_info()[1])
129 verdict = 'unspecified reason [this may be a bug in test.py] (%s)' % e
130 #except Exception: 110 #except Exception:
131 # e = sys.exc_info()[1] 111 # verdict = 'unknown error [this may be a bug in test.py]%s' % strerror(sys.exc_info()[1])
132 # verdict = 'unknown error [this may be a bug in test.py] (%s)' % e
133 else: 112 else:
134 if hasattr(granted, '__iter__'): 113 if hasattr(granted, '__iter__'):
135 granted, comment = granted 114 granted, comment = granted
136 if comment: 115 if comment:
137 comment = ' (%s)' % comment 116 comment = ' (%s)' % comment
143 verdict = 'OK' + comment 122 verdict = 'OK' + comment
144 elif not granted: 123 elif not granted:
145 verdict = 'wrong answer' + comment 124 verdict = 'wrong answer' + comment
146 else: 125 else:
147 verdict = 'partly correct' + comment 126 verdict = 'partly correct' + comment
148 granted *= case.points 127 granted *= case.points
149 say('%g/%g, %s' % (granted, case.points, verdict)) 128 say('%g/%g, %s' % (granted, case.points, verdict))
150 real += granted 129 real += granted
151 weighted = real * prob.config.taskweight / max if max else 0 130 weighted = real * prob.config.taskweight / max if max else 0
152 if nvalued != ntotal: 131 if nvalued != ntotal:
153 say('Problem total: %d/%d tests (%d/%d valued); %g/%g points; weighted score: %g/%g' % (ncorrect, ntotal, ncorrectvalued, nvalued, real, max, weighted, prob.config.taskweight)) 132 say('Problem total: %d/%d tests (%d/%d valued); %g/%g points; weighted score: %g/%g' % (ncorrect, ntotal, ncorrectvalued, nvalued, real, max, weighted, prob.config.taskweight))