Skip to content

Commit

Permalink
cProfile is always available. Bump version number. Exclude coverage t…
Browse files Browse the repository at this point in the history
…emporary files.
  • Loading branch information
jamadden committed Nov 13, 2017
1 parent 1d132d3 commit 452bf24
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 43 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -10,4 +10,5 @@ tags
.tox
parts/
.coverage
.coverage.*
htmlcov/
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -21,7 +21,7 @@
from setuptools import setup
from setuptools.command.test import test

version = '4.8.2.dev0'
version = '4.9.0.dev0'

INSTALL_REQUIRES = [
'setuptools',
Expand Down
49 changes: 23 additions & 26 deletions src/zope/testrunner/profiling.py
Expand Up @@ -13,42 +13,39 @@
##############################################################################
"""Profiler support for the test runner
"""

import os
import cProfile
import glob
import os
import pstats
import tempfile

import zope.testrunner.feature

available_profilers = {}


try:
import cProfile
import pstats
except ImportError: # pragma: no cover (Where could this fail?)
pass
else:
class CProfiler(object):
"""cProfiler"""
def __init__(self, filepath):
self.filepath = filepath
self.profiler = cProfile.Profile()
self.enable = self.profiler.enable
self.disable = self.profiler.disable

def finish(self):
self.profiler.dump_stats(self.filepath)
class CProfiler(object):
"""cProfiler"""
def __init__(self, filepath):
self.filepath = filepath
self.profiler = cProfile.Profile()
self.enable = self.profiler.enable
self.disable = self.profiler.disable

def finish(self):
self.profiler.dump_stats(self.filepath)

def loadStats(self, prof_glob):
stats = None
for file_name in glob.glob(prof_glob):
if stats is None:
stats = pstats.Stats(file_name)
else:
stats.add(file_name)
return stats
def loadStats(self, prof_glob):
stats = None
for file_name in glob.glob(prof_glob):
if stats is None:
stats = pstats.Stats(file_name)
else:
stats.add(file_name)
return stats

available_profilers['cProfile'] = CProfiler
available_profilers['cProfile'] = CProfiler


class Profiling(zope.testrunner.feature.Feature):
Expand Down
26 changes: 10 additions & 16 deletions src/zope/testrunner/tests/test_doctest.py
Expand Up @@ -281,23 +281,17 @@ def test_suite():
]),
)
)
try:
import cProfile
import pstats
except ImportError: # pragma: no cover (where is this true?)
pass
else:
suites.append(
doctest.DocFileSuite(
'testrunner-profiling-cprofiler.txt',
setUp=setUp, tearDown=tearDown,
optionflags=optionflags,
checker=renormalizing.RENormalizing([
(re.compile(r'tests_profile[.]\S*[.]prof'),
'tests_profile.*.prof'),
]),
)
suites.append(
doctest.DocFileSuite(
'testrunner-profiling-cprofiler.txt',
setUp=setUp, tearDown=tearDown,
optionflags=optionflags,
checker=renormalizing.RENormalizing([
(re.compile(r'tests_profile[.]\S*[.]prof'),
'tests_profile.*.prof'),
]),
)
)

suites.append(
doctest.DocFileSuite(
Expand Down

0 comments on commit 452bf24

Please sign in to comment.