Mercurial > ~astiob > upreckon > hgweb
diff 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 |
line wrap: on
line diff
--- a/2.00/test-svn.py Fri Aug 06 15:39:29 2010 +0000 +++ b/2.00/test-svn.py Wed Sep 22 22:01:56 2010 +0000 @@ -57,9 +57,15 @@ say('Downloaded and installed. Now you are using test.py ' + latesttext + '.') sys.exit() -import config, itertools, os, sys, time +import config, itertools, os, subprocess, sys, time if options.autotime: + # This is really a dirty hack that assumes that sleep() does not spend + # the CPU time of the current process and that if clock() measures + # wall-clock time, then it is more precise than time() is. Both these + # assumptions are true on all platforms I have tested this on so far, + # but I am not aware of any guarantee that they will both be true + # on every other platform. c = time.clock() time.sleep(1) c = time.clock() - c @@ -73,19 +79,25 @@ clock = time.time try: + from testcases import pause +except ImportError: + pause = None + +try: globalconf = config.load_global() # Do this check here so that if we have to warn them, we do it as early as possible - if options.pause and not hasattr(globalconf, 'pause'): - try: - # If we have getch, we don't need config.pause - import msvcrt - msvcrt.getch.__call__ - except Exception: + if options.pause and not pause and not hasattr(globalconf, 'pause'): + # testcases.pause will be sure to import msvcrt if it can + #try: + # # If we have getch, we don't need globalconf.pause + # import msvcrt + # msvcrt.getch.__call__ + #except Exception: if os.name == 'posix': globalconf.pause = 'read -s -n 1' - 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.') - sys.stdout.flush() + 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) + sys.stderr.flush() elif os.name == 'nt': globalconf.pause = 'pause' else: @@ -138,7 +150,7 @@ for taskname in globalconf.tasknames: problem = Problem(taskname) - if ntasks: say() + if ntasks and not options.copyonly: say() if shouldprintnames: say(taskname) if options.copyonly: @@ -147,7 +159,7 @@ real, max = problem.test() ntasks += 1 - nfulltasks += (real == max) + nfulltasks += real == max realscore += real maxscore += max @@ -164,8 +176,14 @@ say('Press any key to exit...') sys.stdout.flush() - try: - import msvcrt - msvcrt.getch() - except Exception: - os.system(globalconf.pause + ' >' + os.devnull) \ No newline at end of file + #try: + # import msvcrt + # msvcrt.getch() + #except Exception: + if pause: + pause() + elif callable(globalconf.pause): + globalconf.pause() + else: + with open(os.devnull, 'w') as devnull: + subprocess.call(globalconf.pause, stdout=devnull, stderr=subprocess.STDOUT) \ No newline at end of file