Merge lp:~barry/mailman/nose2 into lp:mailman

Proposed by Barry Warsaw
Status: Merged
Merge reported by: Barry Warsaw
Merged at revision: not available
Proposed branch: lp:~barry/mailman/nose2
Merge into: lp:mailman
Diff against target: 329 lines (+120/-105)
9 files modified
setup.py (+2/-2)
src/mailman/__init__.py (+1/-1)
src/mailman/app/docs/hooks.rst (+2/-1)
src/mailman/model/docs/autorespond.rst (+1/-1)
src/mailman/testing/__init__.py (+0/-39)
src/mailman/testing/documentation.py (+3/-60)
src/mailman/testing/layers.py (+1/-1)
src/mailman/testing/nose.py (+100/-0)
unittest.cfg (+10/-0)
To merge this branch: bzr merge lp:~barry/mailman/nose2
Reviewer Review Type Date Requested Status
Mailman Coders Pending
Review via email: mp+182144@code.launchpad.net

Description of the change

Get rid of zc.buildout and zope.testing. Instead, use virtualenv and nose2.

To post a comment you must log in.
lp:~barry/mailman/nose2 updated
7218. By Barry Warsaw

Add enough __init__.py files to make these docs directories discoverable.

7219. By Barry Warsaw

* Suppress the extra Doctest: lines.
* Use DocFileTest directly.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'setup.py'
--- setup.py 2013-01-05 23:10:43 +0000
+++ setup.py 2013-08-28 00:48:00 +0000
@@ -101,14 +101,14 @@
101 'lazr.config',101 'lazr.config',
102 'lazr.smtptest',102 'lazr.smtptest',
103 'mock',103 'mock',
104 'nose2',
104 'passlib',105 'passlib',
105 'restish',106 'restish',
106 'storm',107 'storm',
107 'zc.buildout',
108 'zope.component',108 'zope.component',
109 'zope.configuration',109 'zope.configuration',
110 'zope.event',110 'zope.event',
111 'zope.interface',111 'zope.interface',
112 'zope.testing<4',
113 ],112 ],
113 test_suite = 'nose2.collector.collector',
114 )114 )
115115
=== modified file 'src/mailman/__init__.py'
--- src/mailman/__init__.py 2013-01-01 14:05:42 +0000
+++ src/mailman/__init__.py 2013-08-28 00:48:00 +0000
@@ -44,7 +44,7 @@
44#44#
45# Do *not* do this if we're building the documentation.45# Do *not* do this if we're building the documentation.
46if 'build_sphinx' not in sys.argv:46if 'build_sphinx' not in sys.argv:
47 if sys.argv[0].split(os.sep)[-1] == 'test':47 if any('nose2' in arg for arg in sys.argv):
48 from mailman.testing.i18n import initialize48 from mailman.testing.i18n import initialize
49 else:49 else:
50 from mailman.core.i18n import initialize50 from mailman.core.i18n import initialize
5151
=== modified file 'src/mailman/app/docs/hooks.rst'
--- src/mailman/app/docs/hooks.rst 2011-09-24 01:42:39 +0000
+++ src/mailman/app/docs/hooks.rst 2013-08-28 00:48:00 +0000
@@ -52,8 +52,9 @@
52 >>> import subprocess52 >>> import subprocess
53 >>> from mailman.testing.layers import ConfigLayer53 >>> from mailman.testing.layers import ConfigLayer
54 >>> def call():54 >>> def call():
55 ... exe = os.path.join(os.path.dirname(sys.executable), 'mailman')
55 ... proc = subprocess.Popen(56 ... proc = subprocess.Popen(
56 ... 'bin/mailman lists --domain ignore -q'.split(),57 ... [exe, 'lists', '--domain', 'ignore', '-q'],
57 ... cwd=ConfigLayer.root_directory,58 ... cwd=ConfigLayer.root_directory,
58 ... env=dict(MAILMAN_CONFIG_FILE=config_path,59 ... env=dict(MAILMAN_CONFIG_FILE=config_path,
59 ... PYTHONPATH=config_directory),60 ... PYTHONPATH=config_directory),
6061
=== added file 'src/mailman/archiving/docs/__init__.py'
=== added file 'src/mailman/commands/docs/__init__.py'
=== added file 'src/mailman/handlers/docs/__init__.py'
=== modified file 'src/mailman/model/docs/autorespond.rst'
--- src/mailman/model/docs/autorespond.rst 2011-09-24 01:42:39 +0000
+++ src/mailman/model/docs/autorespond.rst 2013-08-28 00:48:00 +0000
@@ -90,7 +90,7 @@
90 >>> response.address90 >>> response.address
91 <Address: aperson@example.com [not verified] at ...>91 <Address: aperson@example.com [not verified] at ...>
92 >>> response.response_type92 >>> response.response_type
93 <EnumValue: Response.hold [int=1]>93 <EnumValue: Response.hold [value=1]>
94 >>> response.date_sent94 >>> response.date_sent
95 datetime.date(2005, 8, 1)95 datetime.date(2005, 8, 1)
9696
9797
=== added file 'src/mailman/mta/docs/__init__.py'
=== added file 'src/mailman/rules/docs/__init__.py'
=== added file 'src/mailman/runners/docs/__init__.py'
=== modified file 'src/mailman/testing/__init__.py'
--- src/mailman/testing/__init__.py 2013-01-01 14:05:42 +0000
+++ src/mailman/testing/__init__.py 2013-08-28 00:48:00 +0000
@@ -1,39 +0,0 @@
1# Copyright (C) 2011-2013 by the Free Software Foundation, Inc.
2#
3# This file is part of GNU Mailman.
4#
5# GNU Mailman is free software: you can redistribute it and/or modify it under
6# the terms of the GNU General Public License as published by the Free
7# Software Foundation, either version 3 of the License, or (at your option)
8# any later version.
9#
10# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13# more details.
14#
15# You should have received a copy of the GNU General Public License along with
16# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
17
18"""Set up testing.
19
20This is used as an interface to buildout.cfg's [test] section.
21zope.testrunner supports an initialization variable. It is set to import and
22run the following test initialization method.
23"""
24
25from __future__ import absolute_import, unicode_literals
26
27__metaclass__ = type
28__all__ = [
29 'initialize',
30 ]
31
32
33
340
35def initialize(root_directory):
36 """Initialize the test infrastructure."""
37 from mailman.testing import layers
38 layers.MockAndMonkeyLayer.testing_mode = True
39 layers.ConfigLayer.enable_stderr();
40 layers.ConfigLayer.set_root_directory(root_directory)
411
=== renamed file 'src/mailman/tests/test_documentation.py' => 'src/mailman/testing/documentation.py'
--- src/mailman/tests/test_documentation.py 2013-01-01 14:05:42 +0000
+++ src/mailman/testing/documentation.py 2013-08-28 00:48:00 +0000
@@ -25,23 +25,16 @@
2525
26__metaclass__ = type26__metaclass__ = type
27__all__ = [27__all__ = [
28 'test_suite',28 'setup',
29 'teardown'
29 ]30 ]
3031
3132
32import os
33import sys
34import doctest
35import unittest
36
37from inspect import isfunction, ismethod33from inspect import isfunction, ismethod
3834
39import mailman
40
41from mailman.app.lifecycle import create_list35from mailman.app.lifecycle import create_list
42from mailman.config import config36from mailman.config import config
43from mailman.testing.helpers import (37from mailman.testing.helpers import call_api, specialized_message_from_string
44 call_api, chdir, specialized_message_from_string)
45from mailman.testing.layers import SMTPLayer38from mailman.testing.layers import SMTPLayer
4639
4740
@@ -181,53 +174,3 @@
181 cleanup()174 cleanup()
182 else:175 else:
183 cleanup[0](*cleanup[1:])176 cleanup[0](*cleanup[1:])
184
185
186
187177
188def test_suite():
189 """Create test suites for all .rst documentation tests.
190
191 .txt files are also tested, but .rst is highly preferred.
192 """
193 suite = unittest.TestSuite()
194 topdir = os.path.dirname(mailman.__file__)
195 packages = []
196 for dirpath, dirnames, filenames in os.walk(topdir):
197 if 'docs' in dirnames:
198 docsdir = os.path.join(dirpath, 'docs')[len(topdir)+1:]
199 packages.append(docsdir)
200 # Under higher verbosity settings, report all doctest errors, not just the
201 # first one.
202 flags = (doctest.ELLIPSIS |
203 doctest.NORMALIZE_WHITESPACE |
204 doctest.REPORT_NDIFF)
205 # Add all the doctests in all subpackages.
206 doctest_files = {}
207 with chdir(topdir):
208 for docsdir in packages:
209 # Look to see if the package defines a test layer, otherwise use
210 # SMTPLayer.
211 package_path = 'mailman.' + DOT.join(docsdir.split(os.sep))
212 try:
213 __import__(package_path)
214 except ImportError:
215 layer = SMTPLayer
216 else:
217 layer = getattr(sys.modules[package_path], 'layer', SMTPLayer)
218 for filename in os.listdir(docsdir):
219 base, extension = os.path.splitext(filename)
220 if os.path.splitext(filename)[1] in ('.txt', '.rst'):
221 module_path = package_path + '.' + base
222 doctest_files[module_path] = (
223 os.path.join(docsdir, filename), layer)
224 for module_path in sorted(doctest_files):
225 path, layer = doctest_files[module_path]
226 test = doctest.DocFileSuite(
227 path,
228 package='mailman',
229 optionflags=flags,
230 setUp=setup,
231 tearDown=teardown)
232 test.layer = layer
233 suite.addTest(test)
234 return suite
235178
=== modified file 'src/mailman/testing/layers.py'
--- src/mailman/testing/layers.py 2013-06-17 13:36:43 +0000
+++ src/mailman/testing/layers.py 2013-08-28 00:48:00 +0000
@@ -154,7 +154,7 @@
154 continue154 continue
155 logger_name = 'mailman.' + sub_name155 logger_name = 'mailman.' + sub_name
156 log = logging.getLogger(logger_name)156 log = logging.getLogger(logger_name)
157 log.propagate = True157 #log.propagate = True
158 # Reopen the file to a new path that tests can get at. Instead of158 # Reopen the file to a new path that tests can get at. Instead of
159 # using the configuration file path though, use a path that's159 # using the configuration file path though, use a path that's
160 # specific to the logger so that tests can find expected output160 # specific to the logger so that tests can find expected output
161161
=== added file 'src/mailman/testing/nose.py'
--- src/mailman/testing/nose.py 1970-01-01 00:00:00 +0000
+++ src/mailman/testing/nose.py 2013-08-28 00:48:00 +0000
@@ -0,0 +1,100 @@
1# Copyright (C) 2013 by the Free Software Foundation, Inc.
2#
3# This file is part of GNU Mailman.
4#
5# GNU Mailman is free software: you can redistribute it and/or modify it under
6# the terms of the GNU General Public License as published by the Free
7# Software Foundation, either version 3 of the License, or (at your option)
8# any later version.
9#
10# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13# more details.
14#
15# You should have received a copy of the GNU General Public License along with
16# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
17
18"""nose2 test infrastructure."""
19
20from __future__ import absolute_import, print_function, unicode_literals
21
22__metaclass__ = type
23__all__ = [
24 'NosePlugin',
25 ]
26
27
28import os
29import re
30import doctest
31import mailman
32import importlib
33
34from mailman.testing.documentation import setup, teardown
35from mailman.testing.layers import ConfigLayer, MockAndMonkeyLayer, SMTPLayer
36from nose2.events import Plugin
37
38DOT = '.'
39FLAGS = doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | doctest.REPORT_NDIFF
40TOPDIR = os.path.dirname(mailman.__file__)
41
42
43
044
45class NosePlugin(Plugin):
46 configSection = 'mailman'
47
48 def __init__(self):
49 super(NosePlugin, self).__init__()
50 self.patterns = []
51 self.addArgument(self.patterns, 'P', 'pattern',
52 'Add a test matching pattern')
53
54 def startTestRun(self, event):
55 MockAndMonkeyLayer.testing_mode = True
56 ConfigLayer.enable_stderr()
57
58 def getTestCaseNames(self, event):
59 if len(self.patterns) == 0:
60 # No filter patterns, so everything should be tested.
61 return
62 names = filter(event.isTestMethod, dir(event.testCase))
63 for name in names:
64 for pattern in self.patterns:
65 if re.search(pattern, name):
66 break
67 else:
68 event.excludedNames.append(name)
69
70 def handleFile(self, event):
71 path = event.path[len(TOPDIR)+1:]
72 if len(self.patterns) > 0:
73 for pattern in self.patterns:
74 if re.search(pattern, path):
75 break
76 else:
77 # Skip this doctest.
78 return
79 base, ext = os.path.splitext(path)
80 if ext != '.rst':
81 return
82 # Look to see if the package defines a test layer, otherwise use the
83 # default layer. First turn the file system path into a dotted Python
84 # module path.
85 parent = os.path.dirname(path)
86 dotted = 'mailman.' + DOT.join(parent.split(os.path.sep))
87 try:
88 module = importlib.import_module(dotted)
89 except ImportError:
90 layer = SMTPLayer
91 else:
92 layer = getattr(module, 'layer', SMTPLayer)
93 test = doctest.DocFileTest(
94 path, package='mailman',
95 optionflags=FLAGS,
96 setUp=setup,
97 tearDown=teardown)
98 test.layer = layer
99 # Suppress the extra "Doctest: ..." line.
100 test.shortDescription = lambda: None
101 event.extraTests.append(test)
1102
=== added file 'unittest.cfg'
--- unittest.cfg 1970-01-01 00:00:00 +0000
+++ unittest.cfg 2013-08-28 00:48:00 +0000
@@ -0,0 +1,10 @@
1[unittest]
2verbose = 2
3plugins = mailman.testing.nose
4 nose2.plugins.layers
5
6[mailman]
7always-on = True
8
9[log-capture]
10always-on = False