[Python-checkins] python/dist/src/Lib/test regrtest.py,1.151,1.152

bwarsaw at users.sourceforge.net bwarsaw at users.sourceforge.net
Sat Feb 7 17:43:06 EST 2004


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26424

Modified Files:
	regrtest.py 
Log Message:
Patch #868499, adds -T option for code coverage.  The implementation is a
fairly simpleminded adaptation of Zope3's test.py -T flag.

I also changed some booleans to use True/False where appropriate.


Index: regrtest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/regrtest.py,v
retrieving revision 1.151
retrieving revision 1.152
diff -C2 -d -r1.151 -r1.152
*** regrtest.py	17 Jan 2004 14:29:28 -0000	1.151
--- regrtest.py	7 Feb 2004 22:43:03 -0000	1.152
***************
*** 20,23 ****
--- 20,24 ----
  -h: help      -- print this text and exit
  -t: threshold -- call gc.set_threshold(N)
+ -T: coverage  -- turn on code coverage using the trace module
  
  If non-option arguments are present, they are names for tests to run,
***************
*** 27,30 ****
--- 28,33 ----
  -v is incompatible with -g and does not compare test output files.
  
+ -T turns on code coverage tracing with the trace module.
+ 
  -s means to run only a single test and exit.  This is useful when
  doing memory analysis on the Python interpreter (which tend to consume
***************
*** 69,79 ****
  """
  
- import sys
  import os
  import getopt
- import traceback
  import random
- import cStringIO
  import warnings
  
  # I see no other way to suppress these warnings;
--- 72,82 ----
  """
  
  import os
+ import sys
  import getopt
  import random
  import warnings
+ import cStringIO
+ import traceback
  
  # I see no other way to suppress these warnings;
***************
*** 114,120 ****
  
  
! def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
!          exclude=0, single=0, randomize=0, fromfile=None, findleaks=0,
!          use_resources=None):
      """Execute a test suite.
  
--- 117,123 ----
  
  
! def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
!          exclude=False, single=False, randomize=False, fromfile=None,
!          findleaks=False, use_resources=None, trace=False):
      """Execute a test suite.
  
***************
*** 133,149 ****
      files beginning with test_ will be used.
  
!     The other default arguments (verbose, quiet, generate, exclude,
!     single, randomize, findleaks, and use_resources) allow programmers
!     calling main() directly to set the values that would normally be
!     set by flags on the command line.
! 
      """
  
      test_support.record_original_stdout(sys.stdout)
      try:
!         opts, args = getopt.getopt(sys.argv[1:], 'hvgqxsrf:lu:t:',
                                     ['help', 'verbose', 'quiet', 'generate',
                                      'exclude', 'single', 'random', 'fromfile',
!                                     'findleaks', 'use=', 'threshold='])
      except getopt.error, msg:
          usage(2, msg)
--- 136,152 ----
      files beginning with test_ will be used.
  
!     The other default arguments (verbose, quiet, generate, exclude, single,
!     randomize, findleaks, use_resources, and trace) allow programmers calling
!     main() directly to set the values that would normally be set by flags on
!     the command line.
      """
  
      test_support.record_original_stdout(sys.stdout)
      try:
!         opts, args = getopt.getopt(sys.argv[1:], 'hvgqxsrf:lu:t:T',
                                     ['help', 'verbose', 'quiet', 'generate',
                                      'exclude', 'single', 'random', 'fromfile',
!                                     'findleaks', 'use=', 'threshold=', 'trace',
!                                     ])
      except getopt.error, msg:
          usage(2, msg)
***************
*** 158,178 ****
              verbose += 1
          elif o in ('-q', '--quiet'):
!             quiet = 1;
              verbose = 0
          elif o in ('-g', '--generate'):
!             generate = 1
          elif o in ('-x', '--exclude'):
!             exclude = 1
          elif o in ('-s', '--single'):
!             single = 1
          elif o in ('-r', '--randomize'):
!             randomize = 1
          elif o in ('-f', '--fromfile'):
              fromfile = a
          elif o in ('-l', '--findleaks'):
!             findleaks = 1
          elif o in ('-t', '--threshold'):
              import gc
              gc.set_threshold(int(a))
          elif o in ('-u', '--use'):
              u = [x.lower() for x in a.split(',')]
--- 161,183 ----
              verbose += 1
          elif o in ('-q', '--quiet'):
!             quiet = True;
              verbose = 0
          elif o in ('-g', '--generate'):
!             generate = True
          elif o in ('-x', '--exclude'):
!             exclude = True
          elif o in ('-s', '--single'):
!             single = True
          elif o in ('-r', '--randomize'):
!             randomize = True
          elif o in ('-f', '--fromfile'):
              fromfile = a
          elif o in ('-l', '--findleaks'):
!             findleaks = True
          elif o in ('-t', '--threshold'):
              import gc
              gc.set_threshold(int(a))
+         elif o in ('-T', '--coverage'):
+             trace = True
          elif o in ('-u', '--use'):
              u = [x.lower() for x in a.split(',')]
***************
*** 207,211 ****
          except ImportError:
              print 'No GC available, disabling findleaks.'
!             findleaks = 0
          else:
              # Uncomment the line below to report garbage that is not
--- 212,216 ----
          except ImportError:
              print 'No GC available, disabling findleaks.'
!             findleaks = False
          else:
              # Uncomment the line below to report garbage that is not
***************
*** 254,257 ****
--- 259,267 ----
      if randomize:
          random.shuffle(tests)
+     if trace:
+         import trace
+         tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix],
+                              trace=False, count=True)
+         coverdir = os.path.join(os.getcwd(), 'coverage')
      test_support.verbose = verbose      # Tell tests to be moderately quiet
      test_support.use_resources = use_resources
***************
*** 261,273 ****
              print test
              sys.stdout.flush()
!         ok = runtest(test, generate, verbose, quiet, testdir)
!         if ok > 0:
!             good.append(test)
!         elif ok == 0:
!             bad.append(test)
          else:
!             skipped.append(test)
!             if ok == -2:
!                 resource_denieds.append(test)
          if findleaks:
              gc.collect()
--- 271,289 ----
              print test
              sys.stdout.flush()
!         if trace:
!             # If we're tracing code coverage, then we don't exit with status
!             # if on a false return value from main.
!             tracer.runctx('runtest(test, generate, verbose, quiet, testdir)',
!                           globals=globals(), locals=vars())
          else:
!             ok = runtest(test, generate, verbose, quiet, testdir)
!             if ok > 0:
!                 good.append(test)
!             elif ok == 0:
!                 bad.append(test)
!             else:
!                 skipped.append(test)
!                 if ok == -2:
!                     resource_denieds.append(test)
          if findleaks:
              gc.collect()
***************
*** 331,334 ****
--- 347,354 ----
              os.unlink(filename)
  
+     if trace:
+         r = tracer.results()
+         r.write_results(show_missing=True, summary=True, coverdir=coverdir)
+ 
      sys.exit(len(bad) > 0)
  
***************
*** 363,367 ****
      return stdtests + tests
  
! def runtest(test, generate, verbose, quiet, testdir = None):
      """Run a single test.
      test -- the name of the test
--- 383,387 ----
      return stdtests + tests
  
! def runtest(test, generate, verbose, quiet, testdir=None):
      """Run a single test.
      test -- the name of the test
***************
*** 373,377 ****
      """
      test_support.unload(test)
!     if not testdir: testdir = findtestdir()
      outputdir = os.path.join(testdir, "output")
      outputfile = os.path.join(outputdir, test)
--- 393,398 ----
      """
      test_support.unload(test)
!     if not testdir:
!         testdir = findtestdir()
      outputdir = os.path.join(testdir, "output")
      outputfile = os.path.join(outputdir, test)




More information about the Python-checkins mailing list