[Checkins] SVN: zope.testing/trunk/ Made it Python 2.6 compatible
Patrick Gerken
do3ccqrv at gmail.com
Sat Sep 12 13:36:01 EDT 2009
Log message for revision 103876:
Made it Python 2.6 compatible
Changed:
U zope.testing/trunk/CHANGES.txt
U zope.testing/trunk/src/zope/testing/testrunner/profiling.py
U zope.testing/trunk/src/zope/testing/testrunner/testrunner-profiling.txt
-=-
Modified: zope.testing/trunk/CHANGES.txt
===================================================================
--- zope.testing/trunk/CHANGES.txt 2009-09-12 16:45:30 UTC (rev 103875)
+++ zope.testing/trunk/CHANGES.txt 2009-09-12 17:36:01 UTC (rev 103876)
@@ -4,7 +4,8 @@
3.8.2 (unreleased)
==================
-- Nothing changed yet.
+- Removing hotshot profiler when using Python 2.6. That makes zope.testing
+ compatible with Python 2.6
3.8.1 (2009-08-12)
Modified: zope.testing/trunk/src/zope/testing/testrunner/profiling.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner/profiling.py 2009-09-12 16:45:30 UTC (rev 103875)
+++ zope.testing/trunk/src/zope/testing/testrunner/profiling.py 2009-09-12 17:36:01 UTC (rev 103876)
@@ -55,36 +55,40 @@
# some Linux distributions don't include the profiler, which hotshot uses
-try:
- import hotshot
- import hotshot.stats
-except ImportError:
- pass
-else:
- class HotshotProfiler(object):
- """hotshot interface"""
+if not sys.hexversion >= 0x02060000:
+ # Hotshot is not maintained any longer in 2.6. It does not support
+ # merging to hotshot files. Thus we won't use it in python2.6 and
+ # onwards
+ try:
+ import hotshot
+ import hotshot.stats
+ except ImportError:
+ pass
+ else:
+ class HotshotProfiler(object):
+ """hotshot interface"""
- def __init__(self, filepath):
- self.profiler = hotshot.Profile(filepath)
- self.enable = self.profiler.start
- self.disable = self.profiler.stop
+ def __init__(self, filepath):
+ self.profiler = hotshot.Profile(filepath)
+ self.enable = self.profiler.start
+ self.disable = self.profiler.stop
+
+ def finish(self):
+ self.profiler.close()
- def finish(self):
- self.profiler.close()
+ def loadStats(self, prof_glob):
+ stats = None
+ for file_name in glob.glob(prof_glob):
+ loaded = hotshot.stats.load(file_name)
+ if stats is None:
+ stats = loaded
+ else:
+ stats.add(loaded)
+ return stats
- def loadStats(self, prof_glob):
- stats = None
- for file_name in glob.glob(prof_glob):
- loaded = hotshot.stats.load(file_name)
- if stats is None:
- stats = loaded
- else:
- stats.add(loaded)
- return stats
+ available_profilers['hotshot'] = HotshotProfiler
- available_profilers['hotshot'] = HotshotProfiler
-
class Profiling(zope.testing.testrunner.feature.Feature):
def __init__(self, runner):
Modified: zope.testing/trunk/src/zope/testing/testrunner/testrunner-profiling.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner/testrunner-profiling.txt 2009-09-12 16:45:30 UTC (rev 103875)
+++ zope.testing/trunk/src/zope/testing/testrunner/testrunner-profiling.txt 2009-09-12 17:36:01 UTC (rev 103876)
@@ -1,10 +1,16 @@
Profiling
=========
+The testrunner supports hotshot and cProfile profilers. Hotshot profiler
+support does not work with python2.6
+ >>> import os.path, sys
+ >>> profiler = '--profile=hotshot'
+ >>> if sys.hexversion >= 0x02060000:
+ ... profiler = '--profile=cProfile'
+
The testrunner includes the ability to profile the test execution with hotshot
-via the --profile option.
+via the --profile option, if it a python <= 2.6
- >>> import os.path, sys
>>> directory_with_tests = os.path.join(this_directory, 'testrunner-ex')
>>> sys.path.append(directory_with_tests)
@@ -13,7 +19,7 @@
... '--tests-pattern', '^sampletestsf?$',
... ]
- >>> sys.argv = [testrunner_script, '--profile=hotshot']
+ >>> sys.argv = [testrunner_script, profiler]
When the tests are run, we get profiling output.
@@ -32,7 +38,7 @@
Profiling also works across layers.
- >>> sys.argv = [testrunner_script, '-ssample2', '--profile=hotshot',
+ >>> sys.argv = [testrunner_script, '-ssample2', profiler,
... '--tests-pattern', 'sampletests_ntd']
>>> testrunner.run_internal(defaults)
Running...
More information about the checkins
mailing list