comparison 2.00/testcases.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 b500e117080e
children dc4be35d17e0
comparison
equal deleted inserted replaced
25:b500e117080e 26:5bbb68833868
290 if not case.problem.config.tester: 290 if not case.problem.config.tester:
291 case.validator = None 291 case.validator = None
292 else: 292 else:
293 case.validator = case.problem.config.tester 293 case.validator = case.problem.config.tester
294 294
295 # TODO
296 def validate(case, output): 295 def validate(case, output):
297 if not case.validator: 296 if not case.validator:
298 # Compare the output with the reference output 297 # Compare the output with the reference output
299 case.open_outfile() 298 case.open_outfile()
300 with case.outfile.open() as refoutput: 299 with case.outfile.open() as refoutput:
315 try: 314 try:
316 case.process = Popen(case.validator, stdin=devnull, stdout=PIPE, stderr=STDOUT, universal_newlines=True, bufsize=-1) 315 case.process = Popen(case.validator, stdin=devnull, stdout=PIPE, stderr=STDOUT, universal_newlines=True, bufsize=-1)
317 except OSError: 316 except OSError:
318 raise CannotStartValidator(sys.exc_info()[1]) 317 raise CannotStartValidator(sys.exc_info()[1])
319 comment = case.process.communicate()[0].strip() 318 comment = case.process.communicate()[0].strip()
320 match = re.match(r'(?i)(ok|correct|wrong(?:(?:\s|_)*answer)?)(?:$|\s+|[.,!:]+\s*)', comment) 319 match = re.match(r'(?i)(ok|(?:correct|wrong)(?:(?:\s|_)*answer)?)(?:$|\s+|[.,!:]+\s*)', comment)
321 if match: 320 if match:
322 comment = comment[match.end():] 321 comment = comment[match.end():]
323 if not case.problem.config.maxexitcode: 322 if not case.problem.config.maxexitcode:
324 if case.process.returncode: 323 if case.process.returncode:
325 raise WrongAnswer(comment) 324 raise WrongAnswer(comment)
372 try: 371 try:
373 case.process = Popen(case.problem.config.path, stdin=infile, stdout=outfile, stderr=devnull, universal_newlines=True, bufsize=-1, preexec_fn=preexec_fn) 372 case.process = Popen(case.problem.config.path, stdin=infile, stdout=outfile, stderr=devnull, universal_newlines=True, bufsize=-1, preexec_fn=preexec_fn)
374 except MemoryError: 373 except MemoryError:
375 # If there is not enough memory for the forked test.py, 374 # If there is not enough memory for the forked test.py,
376 # opt for silent dropping of the limit 375 # opt for silent dropping of the limit
376 # TODO: show a warning somewhere
377 case.process = Popen(case.problem.config.path, stdin=infile, stdout=outfile, stderr=devnull, universal_newlines=True, bufsize=-1) 377 case.process = Popen(case.problem.config.path, stdin=infile, stdout=outfile, stderr=devnull, universal_newlines=True, bufsize=-1)
378 except OSError: 378 except OSError:
379 raise CannotStartTestee(sys.exc_info()[1]) 379 raise CannotStartTestee(sys.exc_info()[1])
380 case.time_started = clock() 380 case.time_started = clock()
381 time_next_check = case.time_started + .15 381 time_next_check = case.time_started + .15
422 try: 422 try:
423 case.process = Popen(case.problem.config.path, stdin=devnull, stdout=devnull, stderr=STDOUT, preexec_fn=preexec_fn) 423 case.process = Popen(case.problem.config.path, stdin=devnull, stdout=devnull, stderr=STDOUT, preexec_fn=preexec_fn)
424 except MemoryError: 424 except MemoryError:
425 # If there is not enough memory for the forked test.py, 425 # If there is not enough memory for the forked test.py,
426 # opt for silent dropping of the limit 426 # opt for silent dropping of the limit
427 # TODO: show a warning somewhere
427 case.process = Popen(case.problem.config.path, stdin=devnull, stdout=devnull, stderr=STDOUT) 428 case.process = Popen(case.problem.config.path, stdin=devnull, stdout=devnull, stderr=STDOUT)
428 except OSError: 429 except OSError:
429 raise CannotStartTestee(sys.exc_info()[1]) 430 raise CannotStartTestee(sys.exc_info()[1])
430 case.time_started = clock() 431 case.time_started = clock()
431 time_next_check = case.time_started + .15 432 time_next_check = case.time_started + .15
478 class ReactiveTestCase(TestCase): 479 class ReactiveTestCase(TestCase):
479 __slots__ = () 480 __slots__ = ()
480 # The basic idea is to launch the program to be tested and the grader 481 # The basic idea is to launch the program to be tested and the grader
481 # and to pipe their standard I/O from and to each other, 482 # and to pipe their standard I/O from and to each other,
482 # and then to capture the grader's exit code and use it 483 # and then to capture the grader's exit code and use it
483 # like the exit code of a test validator is used. 484 # like the exit code of an output validator is used.
484 485
485 486
486 def load_problem(prob, _types={'batch' : BatchTestCase, 487 def load_problem(prob, _types={'batch' : BatchTestCase,
487 'outonly' : OutputOnlyTestCase, 488 'outonly' : OutputOnlyTestCase,
488 'bestout' : BestOutputTestCase, 489 'bestout' : BestOutputTestCase,