Commit adf7634d authored by Barry Warsaw's avatar Barry Warsaw

* Re-name doctests.

* Fix executable location now that we're not using buildout.
* Fix enum repr.
parent 4be0e93b
......@@ -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),
......
......@@ -90,7 +90,7 @@ You can also use the response set to get the date of the last response sent.
>>> response.address
<Address: [email protected] [not verified] at ...>
>>> response.response_type
<EnumValue: Response.hold [int=1]>
<EnumValue: Response.hold [value=1]>
>>> response.date_sent
datetime.date(2005, 8, 1)
......
......@@ -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
......@@ -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)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment