[Zope3-checkins] SVN: zope.testing/trunk/ Fix the test coverage. If
a module, for example `interfaces`, was in an
Stephan Richter
srichter at cosmos.phy.tufts.edu
Sat Apr 29 11:46:13 EDT 2006
Log message for revision 67750:
Fix the test coverage. If a module, for example `interfaces`, was in an
ignored directory/package, then if a module of the same name existed in
a covered direcotry/package, then it was also ignored there, because the
ignore cache stored the result by module name and not the filename of
the module. I provided a comprehensive test to fully test the ignoration
API and to demonstrate the issue.
Changed:
U zope.testing/trunk/CHANGES.txt
U zope.testing/trunk/src/zope/testing/testrunner-coverage.txt
U zope.testing/trunk/src/zope/testing/testrunner.py
-=-
Modified: zope.testing/trunk/CHANGES.txt
===================================================================
--- zope.testing/trunk/CHANGES.txt 2006-04-29 09:38:33 UTC (rev 67749)
+++ zope.testing/trunk/CHANGES.txt 2006-04-29 15:46:13 UTC (rev 67750)
@@ -1,6 +1,15 @@
zope.testing Package Changelog
=============================
+zope.testing version 2.x.y (???)
+--------------------------------
+
+- Fix the test coverage. If a module, for example `interfaces`, was in an
+ ignored directory/package, then if a module of the same name existed in a
+ covered direcotry/package, then it was also ignored there, because the
+ ignore cache stored the result by module name and not the filename of the
+ module.
+
zope.testing version 2.0 (2006/01/05)
--------------------------------------
Modified: zope.testing/trunk/src/zope/testing/testrunner-coverage.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner-coverage.txt 2006-04-29 09:38:33 UTC (rev 67749)
+++ zope.testing/trunk/src/zope/testing/testrunner-coverage.txt 2006-04-29 15:46:13 UTC (rev 67750)
@@ -1,5 +1,6 @@
Test Runner
===========
+
Code Coverage
-------------
@@ -76,3 +77,53 @@
>>> import shutil
>>> shutil.rmtree('coverage_dir')
+
+
+Ignoring Tests
+--------------
+
+The ``trace`` module supports ignoring directories and modules based the test
+selection. Only directories selected for testing should report coverage. The
+test runner provides a custom implementation of the relevant API.
+
+The ``TestIgnore`` class, the class managing the ignoring, is initialized by
+passing the command line options. It uses the options to determine the
+directories that should be covered.
+
+ >>> class FauxOptions(object):
+ ... package = None
+ ... test_path = [('/myproject/src/blah/foo', ''),
+ ... ('/myproject/src/blah/bar', '')]
+
+ >>> from zope.testing import testrunner
+ >>> ignore = testrunner.TestIgnore(FauxOptions())
+ >>> ignore._test_dirs
+ ['/myproject/src/blah/foo/', '/myproject/src/blah/bar/']
+
+We can now ask whether a particular module should be ignored:
+
+ >>> ignore.names('/myproject/src/blah/foo/baz.py', 'baz')
+ False
+ >>> ignore.names('/myproject/src/blah/bar/mine.py', 'mine')
+ False
+ >>> ignore.names('/myproject/src/blah/foo/__init__.py', 'foo')
+ False
+ >>> ignore.names('/myproject/src/blah/hello.py', 'hello')
+ True
+
+When running the test runner, modules are sometimes created from text
+strings. Those should *always* be ignored:
+
+ >>> ignore.names('/myproject/src/blah/hello.txt', '<string>')
+ True
+
+To make this check fast, the class implements a cache. In an early
+implementation, the result was cached by the module name, which was a problem,
+since a lot of modules carry the same name (not the Python dotted name
+here!). So just because a module has the same name in an ignored and tested
+directory, does not mean it is always ignored:
+
+ >>> ignore.names('/myproject/src/blah/module.py', 'module')
+ True
+ >>> ignore.names('/myproject/src/blah/foo/module.py', 'module')
+ False
Modified: zope.testing/trunk/src/zope/testing/testrunner.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner.py 2006-04-29 09:38:33 UTC (rev 67749)
+++ zope.testing/trunk/src/zope/testing/testrunner.py 2006-04-29 15:46:13 UTC (rev 67750)
@@ -49,11 +49,14 @@
def __init__(self, options):
self._test_dirs = [d[0] + os.path.sep for d in test_dirs(options, {})]
- self._ignore = {'<string>': 1}
+ self._ignore = {}
self._ignored = self._ignore.get
def names(self, filename, modulename):
- ignore = self._ignored(modulename)
+ # Special case: Modules generated from text files; i.e. doctests
+ if modulename == '<string>':
+ return True
+ ignore = self._ignored(filename)
if ignore is None:
ignore = True
if filename is not None:
@@ -61,7 +64,7 @@
if filename.startswith(d):
ignore = False
break
- self._ignore[modulename] = ignore
+ self._ignore[filename] = ignore
return ignore
class TestTrace(trace.Trace):
More information about the Zope3-Checkins
mailing list