diff options
| author | Barry Warsaw | 2014-11-11 10:59:21 -0500 |
|---|---|---|
| committer | Barry Warsaw | 2014-11-11 10:59:21 -0500 |
| commit | 3eb6e862238e8cfd004389dfe37435a6d60ff605 (patch) | |
| tree | 5f529728b2d240e6b8f02e4864e7a90c1a3ed472 | |
| parent | 46253fde1c3b90dbeb1e8a4d513cd38e302dabbb (diff) | |
| download | mailman-3eb6e862238e8cfd004389dfe37435a6d60ff605.tar.gz mailman-3eb6e862238e8cfd004389dfe37435a6d60ff605.tar.zst mailman-3eb6e862238e8cfd004389dfe37435a6d60ff605.zip | |
| -rw-r--r-- | coverage.ini | 10 | ||||
| -rw-r--r-- | src/mailman/__init__.py | 4 | ||||
| -rw-r--r-- | src/mailman/chains/base.py | 12 | ||||
| -rw-r--r-- | src/mailman/chains/tests/test_base.py | 80 | ||||
| -rw-r--r-- | tox.ini | 3 |
5 files changed, 96 insertions, 13 deletions
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 = '<Link "if {0.rule.name} then {0.action} ' + message = '<Link "if {0.rule.name} then {0.action}"' if self.chain is None and self.function is not None: - message += '{0.function}()' + message += ' {0.function.__name__}()' elif self.chain is not None and self.function is None: - message += '{0.chain.name}' + message += ' {0.chain.name}' elif self.chain is None and self.function is None: pass else: - message += '{0.chain.name} {0.function}()' - message += '">' + message += ' {0.chain.name} {0.function.__name__}()' + message += '>' return message.format(self) @@ -75,7 +75,7 @@ class TerminalChainBase: :param msg: The message. :param msgdata: The message metadata. """ - raise NotImplementedError + raise NotImplementedError # pragma: no cover def get_links(self, mlist, msg, msgdata): """See `IChain`.""" diff --git a/src/mailman/chains/tests/test_base.py b/src/mailman/chains/tests/test_base.py new file mode 100644 index 000000000..8d0d70449 --- /dev/null +++ b/src/mailman/chains/tests/test_base.py @@ -0,0 +1,80 @@ +# Copyright (C) 2014 by the Free Software Foundation, Inc. +# +# This file is part of GNU Mailman. +# +# GNU Mailman is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. + +"""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)), '<Link "if any then LinkAction.defer">') + + def test_link_repr_function(self): + def function(): + pass + self.assertEqual( + repr(Link(Any, function=function)), + '<Link "if any then LinkAction.defer" function()>') + + def test_link_repr_chain(self): + self.assertEqual( + repr(Link(Any, chain=AcceptChain)), + '<Link "if any then LinkAction.defer" accept>') + + def test_link_repr_chain_and_function(self): + def function(): + pass + self.assertEqual( + repr(Link(Any, chain=AcceptChain, function=function)), + '<Link "if any then LinkAction.defer" accept function()>') + + def test_link_repr_chain_all(self): + def function(): + pass + self.assertEqual( + repr(Link(Any, LinkAction.stop, AcceptChain, function)), + '<Link "if any then LinkAction.stop" accept 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) @@ -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 |
