diff options
| author | Barry Warsaw | 2012-03-12 18:03:35 -0700 |
|---|---|---|
| committer | Barry Warsaw | 2012-03-12 18:03:35 -0700 |
| commit | ce02817cd4d3cf982ca58dfcb177a0b62fa75d54 (patch) | |
| tree | 701efb7db4b7d045b1f0bd376eb993c519f7915f /src/mailman/styles/tests/test_styles.py | |
| parent | 3fe7d15a5c6e54cc0c201b10b9dd1329dffe2cd2 (diff) | |
| download | mailman-ce02817cd4d3cf982ca58dfcb177a0b62fa75d54.tar.gz mailman-ce02817cd4d3cf982ca58dfcb177a0b62fa75d54.tar.zst mailman-ce02817cd4d3cf982ca58dfcb177a0b62fa75d54.zip | |
Clean up of style test code, along with refactoring of corner cases to
unittests where they belong.
Diffstat (limited to '')
| -rw-r--r-- | src/mailman/styles/tests/test_styles.py | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/mailman/styles/tests/test_styles.py b/src/mailman/styles/tests/test_styles.py new file mode 100644 index 000000000..ce8b5064d --- /dev/null +++ b/src/mailman/styles/tests/test_styles.py @@ -0,0 +1,90 @@ +# Copyright (C) 2012 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 styles.""" + +from __future__ import absolute_import, print_function, unicode_literals + +__metaclass__ = type +__all__ = [ + 'TestStyle', + ] + + +import unittest + +from zope.component import getUtility +from zope.interface import implements +from zope.interface.exceptions import DoesNotImplement + +from mailman.interfaces.styles import ( + DuplicateStyleError, IStyle, IStyleManager) +from mailman.testing.layers import ConfigLayer + + + +class DummyStyle: + implements(IStyle) + + name = 'dummy' + priority = 1 + + def apply(self, mlist): + pass + + def match(self, mlist, styles): + styles.append(self) + + + +class TestStyle(unittest.TestCase): + """Test styles.""" + + layer = ConfigLayer + + def setUp(self): + self.manager = getUtility(IStyleManager) + + def test_register_style_again(self): + # Registering a style with the same name as a previous style raises an + # exception. + self.manager.register(DummyStyle()) + try: + self.manager.register(DummyStyle()) + except DuplicateStyleError: + pass + else: + raise AssertionError('DuplicateStyleError exception expected') + + def test_register_a_non_style(self): + # You can't register something that doesn't implement the IStyle + # interface. + try: + self.manager.register(object()) + except DoesNotImplement: + pass + else: + raise AssertionError('DoesNotImplement exception expected') + + def test_unregister_a_non_registered_style(self): + # You cannot unregister a style that hasn't yet been registered. + try: + self.manager.unregister(DummyStyle()) + except KeyError: + pass + else: + raise AssertionError('KeyError expected') |
