3030
3131def main ():
3232 try :
33- opts , args = getopt .getopt (sys .argv [1 :], 'vgqx' )
33+ opts , args = getopt .getopt (sys .argv [1 :], 'vgqx' )
3434 except getopt .error , msg :
35- print msg
36- print __doc__
37- return 2
35+ print msg
36+ print __doc__
37+ return 2
3838 verbose = 0
3939 quiet = 0
4040 generate = 0
4141 exclude = 0
4242 for o , a in opts :
43- if o == '-v' : verbose = verbose + 1
44- if o == '-q' : quiet = 1 ; verbose = 0
45- if o == '-g' : generate = 1
46- if o == '-x' : exclude = 1
43+ if o == '-v' : verbose = verbose + 1
44+ if o == '-q' : quiet = 1 ; verbose = 0
45+ if o == '-g' : generate = 1
46+ if o == '-x' : exclude = 1
4747 if generate and verbose :
48- print "-g and -v don't go together!"
49- return 2
48+ print "-g and -v don't go together!"
49+ return 2
5050 good = []
5151 bad = []
5252 skipped = []
5353 for i in range (len (args )):
54- # Strip trailing ".py" from arguments
55- if args [i ][- 3 :] == '.py' :
56- args [i ] = args [i ][:- 3 ]
54+ # Strip trailing ".py" from arguments
55+ if args [i ][- 3 :] == '.py' :
56+ args [i ] = args [i ][:- 3 ]
5757 if exclude :
58- nottests [:0 ] = args
59- args = []
58+ nottests [:0 ] = args
59+ args = []
6060 tests = args or findtests ()
61- test_support .verbose = verbose # Tell tests to be moderately quiet
61+ test_support .verbose = verbose # Tell tests to be moderately quiet
6262 for test in tests :
63- if not quiet :
64- print test
65- ok = runtest (test , generate , verbose )
66- if ok > 0 :
67- good .append (test )
68- elif ok == 0 :
69- bad .append (test )
70- else :
71- if not quiet :
72- print "test" , test ,
73- print "skipped -- an optional feature could not be imported"
74- skipped .append (test )
63+ if not quiet :
64+ print test
65+ ok = runtest (test , generate , verbose )
66+ if ok > 0 :
67+ good .append (test )
68+ elif ok == 0 :
69+ bad .append (test )
70+ else :
71+ if not quiet :
72+ print "test" , test ,
73+ print "skipped -- an optional feature could not be imported"
74+ skipped .append (test )
7575 if good and not quiet :
76- if not bad and not skipped and len (good ) > 1 :
77- print "All" ,
78- print count (len (good ), "test" ), "OK."
76+ if not bad and not skipped and len (good ) > 1 :
77+ print "All" ,
78+ print count (len (good ), "test" ), "OK."
7979 if bad :
80- print count (len (bad ), "test" ), "failed:" ,
81- print string .join (bad )
80+ print count (len (bad ), "test" ), "failed:" ,
81+ print string .join (bad )
8282 if skipped and not quiet :
83- print count (len (skipped ), "test" ), "skipped:" ,
84- print string .join (skipped )
83+ print count (len (skipped ), "test" ), "skipped:" ,
84+ print string .join (skipped )
8585 return len (bad ) > 0
8686
8787stdtests = [
@@ -105,10 +105,10 @@ def findtests():
105105 names = os .listdir (testdir )
106106 tests = []
107107 for name in names :
108- if name [:5 ] == "test_" and name [- 3 :] == ".py" :
109- modname = name [:- 3 ]
110- if modname not in stdtests and modname not in nottests :
111- tests .append (modname )
108+ if name [:5 ] == "test_" and name [- 3 :] == ".py" :
109+ modname = name [:- 3 ]
110+ if modname not in stdtests and modname not in nottests :
111+ tests .append (modname )
112112 tests .sort ()
113113 return stdtests + tests
114114
@@ -118,76 +118,76 @@ def runtest(test, generate, verbose):
118118 outputdir = os .path .join (testdir , "output" )
119119 outputfile = os .path .join (outputdir , test )
120120 try :
121- if generate :
122- cfp = open (outputfile , "w" )
123- elif verbose :
124- cfp = sys .stdout
125- else :
126- cfp = Compare (outputfile )
121+ if generate :
122+ cfp = open (outputfile , "w" )
123+ elif verbose :
124+ cfp = sys .stdout
125+ else :
126+ cfp = Compare (outputfile )
127127 except IOError :
128- cfp = None
129- print "Warning: can't open" , outputfile
128+ cfp = None
129+ print "Warning: can't open" , outputfile
130130 try :
131- save_stdout = sys .stdout
132- try :
133- if cfp :
134- sys .stdout = cfp
135- print test # Output file starts with test name
136- __import__ (test , globals (), locals (), [])
137- finally :
138- sys .stdout = save_stdout
131+ save_stdout = sys .stdout
132+ try :
133+ if cfp :
134+ sys .stdout = cfp
135+ print test # Output file starts with test name
136+ __import__ (test , globals (), locals (), [])
137+ finally :
138+ sys .stdout = save_stdout
139139 except ImportError , msg :
140- return - 1
140+ return - 1
141141 except KeyboardInterrupt , v :
142- raise KeyboardInterrupt , v , sys .exc_info ()[2 ]
142+ raise KeyboardInterrupt , v , sys .exc_info ()[2 ]
143143 except test_support .TestFailed , msg :
144- print "test" , test , "failed --" , msg
145- return 0
144+ print "test" , test , "failed --" , msg
145+ return 0
146146 except :
147- type , value = sys .exc_info ()[:2 ]
148- print "test" , test , "crashed --" , type , ":" , value
149- if verbose :
150- traceback .print_exc (file = sys .stdout )
151- return 0
147+ type , value = sys .exc_info ()[:2 ]
148+ print "test" , test , "crashed --" , type , ":" , value
149+ if verbose :
150+ traceback .print_exc (file = sys .stdout )
151+ return 0
152152 else :
153- return 1
153+ return 1
154154
155155def findtestdir ():
156156 if __name__ == '__main__' :
157- file = sys .argv [0 ]
157+ file = sys .argv [0 ]
158158 else :
159- file = __file__
159+ file = __file__
160160 testdir = os .path .dirname (file ) or os .curdir
161161 return testdir
162162
163163def count (n , word ):
164164 if n == 1 :
165- return "%d %s" % (n , word )
165+ return "%d %s" % (n , word )
166166 else :
167- return "%d %ss" % (n , word )
167+ return "%d %ss" % (n , word )
168168
169169class Compare :
170170
171171 def __init__ (self , filename ):
172- self .fp = open (filename , 'r' )
172+ self .fp = open (filename , 'r' )
173173
174174 def write (self , data ):
175- expected = self .fp .read (len (data ))
176- if data <> expected :
177- raise test_support .TestFailed , \
178- 'Writing: ' + `data` + ', expected: ' + `expected`
175+ expected = self .fp .read (len (data ))
176+ if data <> expected :
177+ raise test_support .TestFailed , \
178+ 'Writing: ' + `data` + ', expected: ' + `expected`
179179
180180 def flush (self ):
181- pass
181+ pass
182182
183183 def close (self ):
184- leftover = self .fp .read ()
185- if leftover :
186- raise test_support .TestFailed , 'Unread: ' + `leftover`
187- self .fp .close ()
184+ leftover = self .fp .read ()
185+ if leftover :
186+ raise test_support .TestFailed , 'Unread: ' + `leftover`
187+ self .fp .close ()
188188
189189 def isatty (self ):
190- return 0
190+ return 0
191191
192192if __name__ == '__main__' :
193193 sys .exit (main ())
0 commit comments