comparison 2.00/test-svn.py @ 22:f07b7a431ea6

Further 2.00 work Testconfs in all supported kinds of archives should now work. Test runs are now cancelled by pressing Escape rather than Ctrl+C. Improved time control. Greatly improved temporary and helper file cleanup. The pause configuration variable can now be a callable and is now processed using subprocess rather than system().
author Oleg Oshmyan <chortos@inbox.lv>
date Wed, 22 Sep 2010 22:01:56 +0000
parents ec6f1a132109
children c1f52b5d80d6
comparison
equal deleted inserted replaced
21:ec6f1a132109 22:f07b7a431ea6
55 sys.stdout.flush() 55 sys.stdout.flush()
56 urllib.urlretrieve('http://chortos.selfip.net/~astiob/test.py/test.py', sys.argv[0]) 56 urllib.urlretrieve('http://chortos.selfip.net/~astiob/test.py/test.py', sys.argv[0])
57 say('Downloaded and installed. Now you are using test.py ' + latesttext + '.') 57 say('Downloaded and installed. Now you are using test.py ' + latesttext + '.')
58 sys.exit() 58 sys.exit()
59 59
60 import config, itertools, os, sys, time 60 import config, itertools, os, subprocess, sys, time
61 61
62 if options.autotime: 62 if options.autotime:
63 # This is really a dirty hack that assumes that sleep() does not spend
64 # the CPU time of the current process and that if clock() measures
65 # wall-clock time, then it is more precise than time() is. Both these
66 # assumptions are true on all platforms I have tested this on so far,
67 # but I am not aware of any guarantee that they will both be true
68 # on every other platform.
63 c = time.clock() 69 c = time.clock()
64 time.sleep(1) 70 time.sleep(1)
65 c = time.clock() - c 71 c = time.clock() - c
66 if int(c + .5) == 1: 72 if int(c + .5) == 1:
67 clock = time.clock 73 clock = time.clock
71 clock = time.clock 77 clock = time.clock
72 else: 78 else:
73 clock = time.time 79 clock = time.time
74 80
75 try: 81 try:
82 from testcases import pause
83 except ImportError:
84 pause = None
85
86 try:
76 globalconf = config.load_global() 87 globalconf = config.load_global()
77 88
78 # Do this check here so that if we have to warn them, we do it as early as possible 89 # Do this check here so that if we have to warn them, we do it as early as possible
79 if options.pause and not hasattr(globalconf, 'pause'): 90 if options.pause and not pause and not hasattr(globalconf, 'pause'):
80 try: 91 # testcases.pause will be sure to import msvcrt if it can
81 # If we have getch, we don't need config.pause 92 #try:
82 import msvcrt 93 # # If we have getch, we don't need globalconf.pause
83 msvcrt.getch.__call__ 94 # import msvcrt
84 except Exception: 95 # msvcrt.getch.__call__
96 #except Exception:
85 if os.name == 'posix': 97 if os.name == 'posix':
86 globalconf.pause = 'read -s -n 1' 98 globalconf.pause = 'read -s -n 1'
87 say('Warning: configuration variable pause is not defined; it was devised automatically but the choice might be incorrect, so test.py might exit immediately after the testing is completed.') 99 say('Warning: configuration variable pause is not defined; it was devised automatically but the choice might be incorrect, so test.py might exit immediately after the testing is completed.', file=sys.stderr)
88 sys.stdout.flush() 100 sys.stderr.flush()
89 elif os.name == 'nt': 101 elif os.name == 'nt':
90 globalconf.pause = 'pause' 102 globalconf.pause = 'pause'
91 else: 103 else:
92 sys.exit('Error: configuration variable pause is not defined and cannot be devised automatically.') 104 sys.exit('Error: configuration variable pause is not defined and cannot be devised automatically.')
93 105
136 realscore = 0 148 realscore = 0
137 149
138 for taskname in globalconf.tasknames: 150 for taskname in globalconf.tasknames:
139 problem = Problem(taskname) 151 problem = Problem(taskname)
140 152
141 if ntasks: say() 153 if ntasks and not options.copyonly: say()
142 if shouldprintnames: say(taskname) 154 if shouldprintnames: say(taskname)
143 155
144 if options.copyonly: 156 if options.copyonly:
145 problem.copytestdata() 157 problem.copytestdata()
146 else: 158 else:
147 real, max = problem.test() 159 real, max = problem.test()
148 160
149 ntasks += 1 161 ntasks += 1
150 nfulltasks += (real == max) 162 nfulltasks += real == max
151 realscore += real 163 realscore += real
152 maxscore += max 164 maxscore += max
153 165
154 if options.copyonly: 166 if options.copyonly:
155 sys.exit() 167 sys.exit()
162 174
163 if options.pause: 175 if options.pause:
164 say('Press any key to exit...') 176 say('Press any key to exit...')
165 sys.stdout.flush() 177 sys.stdout.flush()
166 178
167 try: 179 #try:
168 import msvcrt 180 # import msvcrt
169 msvcrt.getch() 181 # msvcrt.getch()
170 except Exception: 182 #except Exception:
171 os.system(globalconf.pause + ' >' + os.devnull) 183 if pause:
184 pause()
185 elif callable(globalconf.pause):
186 globalconf.pause()
187 else:
188 with open(os.devnull, 'w') as devnull:
189 subprocess.call(globalconf.pause, stdout=devnull, stderr=subprocess.STDOUT)