1- #!/usr/bin/python
1+ #!/usr/bin/env python3
22'''Usage: %s [OPTIONS] <input file(s)>
33Generate test source file for CxxTest.
44
@@ -57,7 +57,7 @@ def main():
5757def usage ( problem = None ):
5858 '''Print usage info and exit'''
5959 if problem is None :
60- print usageString ()
60+ print ( usageString () )
6161 sys .exit (0 )
6262 else :
6363 sys .stderr .write ( usageString () )
@@ -82,7 +82,7 @@ def parseCommandline():
8282 'error-printer' , 'abort-on-fail' , 'have-std' , 'no-std' ,
8383 'have-eh' , 'no-eh' , 'template=' , 'include=' ,
8484 'root' , 'part' , 'no-static-init' , 'factor' , 'longlong=' ] )
85- except getopt .error , problem :
85+ except getopt .error as problem :
8686 usage ( problem )
8787 setOptions ( options )
8888 return setFiles ( patterns )
@@ -147,7 +147,7 @@ def printVersion():
147147def setFiles ( patterns ):
148148 '''Set input files specified on command line'''
149149 files = expandWildcards ( patterns )
150- if len (files ) is 0 and not root :
150+ if len (files ) == 0 and not root :
151151 usage ( "No input files found" )
152152 return files
153153
@@ -169,7 +169,7 @@ def scanInputFiles(files):
169169 for file in files :
170170 scanInputFile (file )
171171 global suites
172- if len (suites ) is 0 and not root :
172+ if len (suites ) == 0 and not root :
173173 abort ( 'No tests defined' )
174174
175175def scanInputFile (fileName ):
@@ -288,7 +288,7 @@ def addLineToBlock( suite, lineNo, line ):
288288 '''Append the line to the current CXXTEST_CODE() block'''
289289 line = fixBlockLine ( suite , lineNo , line )
290290 line = re .sub ( r'^.*\{\{' , '' , line )
291-
291+
292292 e = re .search ( r'\}\}' , line )
293293 if e :
294294 line = line [:e .start ()]
@@ -315,30 +315,30 @@ def scanLineForDestroy( suite, lineNo, line ):
315315
316316def cstr ( str ):
317317 '''Convert a string to its C representation'''
318- return '"' + string .replace ( str , '\\ ' , '\\ \\ ' ) + '"'
318+ return '"' + str .replace ('\\ ' , '\\ \\ ' ) + '"'
319319
320320
321321def addSuiteCreateDestroy ( suite , which , line ):
322322 '''Add createSuite()/destroySuite() to current suite'''
323- if suite . has_key ( which ) :
323+ if which in suite :
324324 abort ( '%s:%s: %sSuite() already declared' % ( suite ['file' ], str (line ), which ) )
325325 suite [which ] = line
326326
327327def closeSuite ():
328328 '''Close current suite and add it to the list if valid'''
329329 global suite
330330 if suite is not None :
331- if len (suite ['tests' ]) is not 0 :
331+ if len (suite ['tests' ]) != 0 :
332332 verifySuite (suite )
333333 rememberSuite (suite )
334334 suite = None
335335
336336def verifySuite (suite ):
337337 '''Verify current suite is legal'''
338- if suite . has_key ( 'create' ) and not suite . has_key ( 'destroy' ) :
338+ if 'create' in suite and 'destroy' not in suite :
339339 abort ( '%s:%s: Suite %s has createSuite() but no destroySuite()' %
340340 (suite ['file' ], suite ['create' ], suite ['name' ]) )
341- if suite . has_key ( 'destroy' ) and not suite . has_key ( 'create' ) :
341+ if 'destroy' in suite and 'create' not in suite :
342342 abort ( '%s:%s: Suite %s has destroySuite() but no createSuite()' %
343343 (suite ['file' ], suite ['destroy' ], suite ['name' ]) )
344344
@@ -474,7 +474,7 @@ def isGenerated(suite):
474474
475475def isDynamic (suite ):
476476 '''Checks whether a suite is dynamic'''
477- return suite . has_key ( 'create' )
477+ return 'create' in suite
478478
479479lastIncluded = ''
480480def writeInclude (output , file ):
@@ -533,11 +533,11 @@ def runBody( suite, test ):
533533def dynamicRun ( suite , test ):
534534 '''Body of TestDescription::run() for test in a dynamic suite'''
535535 return 'if ( ' + suite ['object' ] + ' ) ' + suite ['object' ] + '->' + test ['name' ] + '();'
536-
536+
537537def staticRun ( suite , test ):
538538 '''Body of TestDescription::run() for test in a non-dynamic suite'''
539539 return suite ['object' ] + '.' + test ['name' ] + '();'
540-
540+
541541def writeSuiteDescription ( output , suite ):
542542 '''Write SuiteDescription object'''
543543 if isDynamic ( suite ):
0 commit comments