Commit ae60ba1d authored by Stefan H. Holek's avatar Stefan H. Holek

Removed broken profiler support.

parent 41e02756
......@@ -33,7 +33,6 @@ from ZopeTestCase import FunctionalTestCase
from PortalTestCase import portal_name
from PortalTestCase import PortalTestCase
from profiler import Profiled
from sandbox import Sandboxed
from functional import Functional
......
......@@ -18,7 +18,6 @@ $Id$
import ZopeLite as Zope2
import unittest
import transaction
import profiler
import utils
import interfaces
import connections
......@@ -41,7 +40,7 @@ def close(app):
class TestCase(profiler.Profiled, unittest.TestCase, object):
class TestCase(unittest.TestCase, object):
'''Base test case for Zope testing
'''
......
......@@ -57,8 +57,6 @@ Module Testing.ZopeTestCase
PortalTestCase
Profiled
Sandboxed
Functional
......@@ -243,38 +241,6 @@ Class PortalTestCase
Module profiler
Profiling support
Functions
runcall(func, *args, **kw)
print_stats()
dump_stats(filename)
Classes
Profiled
Class Profiled
Profiling support mix-in for xTestCases
Interfaces
implements(IProfiled)
Methods
runcall(func, *args, **kw)
Module sandbox
ZODB sandbox support
......
0.9.10 (Zope 2.11 edition)
- Switched to Zope3 interfaces.
- Removed broken profiler support.
0.9.9 (Zope 2.11 edition)
- transaction.commit(1) is deprecated in favor of transaction.savepoint(1).
......
<style type="text/css"> <!-- li { margin: 1em } --> </style>
Profiler Readme
Since version 0.9.0 all xTestCases are profiler aware by default.
You can run your tests under profiler control like this::
python testSomething.py profile
If you want to profile fixture creation or destruction type one of::
python testSomething.py profile-setup
python testSomething.py profile-teardown
Profiler statistics will be printed after the test results.
See the API reference for more on the 'profiler' module.
......@@ -95,14 +95,6 @@ class IPortalSecurity(IZopeSecurity):
'''This is currently the same as IZopeSecurity'''
class IProfiled(Interface):
def runcall(func, *args, **kw):
'''Allows to run a function under profiler control
adding to the accumulated profiler statistics.
'''
class IFunctional(Interface):
def publish(path, basic=None, env=None, extra=None, request_method='GET', stdin=None):
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Profiling support for ZTC
$Id$
"""
import os, sys
import interfaces
from zope.interface import implements
# Some distros ship without profile
try:
from profile import Profile
from pstats import Stats
except ImportError:
def Profile(): pass
_profile = Profile()
_have_stats = 0
limit = ('.py:', 200)
sort = ('cumulative', 'time', 'pcalls')
strip_dirs = 1
def runcall(*args, **kw):
if _profile is None:
return apply(args[0], args[1:], kw)
else:
global _have_stats
_have_stats = 1
return apply(_profile.runcall, args, kw)
def print_stats(limit=limit, sort=sort, strip_dirs=strip_dirs):
if _have_stats:
stats = Stats(_profile)
if strip_dirs:
stats.strip_dirs()
apply(stats.sort_stats, sort)
apply(stats.print_stats, limit)
def dump_stats(filename):
if _have_stats:
_profile.dump_stats(filename)
class Profiled:
'''Derive from this class and an xTestCase to get profiling support::
class MyTest(Profiled, ZopeTestCase):
...
Then run the test module by typing::
$ python testSomething.py profile
Profiler statistics will be printed after the test results.
'''
implements(interfaces.IProfiled)
def runcall(self, *args, **kw):
return apply(runcall, args, kw)
def __call__(self, result=None):
if result is None: result = self.defaultTestResult()
result.startTest(self)
testMethod = getattr(self, self._TestCase__testMethodName)
try:
try:
if int(os.environ.get('PROFILE_SETUP', 0)):
self.runcall(self.setUp)
else:
self.setUp()
except KeyboardInterrupt:
raise
except:
result.addError(self, self._TestCase__exc_info())
return
ok = 0
try:
if int(os.environ.get('PROFILE_TESTS', 0)):
self.runcall(testMethod)
else:
testMethod()
ok = 1
except self.failureException:
result.addFailure(self, self._TestCase__exc_info())
except KeyboardInterrupt:
raise
except:
result.addError(self, self._TestCase__exc_info())
try:
if int(os.environ.get('PROFILE_TEARDOWN', 0)):
self.runcall(self.tearDown)
else:
self.tearDown()
except KeyboardInterrupt:
raise
except:
result.addError(self, self._TestCase__exc_info())
ok = 0
if ok: result.addSuccess(self)
finally:
result.stopTest(self)
......@@ -28,19 +28,12 @@ from zope.interface.verify import verifyObject
class TestAbstractClasses(TestCase):
def testIProfiled(self):
self.failUnless(verifyClass(IProfiled, Profiled))
def testIFunctional(self):
self.failUnless(verifyClass(IFunctional, Functional))
class TestBaseTestCase(TestCase):
def testIProfiled(self):
self.failUnless(verifyClass(IProfiled, TestCase))
self.failUnless(verifyObject(IProfiled, self))
def testIZopeTestCase(self):
self.failUnless(verifyClass(IZopeTestCase, TestCase))
self.failUnless(verifyObject(IZopeTestCase, self))
......@@ -50,10 +43,6 @@ class TestZopeTestCase(ZopeTestCase):
_setup_fixture = 0
def testIProfiled(self):
self.failUnless(verifyClass(IProfiled, ZopeTestCase))
self.failUnless(verifyObject(IProfiled, self))
def testIZopeTestCase(self):
self.failUnless(verifyClass(IZopeTestCase, ZopeTestCase))
self.failUnless(verifyObject(IZopeTestCase, self))
......@@ -71,10 +60,6 @@ class TestFunctionalTestCase(FunctionalTestCase):
self.failUnless(verifyClass(IFunctional, FunctionalTestCase))
self.failUnless(verifyObject(IFunctional, self))
def testIProfiled(self):
self.failUnless(verifyClass(IProfiled, FunctionalTestCase))
self.failUnless(verifyObject(IProfiled, self))
def testIZopeTestCase(self):
self.failUnless(verifyClass(IZopeTestCase, FunctionalTestCase))
self.failUnless(verifyObject(IZopeTestCase, self))
......@@ -91,10 +76,6 @@ class TestPortalTestCase(PortalTestCase):
def _portal(self):
return None
def testIProfiled(self):
self.failUnless(verifyClass(IProfiled, PortalTestCase))
self.failUnless(verifyObject(IProfiled, self))
def testIZopeTestCase(self):
self.failUnless(verifyClass(IZopeTestCase, PortalTestCase))
self.failUnless(verifyObject(IZopeTestCase, self))
......
......@@ -21,7 +21,7 @@ $Id$
"""
# Overwrites the default framework() method to expose the
# TestRunner parameters and add profiler support.
# TestRunner parameters
#
def framework(stream=sys.stderr, descriptions=1, verbosity=1):
if __name__ != '__main__':
......@@ -29,17 +29,9 @@ def framework(stream=sys.stderr, descriptions=1, verbosity=1):
if len(sys.argv) > 1:
arg = sys.argv[1]
if arg in ('profile', 'profile-tests'):
os.environ['PROFILE_TESTS'] = '1'
elif arg == 'profile-setup':
os.environ['PROFILE_SETUP'] = '1'
elif arg == 'profile-teardown':
os.environ['PROFILE_TEARDOWN'] = '1'
else:
sys.exit(globals()[arg]() and 1 or 0)
sys.exit(globals()[arg]() and 1 or 0)
result = TestRunner(stream, descriptions, verbosity).run(test_suite())
from Testing.ZopeTestCase import profiler; profiler.print_stats()
sys.exit(len(result.errors) + len(result.failures))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment