Skip to content

Commit

Permalink
Low-hanging fruit for coverage. Also whitespace cleanup in test_docte…
Browse files Browse the repository at this point in the history
…sts.py
  • Loading branch information
jamadden committed Nov 13, 2017
1 parent 4253f06 commit 5d70b40
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 124 deletions.
8 changes: 8 additions & 0 deletions .coveragerc
@@ -1,6 +1,12 @@
[run]
source = zope.testrunner
parallel = true
omit =
# These files are definitely imported and executed,
# but for some reason don't show up as such.
# See testrunner-knit
src/zope/testrunner/tests/testrunner-ex-pp-products/more/sampletests.py
src/zope/testrunner/tests/testrunner-ex-pp-products/sampletests.py

[report]
precision = 2
Expand All @@ -10,3 +16,5 @@ exclude_lines =
raise NotImplementedError
self.fail
raise AssertionError
if is_jython:
if sys.platform == 'win32':
4 changes: 2 additions & 2 deletions src/zope/testrunner/coverage.py
Expand Up @@ -28,7 +28,7 @@
# trace can be set, so that debugging still works.
osettrace = sys.settrace
def settrace(trace):
if trace is None:
if trace is None: # pragma: no cover
return
osettrace(trace)

Expand Down Expand Up @@ -81,7 +81,7 @@ def stop(self):
self.started = False


class TestIgnore:
class TestIgnore(object):

def __init__(self, directories):
self._test_dirs = [self._filenameFormat(d[0]) + os.path.sep
Expand Down
2 changes: 1 addition & 1 deletion src/zope/testrunner/profiling.py
Expand Up @@ -25,7 +25,7 @@
try:
import cProfile
import pstats
except ImportError:
except ImportError: # pragma: no cover (Where could this fail?)
pass
else:
class CProfiler(object):
Expand Down
221 changes: 104 additions & 117 deletions src/zope/testrunner/tests/test_doctest.py
Expand Up @@ -31,7 +31,7 @@
checker = renormalizing.RENormalizing([
# 2.5 changed the way pdb reports exceptions
(re.compile(r"<class 'exceptions.(\w+)Error'>:"),
r'exceptions.\1Error:'),
r'exceptions.\1Error:'),

#rewrite pdb prompt to ... the current location
#windows, py2.4 pdb seems not to put the '>' on doctest locations
Expand All @@ -41,9 +41,9 @@
#rewrite pdb prompt to ... the current location
(re.compile('^> [^\n]+->None$', re.M), '> ...->None'),

(re.compile(r"<module>"),(r'?')),
(re.compile(r"<module>"), (r'?')),
(re.compile(r"<type 'exceptions.(\w+)Error'>:"),
r'exceptions.\1Error:'),
r'exceptions.\1Error:'),

# testtools content formatter is used to mime-encode
# tracebacks when the SubunitOutputFormatter is used, and the
Expand Down Expand Up @@ -74,7 +74,7 @@
(re.compile('( |")[^\n]+testrunner-ex'), r'\1testrunner-ex'),
(re.compile('( |")[^\n]+testrunner.py'), r'\1testrunner.py'),
(re.compile(r'> [^\n]*(doc|unit)test[.]py\(\d+\)'),
r'\1test.py(NNN)'),
r'\1test.py(NNN)'),
(re.compile(r'[.]py\(\d+\)'), r'.py(NNN)'),
(re.compile(r'[.]py:\d+'), r'.py:NNN'),
(re.compile(r' line \d+,', re.IGNORECASE), r' Line NNN,'),
Expand Down Expand Up @@ -114,14 +114,14 @@
checker = renormalizing.RENormalizing([
# 2.5 changed the way pdb reports exceptions
(re.compile(r"<class 'exceptions.(\w+)Error'>:"),
r'exceptions.\1Error:'),
r'exceptions.\1Error:'),

#rewrite pdb prompt to ... the current location
(re.compile('^> [^\n]+->None$', re.M), '> ...->None'),

(re.compile(r"<module>"),(r'?')),
(re.compile(r"<module>"), (r'?')),
(re.compile(r"<type 'exceptions.(\w+)Error'>:"),
r'exceptions.\1Error:'),
r'exceptions.\1Error:'),

#this is a magic to put linefeeds into the doctest
#on win it takes one step, linux is crazy about the same...
Expand All @@ -136,7 +136,7 @@
(re.compile('( |"|\')[^\'\n]+testrunner-ex'), r'\1testrunner-ex'),
(re.compile('( |"|\')[^\'\n]+testrunner.py'), r'\1testrunner.py'),
(re.compile(r'> [^\n]*(doc|unit)test[.]py\(\d+\)'),
r'\1test.py(NNN)'),
r'\1test.py(NNN)'),
(re.compile(r'[.]py\(\d+\)'), r'.py(NNN)'),
(re.compile(r'[.]py:\d+'), r'.py:NNN'),
(re.compile(r' line \d+,', re.IGNORECASE), r' Line NNN,'),
Expand Down Expand Up @@ -205,109 +205,99 @@ def test_suite():
doctest.REPORT_NDIFF)
suites = [
doctest.DocFileSuite(
'testrunner-arguments.txt',
'testrunner-coverage.txt',
'testrunner-debugging-layer-setup.test',
'testrunner-debugging-import-failure.test',
'testrunner-debugging-nonprintable-exc.test',
'testrunner-debugging.txt',
'testrunner-edge-cases.txt',
'testrunner-errors.txt',
'testrunner-layers-api.txt',
'testrunner-layers-instances.txt',
'testrunner-layers-buff.txt',
'testrunner-subprocess-errors.txt',
'testrunner-layers-cantfind.txt',
'testrunner-layers-cwd.txt',
'testrunner-layers-ntd.txt',
'testrunner-layers-topological-sort.txt',
'testrunner-layers.txt',
'testrunner-progress.txt',
'testrunner-colors.txt',
'testrunner-simple.txt',
'testrunner-nestedcode.txt',
'testrunner-test-selection.txt',
'testrunner-verbose.txt',
'testrunner-repeat.txt',
'testrunner-knit.txt',
'testrunner-shuffle.txt',
'testrunner-eggsupport.txt',
'testrunner-stops-when-stop-on-error.txt',
'testrunner-new-threads.txt',
setUp=setUp, tearDown=tearDown,
optionflags=optionflags,
checker=checker),
'testrunner-arguments.txt',
'testrunner-coverage.txt',
'testrunner-debugging-layer-setup.test',
'testrunner-debugging-import-failure.test',
'testrunner-debugging-nonprintable-exc.test',
'testrunner-debugging.txt',
'testrunner-edge-cases.txt',
'testrunner-errors.txt',
'testrunner-layers-api.txt',
'testrunner-layers-instances.txt',
'testrunner-layers-buff.txt',
'testrunner-subprocess-errors.txt',
'testrunner-layers-cantfind.txt',
'testrunner-layers-cwd.txt',
'testrunner-layers-ntd.txt',
'testrunner-layers-topological-sort.txt',
'testrunner-layers.txt',
'testrunner-progress.txt',
'testrunner-colors.txt',
'testrunner-simple.txt',
'testrunner-nestedcode.txt',
'testrunner-test-selection.txt',
'testrunner-verbose.txt',
'testrunner-repeat.txt',
'testrunner-knit.txt',
'testrunner-shuffle.txt',
'testrunner-eggsupport.txt',
'testrunner-stops-when-stop-on-error.txt',
'testrunner-new-threads.txt',
setUp=setUp, tearDown=tearDown,
optionflags=optionflags,
checker=checker),
doctest.DocTestSuite('zope.testrunner'),
doctest.DocTestSuite('zope.testrunner.coverage',
optionflags=optionflags),
optionflags=optionflags),
doctest.DocTestSuite('zope.testrunner.options'),
doctest.DocTestSuite('zope.testrunner.find'),
]
]

# PyPy uses a different garbage collector
if hasattr(gc, 'get_threshold'):
suites.append(
doctest.DocFileSuite(
'testrunner-gc.txt',
setUp=setUp, tearDown=tearDown,
optionflags=optionflags,
checker=checker))
'testrunner-gc.txt',
setUp=setUp, tearDown=tearDown,
optionflags=optionflags,
checker=checker))

# PyPy does not support sourceless imports, apparently (tried version 1.9)
if 'PyPy' not in sys.version and not sys.dont_write_bytecode:
suites.append(
doctest.DocFileSuite(
'testrunner-wo-source.txt',
setUp=setUp, tearDown=tearDown,
optionflags=optionflags,
checker=checker))
'testrunner-wo-source.txt',
setUp=setUp, tearDown=tearDown,
optionflags=optionflags,
checker=checker))

if sys.platform == 'win32':
suites.append(
doctest.DocFileSuite(
'testrunner-coverage-win32.txt',
'testrunner-coverage-win32.txt',
setUp=setUp, tearDown=tearDown,
optionflags=optionflags,
checker=checker))

suites.append(
doctest.DocFileSuite(
'testrunner-profiling.txt',
setUp=setUp, tearDown=tearDown,
optionflags=optionflags,
checker=checker))

# Python <= 2.4.1 had a bug that prevented hotshot from running in
# non-optimize mode
if sys.version_info[:3] > (2,4,1) or not __debug__:
# some Linux distributions don't include the profiling module (which
# hotshot.stats depends on)
try:
import hotshot.stats
except ImportError:
pass
else:
suites.append(
doctest.DocFileSuite(
'testrunner-profiling.txt',
setUp=setUp, tearDown=tearDown,
optionflags=optionflags,
checker = renormalizing.RENormalizing([
(re.compile(r'tests_profile[.]\S*[.]prof'),
'tests_profile.*.prof'),
]),
)
)
try:
import cProfile
import pstats
except ImportError:
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'),
]),
)
)
checker=renormalizing.RENormalizing([
(re.compile(r'tests_profile[.]\S*[.]prof'),
'tests_profile.*.prof'),
]),
)
)
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(
Expand All @@ -320,39 +310,36 @@ def test_suite():
if hasattr(sys, 'gettotalrefcount'):
suites.append(
doctest.DocFileSuite(
'testrunner-leaks.txt',
setUp=setUp, tearDown=tearDown,
optionflags=optionflags,
checker = renormalizing.RENormalizing([
(re.compile(r'(\d+ minutes )?\d+[.]\d\d\d seconds'), 'N.NNN seconds'),
(re.compile(r'sys refcount=\d+ +change=\d+'),
'sys refcount=NNNNNN change=NN'),
(re.compile(r'sum detail refcount=\d+ +'),
'sum detail refcount=NNNNNN '),
(re.compile(r'total +\d+ +\d+'),
'total NNNN NNNN'),
(re.compile(r"^ +(int|type) +-?\d+ +-?\d+ *\n", re.M),
''),
]),

'testrunner-leaks.txt',
setUp=setUp, tearDown=tearDown,
optionflags=optionflags,
checker=renormalizing.RENormalizing([
(re.compile(r'(\d+ minutes )?\d+[.]\d\d\d seconds'), 'N.NNN seconds'),
(re.compile(r'sys refcount=\d+ +change=\d+'),
'sys refcount=NNNNNN change=NN'),
(re.compile(r'sum detail refcount=\d+ +'),
'sum detail refcount=NNNNNN '),
(re.compile(r'total +\d+ +\d+'),
'total NNNN NNNN'),
(re.compile(r"^ +(int|type) +-?\d+ +-?\d+ *\n", re.M),
''),
]),
)
)
else:
suites.append(
doctest.DocFileSuite(
'testrunner-leaks-err.txt',
setUp=setUp, tearDown=tearDown,
optionflags=optionflags,
checker=checker,
'testrunner-leaks-err.txt',
setUp=setUp, tearDown=tearDown,
optionflags=optionflags,
checker=checker,
)
)

if sys.version_info[:3] >= (2,7,0):
# Python 2.7 adds support for unittest.expectedFailure
suites.append(doctest.DocFileSuite(
'testrunner-unexpected-success.txt',
setUp=setUp, tearDown=tearDown,
optionflags=optionflags,
checker=checker))
suites.append(doctest.DocFileSuite(
'testrunner-unexpected-success.txt',
setUp=setUp, tearDown=tearDown,
optionflags=optionflags,
checker=checker))

return unittest.TestSuite(suites)
Expand Up @@ -20,6 +20,7 @@ class Test(unittest.TestCase):

def test_extra_test_in_products(self):
pass



def test_suite():
return unittest.makeSuite(Test)
8 changes: 6 additions & 2 deletions src/zope/testrunner/tests/testrunner-knit.txt
Expand Up @@ -18,7 +18,7 @@ It isn't enough to add the containing directory to the test path
because then we wouldn't be able to determine the package name
properly. We might be able to use the --package option to run the
tests from the sample4/products package, but we want to run tests in
testrunner-ex that aren't in this package.
testrunner-ex that aren't in this package.

We can use the --package-path option in this case. The --package-path
option is like the --test-path option in that it defines a path to be
Expand All @@ -39,7 +39,8 @@ package name and file path.
... ]

>>> from zope import testrunner

>>> old_argv = sys.argv

>>> sys.argv = 'test --layer Layer111 -vv'.split()
>>> _ = testrunner.run_internal(defaults)
Running tests at level 1
Expand Down Expand Up @@ -103,3 +104,6 @@ or individual packages within knit-in packages:
Tear down samplelayers.Layer11 in 0.000 seconds.
Tear down samplelayers.Layer1 in 0.000 seconds.

Restore the arguments::

>>> sys.argv = old_argv
2 changes: 1 addition & 1 deletion tox.ini
Expand Up @@ -15,7 +15,7 @@ basepython =
commands =
coverage run setup.py -q test -q
coverage combine
coverage report
coverage report --fail-under=85
setenv =
COVERAGE_PROCESS_START = {toxinidir}/.coveragerc
deps =
Expand Down

0 comments on commit 5d70b40

Please sign in to comment.