------------------------------------------------------------
revno: 6734
committer: Barry Warsaw <[email protected]>
branch nick: 3.0
timestamp: Wed 2009-05-27 17:44:10 +0200
message:
  Allow for setting the doctest layer in the doctest package's __init__.  If not
  given, then SMTPLayer is used by default.
added:
  src/mailman/rest/docs/__init__.py
modified:
  src/mailman/rest/docs/basic.txt
  src/mailman/testing/layers.py
  src/mailman/tests/test_documentation.py

=== added file 'src/mailman/rest/docs/__init__.py'
--- src/mailman/rest/docs/__init__.py   1970-01-01 00:00:00 +0000
+++ src/mailman/rest/docs/__init__.py   2009-05-27 15:44:10 +0000
@@ -0,0 +1,30 @@
+# Copyright (C) 2009 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/>.
+
+"""Doctest layer setup."""
+
+from __future__ import absolute_import, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+    'layer',
+    ]
+
+
+
+from mailman.testing.layers import RESTLayer
+layer = RESTLayer

=== modified file 'src/mailman/rest/docs/basic.txt'
--- src/mailman/rest/docs/basic.txt     2009-05-07 02:07:35 +0000
+++ src/mailman/rest/docs/basic.txt     2009-05-27 15:44:10 +0000
@@ -1,12 +1,9 @@
+===========
 REST server
 ===========
 
 Mailman exposes a REST HTTP server for administrative control.
 
-    >>> from mailman.rest.testing.server import TestableServer
-    >>> server = TestableServer()
-    >>> server.start()
-
 The server listens for connections on a configurable host name and port.
 Because the REST server has full administrative access, it should always be
 run only on localhost, unless you really know what you're doing.  The Mailman
@@ -24,7 +21,7 @@
 
 
 Non-existent links
-------------------
+==================
 
 when you try to access an admin link that doesn't exist, you get the
 appropriate HTTP 404 Not Found error.
@@ -34,9 +31,3 @@
     Traceback (most recent call last):
     ...
     HTTPError: HTTP Error 404: Not Found
-
-
-Cleanup
--------
-
-    >>> server.stop()

=== modified file 'src/mailman/testing/layers.py'
--- src/mailman/testing/layers.py       2009-02-18 02:40:55 +0000
+++ src/mailman/testing/layers.py       2009-05-27 15:44:10 +0000
@@ -23,6 +23,7 @@
 __all__ = [
     'ConfigLayer',
     'MockAndMonkeyLayer',
+    'RESTLayer',
     'SMTPLayer',
     ]
 
@@ -221,3 +222,23 @@
     @classmethod
     def testTearDown(cls):
         pass
+
+
+
+class RESTLayer(SMTPLayer):
+    """Layer for starting, stopping, and accessing the test REST layer."""
+
+    server = None
+
+    @classmethod
+    def setUp(cls):
+        assert cls.server is None, 'Layer already set up'
+        from mailman.rest.testing.server import TestableServer
+        cls.server = TestableServer()
+        cls.server.start()
+
+    @classmethod
+    def tearDown(cls):
+        assert cls.server is not None, 'Layer not set up'
+        cls.server.stop()
+        cls.server = None

=== modified file 'src/mailman/tests/test_documentation.py'
--- src/mailman/tests/test_documentation.py     2009-05-04 15:05:51 +0000
+++ src/mailman/tests/test_documentation.py     2009-05-27 15:44:10 +0000
@@ -30,6 +30,7 @@
 
 
 import os
+import sys
 import json
 import random
 import doctest
@@ -156,17 +157,26 @@
     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):
                 if os.path.splitext(filename)[1] == '.txt':
-                    doctest_files[filename] = os.path.join(docsdir, filename)
-    files = sorted(doctest_files)
-    for filename in files:
-        path = doctest_files[filename]
+                    doctest_files[filename] = (
+                        os.path.join(docsdir, filename), layer)
+    for filename in sorted(doctest_files):
+        path, layer = doctest_files[filename]
         test = doctest.DocFileSuite(
             path,
             package='mailman',
             optionflags=flags,
             setUp=setup)
-        test.layer = SMTPLayer
+        test.layer = layer
         suite.addTest(test)
     return suite



--
lp:mailman
https://code.launchpad.net/~mailman-coders/mailman/3.0

Your team Mailman Checkins is subscribed to branch lp:mailman.
To unsubscribe from this branch go to 
https://code.launchpad.net/~mailman-coders/mailman/3.0/+edit-subscription.
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe: 
http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to