diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/app/docs/hooks.rst | 3 | ||||
| -rw-r--r-- | src/mailman/model/docs/autorespond.rst | 2 | ||||
| -rw-r--r-- | src/mailman/testing/documentation.py (renamed from src/mailman/tests/test_documentation.py) | 63 | ||||
| -rw-r--r-- | src/mailman/testing/nose.py | 42 |
4 files changed, 46 insertions, 64 deletions
diff --git a/src/mailman/app/docs/hooks.rst b/src/mailman/app/docs/hooks.rst index 7e214f13f..a29c7ee10 100644 --- a/src/mailman/app/docs/hooks.rst +++ b/src/mailman/app/docs/hooks.rst @@ -52,8 +52,9 @@ script that will produce no output to force the hooks to run. >>> import subprocess >>> from mailman.testing.layers import ConfigLayer >>> def call(): + ... exe = os.path.join(os.path.dirname(sys.executable), 'mailman') ... proc = subprocess.Popen( - ... 'bin/mailman lists --domain ignore -q'.split(), + ... [exe, 'lists', '--domain', 'ignore', '-q'], ... cwd=ConfigLayer.root_directory, ... env=dict(MAILMAN_CONFIG_FILE=config_path, ... PYTHONPATH=config_directory), diff --git a/src/mailman/model/docs/autorespond.rst b/src/mailman/model/docs/autorespond.rst index 3a9ad01b2..df47fc2e7 100644 --- a/src/mailman/model/docs/autorespond.rst +++ b/src/mailman/model/docs/autorespond.rst @@ -90,7 +90,7 @@ You can also use the response set to get the date of the last response sent. >>> response.address <Address: aperson@example.com [not verified] at ...> >>> response.response_type - <EnumValue: Response.hold [int=1]> + <EnumValue: Response.hold [value=1]> >>> response.date_sent datetime.date(2005, 8, 1) diff --git a/src/mailman/tests/test_documentation.py b/src/mailman/testing/documentation.py index 37eb760ab..b1cc36f91 100644 --- a/src/mailman/tests/test_documentation.py +++ b/src/mailman/testing/documentation.py @@ -25,23 +25,16 @@ from __future__ import absolute_import, unicode_literals __metaclass__ = type __all__ = [ - 'test_suite', + 'setup', + 'teardown' ] -import os -import sys -import doctest -import unittest - from inspect import isfunction, ismethod -import mailman - from mailman.app.lifecycle import create_list from mailman.config import config -from mailman.testing.helpers import ( - call_api, chdir, specialized_message_from_string) +from mailman.testing.helpers import call_api, specialized_message_from_string from mailman.testing.layers import SMTPLayer @@ -181,53 +174,3 @@ def teardown(testobj): cleanup() else: cleanup[0](*cleanup[1:]) - - - -def test_suite(): - """Create test suites for all .rst documentation tests. - - .txt files are also tested, but .rst is highly preferred. - """ - suite = unittest.TestSuite() - topdir = os.path.dirname(mailman.__file__) - packages = [] - for dirpath, dirnames, filenames in os.walk(topdir): - if 'docs' in dirnames: - docsdir = os.path.join(dirpath, 'docs')[len(topdir)+1:] - packages.append(docsdir) - # Under higher verbosity settings, report all doctest errors, not just the - # first one. - flags = (doctest.ELLIPSIS | - doctest.NORMALIZE_WHITESPACE | - doctest.REPORT_NDIFF) - # Add all the doctests in all subpackages. - doctest_files = {} - with chdir(topdir): - for docsdir in packages: - # Look to see if the package defines a test layer, otherwise use - # SMTPLayer. - package_path = 'mailman.' + DOT.join(docsdir.split(os.sep)) - try: - __import__(package_path) - except ImportError: - layer = SMTPLayer - else: - layer = getattr(sys.modules[package_path], 'layer', SMTPLayer) - for filename in os.listdir(docsdir): - base, extension = os.path.splitext(filename) - if os.path.splitext(filename)[1] in ('.txt', '.rst'): - module_path = package_path + '.' + base - doctest_files[module_path] = ( - os.path.join(docsdir, filename), layer) - for module_path in sorted(doctest_files): - path, layer = doctest_files[module_path] - test = doctest.DocFileSuite( - path, - package='mailman', - optionflags=flags, - setUp=setup, - tearDown=teardown) - test.layer = layer - suite.addTest(test) - return suite diff --git a/src/mailman/testing/nose.py b/src/mailman/testing/nose.py index c8a6a0798..4255011d2 100644 --- a/src/mailman/testing/nose.py +++ b/src/mailman/testing/nose.py @@ -27,15 +27,20 @@ __all__ = [ import os import re +import doctest import mailman +import importlib -from mailman.testing.layers import ConfigLayer, MockAndMonkeyLayer +from mailman.testing.documentation import setup, teardown +from mailman.testing.layers import ConfigLayer, MockAndMonkeyLayer, SMTPLayer from nose2.events import Plugin - +DOT = '.' +FLAGS = doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | doctest.REPORT_NDIFF TOPDIR = os.path.dirname(mailman.__file__) + class NosePlugin(Plugin): configSection = 'mailman' @@ -59,3 +64,36 @@ class NosePlugin(Plugin): break else: event.excludedNames.append(name) + + def handleFile(self, event): + path = event.path[len(TOPDIR)+1:] + if len(self.patterns) > 0: + for pattern in self.patterns: + if re.search(pattern, path): + break + else: + # Skip this doctest. + return + base, ext = os.path.splitext(path) + if ext != '.rst': + return + # Look to see if the package defines a test layer, otherwise use the + # default layer. First turn the file system path into a dotted Python + # module path. + parent = os.path.dirname(path) + dotted = 'mailman.' + DOT.join(parent.split(os.path.sep)) + try: + module = importlib.import_module(dotted) + except ImportError: + layer = SMTPLayer + else: + layer = getattr(module, 'layer', SMTPLayer) + suite = doctest.DocFileSuite( + path, package='mailman', + optionflags=FLAGS, + setUp=setup, + tearDown=teardown) + # Flatten the suite, adding the layer flag on every TestCase. + for test in suite: + test.layer = layer + event.extraTests.append(test) |
