From 3eb6e862238e8cfd004389dfe37435a6d60ff605 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Tue, 11 Nov 2014 10:59:21 -0500 Subject: * Improve test coverage a bit. * Shore up the coverage.ini file. * Fix up Link.__repr__() --- coverage.ini | 10 +++-- src/mailman/__init__.py | 4 +- src/mailman/chains/base.py | 12 +++--- src/mailman/chains/tests/test_base.py | 80 +++++++++++++++++++++++++++++++++++ tox.ini | 3 +- 5 files changed, 96 insertions(+), 13 deletions(-) create mode 100644 src/mailman/chains/tests/test_base.py diff --git a/coverage.ini b/coverage.ini index 6acdb7541..56a2c7fab 100644 --- a/coverage.ini +++ b/coverage.ini @@ -4,6 +4,10 @@ parallel = true omit = setup* /usr/lib/* - -#[paths] -#source = + */showme.py + .tox/coverage/lib/python2.7/site-packages/* + +[paths] +source = + mailman + .tox/coverage/lib/python*/site-packages/mailman diff --git a/src/mailman/__init__.py b/src/mailman/__init__.py index e97ad4c56..db7befab7 100644 --- a/src/mailman/__init__.py +++ b/src/mailman/__init__.py @@ -31,7 +31,7 @@ import sys try: import pkg_resources pkg_resources.declare_namespace(__name__) -except ImportError: +except ImportError: # pragma: no cover import pkgutil __path__ = pkgutil.extend_path(__path__, __name__) @@ -42,7 +42,7 @@ except ImportError: # imported. # # Do *not* do this if we're building the documentation. -if 'build_sphinx' not in sys.argv: +if 'build_sphinx' not in sys.argv: # pragma: no cover if any('nose2' in arg for arg in sys.argv): from mailman.testing.i18n import initialize else: diff --git a/src/mailman/chains/base.py b/src/mailman/chains/base.py index 45f890517..37d8e76f3 100644 --- a/src/mailman/chains/base.py +++ b/src/mailman/chains/base.py @@ -46,16 +46,16 @@ class Link: self.function = function def __repr__(self): - message = '. + +"""Test the base chain stuff.""" + +from __future__ import absolute_import, print_function, unicode_literals + +__metaclass__ = type +__all__ = [ + 'TestMiscellaneous', + ] + + +import unittest + +from mailman.chains.accept import AcceptChain +from mailman.chains.base import Chain, Link +from mailman.interfaces.chain import LinkAction +from mailman.rules.any import Any + + + +class TestMiscellaneous(unittest.TestCase): + """Reach additional code coverage.""" + + def test_link_repr(self): + self.assertEqual( + repr(Link(Any)), '') + + def test_link_repr_function(self): + def function(): + pass + self.assertEqual( + repr(Link(Any, function=function)), + '') + + def test_link_repr_chain(self): + self.assertEqual( + repr(Link(Any, chain=AcceptChain)), + '') + + def test_link_repr_chain_and_function(self): + def function(): + pass + self.assertEqual( + repr(Link(Any, chain=AcceptChain, function=function)), + '') + + def test_link_repr_chain_all(self): + def function(): + pass + self.assertEqual( + repr(Link(Any, LinkAction.stop, AcceptChain, function)), + '') + + def test_flush(self): + # Test that we can flush the links of a chain. + chain = Chain('test', 'just a testing chain') + chain.append_link(Link(Any)) + # Iterate over the links of the chain to prove there are some. + count = sum(1 for link in chain.get_iterator()) + self.assertEqual(count, 1) + # Flush the chain; then there will be no links. + chain.flush() + count = sum(1 for link in chain.get_iterator()) + self.assertEqual(count, 0) diff --git a/tox.ini b/tox.ini index 475e4f9a3..803e8da37 100644 --- a/tox.ini +++ b/tox.ini @@ -18,14 +18,13 @@ deps = psycopg2 [coverage] rcfile = {toxinidir}/coverage.ini rc = --rcfile={[coverage]rcfile} -dir = --directory={envname} [testenv:coverage] basepython = python2.7 commands = coverage run {[coverage]rc} -m nose2 -v coverage combine {[coverage]rc} - coverage html {[coverage]rc} {[coverage]dir} + coverage html {[coverage]rc} #sitepackages = True usedevelop = True whitelist_externals = python-coverage -- cgit v1.2.3-70-g09d2