summaryrefslogtreecommitdiff
path: root/Mailman/testing
diff options
context:
space:
mode:
authorBarry Warsaw2007-06-22 17:15:03 -0400
committerBarry Warsaw2007-06-22 17:15:03 -0400
commitd629fe4305a062a62eb77d12d8847b7e405ff5e6 (patch)
treea7bdda181b945ba86afeb89a2439f1836453bdd1 /Mailman/testing
parentfba4983f88e0305a32e3135d129621890bf9adde (diff)
downloadmailman-d629fe4305a062a62eb77d12d8847b7e405ff5e6.tar.gz
mailman-d629fe4305a062a62eb77d12d8847b7e405ff5e6.tar.zst
mailman-d629fe4305a062a62eb77d12d8847b7e405ff5e6.zip
Refactor tests to get consistent clean up behavior. The clean up sections
have been removed from the .txt files and instead added to the test harness, which all doctests now use.
Diffstat (limited to 'Mailman/testing')
-rw-r--r--Mailman/testing/base.py34
-rw-r--r--Mailman/testing/test_acknowledge.py9
-rw-r--r--Mailman/testing/test_address.py7
-rw-r--r--Mailman/testing/test_after_delivery.py8
-rw-r--r--Mailman/testing/test_avoid_duplicates.py10
-rw-r--r--Mailman/testing/test_calc_recips.py9
-rw-r--r--Mailman/testing/test_cleanse.py9
-rw-r--r--Mailman/testing/test_cook_headers.py7
-rw-r--r--Mailman/testing/test_decorate.py9
-rw-r--r--Mailman/testing/test_listmanager.py5
-rw-r--r--Mailman/testing/test_membership.py8
-rw-r--r--Mailman/testing/test_mlist_addresses.py5
-rw-r--r--Mailman/testing/test_replybot.py9
-rw-r--r--Mailman/testing/test_user.py9
-rw-r--r--Mailman/testing/test_usermanager.py5
15 files changed, 62 insertions, 81 deletions
diff --git a/Mailman/testing/base.py b/Mailman/testing/base.py
index 562443b1e..c3f64554a 100644
--- a/Mailman/testing/base.py
+++ b/Mailman/testing/base.py
@@ -24,6 +24,7 @@ import pwd
import sys
import stat
import shutil
+import doctest
import difflib
import tempfile
import unittest
@@ -35,9 +36,11 @@ from Mailman import MailList
from Mailman import Utils
from Mailman.bin import rmlist
from Mailman.configuration import config
+from Mailman.database import flush
from Mailman.database.dbcontext import dbcontext
NL = '\n'
+COMMASPACE = ', '
@@ -79,3 +82,34 @@ class TestBase(unittest.TestCase):
path = os.path.join(config.LOCK_DIR, filename)
print >> sys.stderr, '@@@@@ removing:', path
os.unlink(path)
+
+
+
+def cleaning_teardown(testobj):
+ for user in config.user_manager.users:
+ config.user_manager.delete_user(user)
+ for address in config.user_manager.addresses:
+ config.user_manager.delete_address(address)
+ for mlist in config.list_manager.mailing_lists:
+ for member in mlist.members.members:
+ member.unsubscribe()
+ for admin in mlist.administrators.members:
+ admin.unsubscribe()
+ config.list_manager.delete(mlist)
+ flush()
+ assert not list(config.list_manager.mailing_lists), (
+ 'There should be no mailing lists left: %s' %
+ COMMASPACE.join(sorted(config.list_manager.names)))
+ assert not list(config.user_manager.users), (
+ 'There should be no users left!')
+ assert not list(config.user_manager.addresses), (
+ 'There should be no addresses left!')
+
+
+def make_docfile_suite(path):
+ return doctest.DocFileSuite(
+ path,
+ optionflags=(doctest.ELLIPSIS
+ | doctest.NORMALIZE_WHITESPACE
+ | doctest.REPORT_NDIFF),
+ tearDown=cleaning_teardown)
diff --git a/Mailman/testing/test_acknowledge.py b/Mailman/testing/test_acknowledge.py
index a40d0c9e4..605c6edda 100644
--- a/Mailman/testing/test_acknowledge.py
+++ b/Mailman/testing/test_acknowledge.py
@@ -17,16 +17,11 @@
"""Doctest harness for testing message acknowledgment."""
-import doctest
import unittest
-
-options = (doctest.ELLIPSIS
- | doctest.NORMALIZE_WHITESPACE
- | doctest.REPORT_NDIFF)
+from Mailman.testing.base import make_docfile_suite
def test_suite():
suite = unittest.TestSuite()
- suite.addTest(doctest.DocFileSuite('../docs/acknowledge.txt',
- optionflags=options))
+ suite.addTest(make_docfile_suite('../docs/acknowledge.txt'))
return suite
diff --git a/Mailman/testing/test_address.py b/Mailman/testing/test_address.py
index a04b3e795..d66292c55 100644
--- a/Mailman/testing/test_address.py
+++ b/Mailman/testing/test_address.py
@@ -17,14 +17,11 @@
"""Doctest harness for testing IAddress interface."""
-import doctest
import unittest
-
-options = doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE
+from Mailman.testing.base import make_docfile_suite
def test_suite():
suite = unittest.TestSuite()
- suite.addTest(doctest.DocFileSuite('../docs/addresses.txt',
- optionflags=options))
+ suite.addTest(make_docfile_suite('../docs/addresses.txt'))
return suite
diff --git a/Mailman/testing/test_after_delivery.py b/Mailman/testing/test_after_delivery.py
index ea4801b39..a7d0f01f4 100644
--- a/Mailman/testing/test_after_delivery.py
+++ b/Mailman/testing/test_after_delivery.py
@@ -17,16 +17,12 @@
"""Doctest harness for testing bookkeeping done after message delivery."""
-import doctest
import unittest
-options = (doctest.ELLIPSIS
- | doctest.NORMALIZE_WHITESPACE
- | doctest.REPORT_NDIFF)
+from Mailman.testing.base import make_docfile_suite
def test_suite():
suite = unittest.TestSuite()
- suite.addTest(doctest.DocFileSuite('../docs/after-delivery.txt',
- optionflags=options))
+ suite.addTest(make_docfile_suite('../docs/after-delivery.txt'))
return suite
diff --git a/Mailman/testing/test_avoid_duplicates.py b/Mailman/testing/test_avoid_duplicates.py
index 96599f1ed..b5de721e6 100644
--- a/Mailman/testing/test_avoid_duplicates.py
+++ b/Mailman/testing/test_avoid_duplicates.py
@@ -17,17 +17,11 @@
"""Doctest harness for the AvoidDuplicates handler."""
-import os
-import doctest
import unittest
-
-options = (doctest.ELLIPSIS
- | doctest.NORMALIZE_WHITESPACE
- | doctest.REPORT_NDIFF)
+from Mailman.testing.base import make_docfile_suite
def test_suite():
suite = unittest.TestSuite()
- suite.addTest(doctest.DocFileSuite('../docs/avoid-duplicates.txt',
- optionflags=options))
+ suite.addTest(make_docfile_suite('../docs/avoid-duplicates.txt'))
return suite
diff --git a/Mailman/testing/test_calc_recips.py b/Mailman/testing/test_calc_recips.py
index 7e876d428..da3929b65 100644
--- a/Mailman/testing/test_calc_recips.py
+++ b/Mailman/testing/test_calc_recips.py
@@ -17,16 +17,11 @@
"""Doctest harness for testing the recipient calculation handler."""
-import doctest
import unittest
-
-options = (doctest.ELLIPSIS
- | doctest.NORMALIZE_WHITESPACE
- | doctest.REPORT_NDIFF)
+from Mailman.testing.base import make_docfile_suite
def test_suite():
suite = unittest.TestSuite()
- suite.addTest(doctest.DocFileSuite('../docs/calc-recips.txt',
- optionflags=options))
+ suite.addTest(make_docfile_suite('../docs/calc-recips.txt'))
return suite
diff --git a/Mailman/testing/test_cleanse.py b/Mailman/testing/test_cleanse.py
index 97ad9c46c..e058c7bfa 100644
--- a/Mailman/testing/test_cleanse.py
+++ b/Mailman/testing/test_cleanse.py
@@ -17,16 +17,11 @@
"""Doctest harness for the Cleanse handler."""
-import doctest
import unittest
-
-options = (doctest.ELLIPSIS
- | doctest.NORMALIZE_WHITESPACE
- | doctest.REPORT_NDIFF)
+from Mailman.testing.base import make_docfile_suite
def test_suite():
suite = unittest.TestSuite()
- suite.addTest(doctest.DocFileSuite('../docs/cleanse.txt',
- optionflags=options))
+ suite.addTest(make_docfile_suite('../docs/cleanse.txt'))
return suite
diff --git a/Mailman/testing/test_cook_headers.py b/Mailman/testing/test_cook_headers.py
index ec8997858..dd141aab9 100644
--- a/Mailman/testing/test_cook_headers.py
+++ b/Mailman/testing/test_cook_headers.py
@@ -18,12 +18,9 @@
"""Doctest harness for the CookHeaders handler."""
import os
-import doctest
import unittest
-options = (doctest.ELLIPSIS
- | doctest.NORMALIZE_WHITESPACE
- | doctest.REPORT_NDIFF)
+from Mailman.testing.base import make_docfile_suite
def test_suite():
@@ -31,5 +28,5 @@ def test_suite():
for filename in ('ack-headers', 'cook-headers', 'subject-munging',
'reply-to'):
path = os.path.join('..', 'docs', filename + '.txt')
- suite.addTest(doctest.DocFileSuite(path, optionflags=options))
+ suite.addTest(make_docfile_suite(path))
return suite
diff --git a/Mailman/testing/test_decorate.py b/Mailman/testing/test_decorate.py
index 23af0598c..1bbe84250 100644
--- a/Mailman/testing/test_decorate.py
+++ b/Mailman/testing/test_decorate.py
@@ -17,16 +17,11 @@
"""Doctest harness for testing message decoration."""
-import doctest
import unittest
-
-options = (doctest.ELLIPSIS
- | doctest.NORMALIZE_WHITESPACE
- | doctest.REPORT_NDIFF)
+from Mailman.testing.base import make_docfile_suite
def test_suite():
suite = unittest.TestSuite()
- suite.addTest(doctest.DocFileSuite('../docs/decorate.txt',
- optionflags=options))
+ suite.addTest(make_docfile_suite('../docs/decorate.txt'))
return suite
diff --git a/Mailman/testing/test_listmanager.py b/Mailman/testing/test_listmanager.py
index 165018fa6..e6e9d6a3b 100644
--- a/Mailman/testing/test_listmanager.py
+++ b/Mailman/testing/test_listmanager.py
@@ -17,12 +17,11 @@
"""Doctest harness for testing mailing list creation and deletion."""
-import doctest
import unittest
+from Mailman.testing.base import make_docfile_suite
def test_suite():
suite = unittest.TestSuite()
- suite.addTest(doctest.DocFileSuite('../docs/listmanager.txt',
- optionflags=doctest.ELLIPSIS))
+ suite.addTest(make_docfile_suite('../docs/listmanager.txt'))
return suite
diff --git a/Mailman/testing/test_membership.py b/Mailman/testing/test_membership.py
index 8a25287ac..810a2fed9 100644
--- a/Mailman/testing/test_membership.py
+++ b/Mailman/testing/test_membership.py
@@ -19,7 +19,6 @@
import os
import time
-import doctest
import unittest
from Mailman import MailList
@@ -29,9 +28,7 @@ from Mailman import passwords
from Mailman.Errors import NotAMemberError
from Mailman.UserDesc import UserDesc
from Mailman.configuration import config
-from Mailman.testing.base import TestBase
-
-OPTIONFLAGS = doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE
+from Mailman.testing.base import TestBase, make_docfile_suite
@@ -390,6 +387,5 @@ class TestMembers(TestBase):
def test_suite():
suite = unittest.TestSuite()
- suite.addTest(doctest.DocFileSuite('../docs/membership.txt',
- optionflags=OPTIONFLAGS))
+ suite.addTest(make_docfile_suite('../docs/membership.txt'))
return suite
diff --git a/Mailman/testing/test_mlist_addresses.py b/Mailman/testing/test_mlist_addresses.py
index fe32c12b2..1998f33ee 100644
--- a/Mailman/testing/test_mlist_addresses.py
+++ b/Mailman/testing/test_mlist_addresses.py
@@ -17,12 +17,11 @@
"""Doctest harness for the IMailingListAddresses interface."""
-import doctest
import unittest
+from Mailman.testing.base import make_docfile_suite
def test_suite():
suite = unittest.TestSuite()
- suite.addTest(doctest.DocFileSuite('../docs/mlist-addresses.txt',
- optionflags=doctest.ELLIPSIS))
+ suite.addTest(make_docfile_suite('../docs/mlist-addresses.txt'))
return suite
diff --git a/Mailman/testing/test_replybot.py b/Mailman/testing/test_replybot.py
index 6b371c9d0..9f5d454a6 100644
--- a/Mailman/testing/test_replybot.py
+++ b/Mailman/testing/test_replybot.py
@@ -17,16 +17,11 @@
"""Doctest harness for testing the replybot handler."""
-import doctest
import unittest
-
-options = (doctest.ELLIPSIS
- | doctest.NORMALIZE_WHITESPACE
- | doctest.REPORT_NDIFF)
+from Mailman.testing.base import make_docfile_suite
def test_suite():
suite = unittest.TestSuite()
- suite.addTest(doctest.DocFileSuite('../docs/replybot.txt',
- optionflags=options))
+ suite.addTest(make_docfile_suite('../docs/replybot.txt'))
return suite
diff --git a/Mailman/testing/test_user.py b/Mailman/testing/test_user.py
index 59b686795..b66efac62 100644
--- a/Mailman/testing/test_user.py
+++ b/Mailman/testing/test_user.py
@@ -17,16 +17,11 @@
"""Doctest harness for testing users."""
-import doctest
import unittest
-
-options = (doctest.ELLIPSIS
- | doctest.NORMALIZE_WHITESPACE
- | doctest.REPORT_NDIFF)
+from Mailman.testing.base import make_docfile_suite
def test_suite():
suite = unittest.TestSuite()
- suite.addTest(doctest.DocFileSuite('../docs/users.txt',
- optionflags=options))
+ suite.addTest(make_docfile_suite('../docs/users.txt'))
return suite
diff --git a/Mailman/testing/test_usermanager.py b/Mailman/testing/test_usermanager.py
index fa115728e..9b98a6689 100644
--- a/Mailman/testing/test_usermanager.py
+++ b/Mailman/testing/test_usermanager.py
@@ -17,12 +17,11 @@
"""Doctest harness for testing mailing list creation and deletion."""
-import doctest
import unittest
+from Mailman.testing.base import make_docfile_suite
def test_suite():
suite = unittest.TestSuite()
- suite.addTest(doctest.DocFileSuite('../docs/usermanager.txt',
- optionflags=doctest.ELLIPSIS))
+ suite.addTest(make_docfile_suite('../docs/usermanager.txt'))
return suite