comparison testcases.py @ 136:ed4035661b85

Added a C implementation of the unix module (called _unix)
author Oleg Oshmyan <chortos@inbox.lv>
date Tue, 24 May 2011 20:51:01 +0100
parents e84f33a60a5c
children
comparison
equal deleted inserted replaced
135:523ba6907f3a 136:ed4035661b85
32 class DummySignalIgnorer(object): 32 class DummySignalIgnorer(object):
33 def __enter__(self): pass 33 def __enter__(self): pass
34 def __exit__(self, exc_type, exc_value, traceback): pass 34 def __exit__(self, exc_type, exc_value, traceback): pass
35 signal_ignorer = DummySignalIgnorer() 35 signal_ignorer = DummySignalIgnorer()
36 36
37 try: 37 # win32 and unix are imported a bit later
38 from win32 import *
39 except Exception:
40 from unix import *
41 38
42 __all__ = ('TestCase', 'load_problem', 'TestCaseNotPassed', 39 __all__ = ('TestCase', 'load_problem', 'TestCaseNotPassed',
43 'TimeLimitExceeded', 'CanceledByUser', 'WrongAnswer', 40 'TimeLimitExceeded', 'CanceledByUser', 'WrongAnswer',
44 'NonZeroExitCode', 'CannotStartTestee', 41 'NonZeroExitCode', 'CannotStartTestee',
45 'CannotStartValidator', 'CannotReadOutputFile', 42 'CannotStartValidator', 'CannotReadOutputFile',
77 class CannotStartTestee(ExceptionWrapper): __slots__ = () 74 class CannotStartTestee(ExceptionWrapper): __slots__ = ()
78 class CannotStartValidator(ExceptionWrapper): __slots__ = () 75 class CannotStartValidator(ExceptionWrapper): __slots__ = ()
79 class CannotReadOutputFile(ExceptionWrapper): __slots__ = () 76 class CannotReadOutputFile(ExceptionWrapper): __slots__ = ()
80 class CannotReadInputFile(ExceptionWrapper): __slots__ = () 77 class CannotReadInputFile(ExceptionWrapper): __slots__ = ()
81 class CannotReadAnswerFile(ExceptionWrapper): __slots__ = () 78 class CannotReadAnswerFile(ExceptionWrapper): __slots__ = ()
79
80 # Import platform-specific code now that exception classes are defined
81 try:
82 from win32 import *
83 except Exception:
84 from unix import *
82 85
83 86
84 87
85 # Helper context managers 88 # Helper context managers
86 89
183 if not case.has_called_back: 186 if not case.has_called_back:
184 callback() 187 callback()
185 case.cleanup() 188 case.cleanup()
186 189
187 def cleanup(case): 190 def cleanup(case):
191 # Note that native extensions clean up on their own
192 # and never let this condition be satisfied
188 if getattr(case, 'process', None) and case.process.returncode is None: 193 if getattr(case, 'process', None) and case.process.returncode is None:
189 kill(case.process) 194 kill(case.process)
190 for name in case.files_to_delete: 195 for name in case.files_to_delete:
191 try: 196 try:
192 os.remove(name) 197 os.remove(name)