[Zope3-checkins] SVN: zope.testing/trunk/src/zope/testing/ Cleaned up profiling test:

Jim Fulton jim at zope.com
Tue Nov 15 10:48:14 EST 2005


Log message for revision 40129:
  Cleaned up profiling test:
  
  - Renamed to match other text file names
  
  - Added documentation of the temporary files that profiling leaves
    behind intentionally.
  
  - Cleans up temporary files created when testing profiling.
  

Changed:
  D   zope.testing/trunk/src/zope/testing/profiling.txt
  A   zope.testing/trunk/src/zope/testing/testrunner-profiling.txt
  U   zope.testing/trunk/src/zope/testing/testrunner.py
  U   zope.testing/trunk/src/zope/testing/testrunner.txt

-=-
Deleted: zope.testing/trunk/src/zope/testing/profiling.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/profiling.txt	2005-11-15 15:13:49 UTC (rev 40128)
+++ zope.testing/trunk/src/zope/testing/profiling.txt	2005-11-15 15:48:14 UTC (rev 40129)
@@ -1,38 +0,0 @@
-Profiling
-=========
-
-The testrunner includes the ability to profile the test execution with hotshot
-via the --profile option.
-
-    >>> import os.path, sys
-    >>> directory_with_tests = os.path.join(this_directory, 'testrunner-ex')
-    >>> sys.path.append(directory_with_tests)
-
-    >>> defaults = [
-    ...     '--path', directory_with_tests,
-    ...     '--tests-pattern', '^sampletestsf?$',
-    ...     ]
-
-    >>> sys.argv = [testrunner_script, '--profile']
-
-When the tests are run, we get profiling output.
-
-    >>> from zope.testing import testrunner
-    >>> testrunner.run(defaults)
-    Running unit tests:
-    ...
-    Running samplelayers.Layer1 tests:
-    ...
-    Running samplelayers.Layer11 tests:
-    ...
-    Total: ... tests, 0 failures, 0 errors
-    ...
-       ncalls  tottime  percall  cumtime  percall filename:lineno(function)...
-
-Profiling also works across layers.
-
-    >>> sys.argv = [testrunner_script, '-ssample2', '--profile', '--tests-pattern', 'sampletests_ntd']
-    >>> testrunner.run(defaults)
-    Running...
-      Tear down ... not supported...
-       ncalls  tottime  percall  cumtime  percall filename:lineno(function)...

Copied: zope.testing/trunk/src/zope/testing/testrunner-profiling.txt (from rev 40124, zope.testing/trunk/src/zope/testing/profiling.txt)
===================================================================
--- zope.testing/trunk/src/zope/testing/profiling.txt	2005-11-15 14:50:05 UTC (rev 40124)
+++ zope.testing/trunk/src/zope/testing/testrunner-profiling.txt	2005-11-15 15:48:14 UTC (rev 40129)
@@ -0,0 +1,54 @@
+Profiling
+=========
+
+The testrunner includes the ability to profile the test execution with hotshot
+via the --profile option.
+
+    >>> import os.path, sys
+    >>> directory_with_tests = os.path.join(this_directory, 'testrunner-ex')
+    >>> sys.path.append(directory_with_tests)
+
+    >>> defaults = [
+    ...     '--path', directory_with_tests,
+    ...     '--tests-pattern', '^sampletestsf?$',
+    ...     ]
+
+    >>> sys.argv = [testrunner_script, '--profile']
+
+When the tests are run, we get profiling output.
+
+    >>> from zope.testing import testrunner
+    >>> testrunner.run(defaults)
+    Running unit tests:
+    ...
+    Running samplelayers.Layer1 tests:
+    ...
+    Running samplelayers.Layer11 tests:
+    ...
+    Total: ... tests, 0 failures, 0 errors
+    ...
+       ncalls  tottime  percall  cumtime  percall filename:lineno(function)...
+
+Profiling also works across layers.
+
+    >>> sys.argv = [testrunner_script, '-ssample2', '--profile', 
+    ...             '--tests-pattern', 'sampletests_ntd']
+    >>> testrunner.run(defaults)
+    Running...
+      Tear down ... not supported...
+       ncalls  tottime  percall  cumtime  percall filename:lineno(function)...
+
+The testrunner creates temnporary files containing hotshot profiler
+data:
+
+    >>> import glob
+    >>> files = list(glob.glob('tests_profile.*.prof'))
+    >>> files.sort()
+    >>> files
+    ['tests_profile.cZj2jt.prof', 'tests_profile.yHD-so.prof']
+
+It deletes these when rerun.  We'll delete these ourselves:
+
+    >>> import os
+    >>> for f in files:
+    ...     os.unlink(f)

Modified: zope.testing/trunk/src/zope/testing/testrunner.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner.py	2005-11-15 15:13:49 UTC (rev 40128)
+++ zope.testing/trunk/src/zope/testing/testrunner.py	2005-11-15 15:48:14 UTC (rev 40129)
@@ -168,8 +168,9 @@
                'so you can\'t use the --profile switch.')
         sys.exit()
 
-    if (hotshot is not None and options.profile
-    and sys.version_info[:3] <= (2,4,1) and __debug__):
+    if (options.profile
+        and sys.version_info[:3] <= (2,4,1)
+        and __debug__):
         print ('Because of a bug in Python < 2.4.1, profiling '
                'during tests requires the -O option be passed to '
                'Python (not the test runner).')
@@ -183,7 +184,7 @@
     else:
         tracer = None
 
-    if hotshot is not None and options.profile:
+    if options.profile:
         prof_prefix = 'tests_profile.'
         prof_suffix = '.prof'
         prof_glob = prof_prefix + '*' + prof_suffix
@@ -207,7 +208,7 @@
     finally:
         if tracer:
             tracer.stop()
-        if hotshot is not None and options.profile:
+        if options.profile:
             prof.stop()
             prof.close()
             # We must explicitly close the handle mkstemp returned, else on
@@ -215,7 +216,7 @@
             # attempt to unlink a still-open file.
             os.close(oshandle)
 
-    if hotshot is not None and options.profile and not options.resume_layer:
+    if options.profile and not options.resume_layer:
         stats = None
         for file_name in glob.glob(prof_glob):
             loaded = hotshot.stats.load(file_name)
@@ -223,6 +224,7 @@
                 stats = loaded
             else:
                 stats.add(loaded)
+
         stats.sort_stats('cumulative', 'calls')
         stats.print_stats(50)
 
@@ -1769,10 +1771,13 @@
         else:
             suites.append(
                 doctest.DocFileSuite(
-                    'profiling.txt',
+                    'testrunner-profiling.txt',
                     setUp=setUp, tearDown=tearDown,
                     optionflags=doctest.ELLIPSIS+doctest.NORMALIZE_WHITESPACE,
-                    checker=checker,
+                    checker = renormalizing.RENormalizing([
+                        (re.compile('tests_profile[.]\S*[.]prof'),
+                         'tests_profile.*.prof'),
+                        ]),
                     )
                 )
             

Modified: zope.testing/trunk/src/zope/testing/testrunner.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner.txt	2005-11-15 15:13:49 UTC (rev 40128)
+++ zope.testing/trunk/src/zope/testing/testrunner.txt	2005-11-15 15:48:14 UTC (rev 40129)
@@ -80,6 +80,7 @@
 - `Debugging <testrunner-debugging.txt>`_
 - `Layers that can't be torn down <testrunner-layers-ntd.txt>`_
 - `Code Coverage <testrunner-coverage.txt>`_
+- `Profiling <testrunner-profiling.txt>`_
 - `Running Without Source Code <testrunner-wo-source.txt>`_
 - `Repeating Tests <testrunner-looping.txt>`_
 - `Garbage Collection Control and Statistics <testrunner-gc.txt>`_



More information about the Zope3-Checkins mailing list