diff 2.00/test-svn.py @ 25:b500e117080e

Bug fixes and overhead reduction Added the --problem/-p option. (WARNING: not the same as the -p option of test.py 1.x.) The problem names supplied are not validated. Added zip_longest to compat.py. Experimental: problem names are now _always_ printed for multi-problem sets. Overhead: Escape presses are now checked only once every .15 seconds (at least kbhit() on Windows is very slow). Overhead: sleep(0) is now called in the time-control-and-Escape-watching loop (at least on Windows, it immediately transfers control to some waiting thread). Bug fix: compat.py now overwrites built-ins only while including testconfs (--help was broken in Python 2). Bug fix: ReadDeleting in config.py now closes the file it opens (especially important on Windows, where open files cannot be deleted). Bug fix: added callable to compat.py (it is absent from Python 3). Bug fix: the default (built-in) output validator now properly handles unwanted trailing data. Bug fix: testconfs in custom archives no more raise NameError. Bug fix: if a validator program cannot be launched, CannotStartValidator is now raised instead of the fatal OSError.
author Oleg Oshmyan <chortos@inbox.lv>
date Thu, 23 Sep 2010 23:05:58 +0000
parents c1f52b5d80d6
children 5bbb68833868
line wrap: on
line diff
--- a/2.00/test-svn.py	Thu Sep 23 00:11:24 2010 +0000
+++ b/2.00/test-svn.py	Thu Sep 23 23:05:58 2010 +0000
@@ -15,6 +15,7 @@
 parser = optparse.OptionParser(version='test.py '+version, epilog='Python 2.5 or newer is required, unless you have a custom build of Python.')
 parser.add_option('-1', dest='legacy', action='store_true', default=False, help='handle configuration files in a way more compatible with test.py 1.x')
 parser.add_option('-u', '--update', dest='update', action='store_true', default=False, help='check for an updated version of test.py')
+parser.add_option('-p', '--problem', dest='problems', metavar='PROBLEM', action='append', help='test only the PROBLEM (this option can be specified more than once with different problem names, all of which will be tested)')
 parser.add_option('-m', '--copy-io', dest='copyonly', action='store_true', default=False, help='create a copy of the input/output files of the last test case for manual testing and exit')
 parser.add_option('-x', '--auto-exit', dest='pause', action='store_false', default=True, help='do not wait for a key to be pressed after finishing testing')
 parser.add_option('-s', '--save-io', dest='erase', action='store_false', default=True, help='do not delete the copies of input/output files after the last test case; create copies of input files and store output in files even if the solution uses standard I/O; delete the stored input/output files if the solution uses standard I/O and the -c/--cleanup option is specified')
@@ -89,20 +90,14 @@
 
 	# Do this check here so that if we have to warn them, we do it as early as possible
 	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.', file=sys.stderr)
-				sys.stderr.flush()
-			elif os.name == 'nt':
-				globalconf.pause = 'pause'
-			else:
-				sys.exit('Error: configuration variable pause is not defined and cannot be devised automatically.')
+		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.', file=sys.stderr)
+			sys.stderr.flush()
+		elif os.name == 'nt':
+			globalconf.pause = 'pause'
+		else:
+			sys.exit('Error: configuration variable pause is not defined and cannot be devised automatically.')
 
 	try:
 		from problem import *
@@ -116,39 +111,41 @@
 		globalconf.tasknames = os.path.curdir,
 	else:
 		globalconf.multiproblem = True
-		try:
-			shouldprintnames = len(globalconf.tasknames) > 1
-		except Exception:
-			# Try to retrieve the first two problem names and cache them on success
-			globalconf.tasknames = iter(globalconf.tasknames)
-			try:
-				try:
-					first = next(globalconf.tasknames)
-				except NameError:
-					# Python 2.5 lacks the next() built-in
-					first = globalconf.tasknames.next()
-			except StopIteration:
-				globalconf.tasknames = ()
-				shouldprintnames = False
-			else:
-				try:
-					try:
-						second = next(globalconf.tasknames)
-					except NameError:
-						second = globalconf.tasknames.next()
-				except StopIteration:
-					globalconf.tasknames = first,
-					shouldprintnames = False
-				else:
-					globalconf.tasknames = itertools.chain((first, second), globalconf.tasknames)
-					shouldprintnames = True
+		# TODO: erase the commented part? if it has a tasknames variable, it is by definition multi-problem
+		shouldprintnames = True
+		# try:
+		# 	shouldprintnames = len(globalconf.tasknames) > 1
+		# except Exception:
+		# 	# Try to retrieve the first two problem names and cache them on success
+		# 	globalconf.tasknames = iter(globalconf.tasknames)
+		# 	try:
+		# 		try:
+		# 			first = next(globalconf.tasknames)
+		# 		except NameError:
+		# 			# Python 2.5 lacks the next() built-in
+		# 			first = globalconf.tasknames.next()
+		# 	except StopIteration:
+		# 		globalconf.tasknames = ()
+		# 		shouldprintnames = False
+		# 	else:
+		# 		try:
+		# 			try:
+		# 				second = next(globalconf.tasknames)
+		# 			except NameError:
+		# 				second = globalconf.tasknames.next()
+		# 		except StopIteration:
+		# 			globalconf.tasknames = first,
+		# 			shouldprintnames = False
+		# 		else:
+		# 			globalconf.tasknames = itertools.chain((first, second), globalconf.tasknames)
+		# 			shouldprintnames = True
 
 	ntasks = 0
 	nfulltasks = 0
 	maxscore = 0
 	realscore = 0
 
-	for taskname in globalconf.tasknames:
+	for taskname in (globalconf.tasknames if not options.problems else options.problems):
 		problem = Problem(taskname)
 		
 		if ntasks and not options.copyonly: say()
@@ -177,10 +174,6 @@
 	say('Press any key to exit...')
 	sys.stdout.flush()
 	
-	#try:
-	#	import msvcrt
-	#	msvcrt.getch()
-	#except Exception:
 	if pause:
 		pause()
 	elif callable(globalconf.pause):