From b277307e38c610a3bbe3d140a4fbaef5641a34a3 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Fri, 18 Oct 2013 17:44:31 -0400 Subject: * When --sort is used, watch out for continuation lines, which shouldn't get sorted. * Fix stderr output in sub-runners, and move the -e test option to -E. --- src/mailman/commands/tests/test_conf.py | 7 ++++++- src/mailman/core/logging.py | 3 +-- src/mailman/docs/NEWS.rst | 3 ++- src/mailman/testing/layers.py | 33 ++++++--------------------------- src/mailman/testing/nose.py | 9 ++++++++- 5 files changed, 23 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/mailman/commands/tests/test_conf.py b/src/mailman/commands/tests/test_conf.py index 307151c74..04ce4c9b5 100644 --- a/src/mailman/commands/tests/test_conf.py +++ b/src/mailman/commands/tests/test_conf.py @@ -110,4 +110,9 @@ class TestConf(unittest.TestCase): self.command.process(self.args) last_line = '' for line in output.getvalue().splitlines(): - self.assertTrue(line > last_line) + if not line.startswith('['): + # This is a continuation line. --sort doesn't sort these. + continue + self.assertTrue(line > last_line, + '{} !> {}'.format(line, last_line)) + last_line = line diff --git a/src/mailman/core/logging.py b/src/mailman/core/logging.py index 7554c3651..c80535fc1 100644 --- a/src/mailman/core/logging.py +++ b/src/mailman/core/logging.py @@ -117,8 +117,7 @@ def initialize(propagate=None): # sublogs. The root logger should log to stderr. logging.basicConfig(format=config.logging.root.format, datefmt=config.logging.root.datefmt, - level=as_log_level(config.logging.root.level), - stream=sys.stderr) + level=as_log_level(config.logging.root.level)) # Create the sub-loggers. Note that we'll redirect flufl.lock to # mailman.locks. for logger_config in config.logger_configs: diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst index 6572c9a7b..552b396ac 100644 --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -16,7 +16,8 @@ Development ----------- * Mailman 3 no longer uses ``zc.buildout`` and tests are now run by the ``nose2`` test runner. See ``src/mailman/docs/START.rst`` for details on - how to build Mailman and run the test suite. + how to build Mailman and run the test suite. Also, use ``-P`` to select a + test pattern and ``-E`` to enable stderr debugging in runners. * Use the ``enum34`` package instead of ``flufl.enum``. REST diff --git a/src/mailman/testing/layers.py b/src/mailman/testing/layers.py index 6d150815f..2d2552f93 100644 --- a/src/mailman/testing/layers.py +++ b/src/mailman/testing/layers.py @@ -143,7 +143,6 @@ class ConfigLayer(MockAndMonkeyLayer): if cls.stderr: test_config += dedent(""" [logging.root] - propagate: yes level: debug """) # Enable log message propagation and reset the log paths so that the @@ -154,7 +153,7 @@ class ConfigLayer(MockAndMonkeyLayer): continue logger_name = 'mailman.' + sub_name log = logging.getLogger(logger_name) - #log.propagate = True + log.propagate = cls.stderr # Reopen the file to a new path that tests can get at. Instead of # using the configuration file path though, use a path that's # specific to the logger so that tests can find expected output @@ -170,15 +169,16 @@ class ConfigLayer(MockAndMonkeyLayer): propagate: yes level: debug """), dict(name=sub_name, path=path)) - # zope.testing sets up logging before we get to our own initialization - # function. This messes with the root logger, so explicitly set it to - # go to stderr. + # The root logger will already have a handler, but it's not the right + # handler. Remove that and set our own. if cls.stderr: console = logging.StreamHandler(sys.stderr) formatter = logging.Formatter(config.logging.root.format, config.logging.root.datefmt) console.setFormatter(formatter) - logging.getLogger().addHandler(console) + root = logging.getLogger() + del root.handlers[:] + root.addHandler(console) # Write the configuration file for subprocesses and set up the config # object to pass that properly on the -C option. config_file = os.path.join(cls.var_dir, 'test.cfg') @@ -209,27 +209,6 @@ class ConfigLayer(MockAndMonkeyLayer): # Flag to indicate that loggers should propagate to the console. stderr = False - @classmethod - def enable_stderr(cls): - """Enable stderr logging if -e/--stderr is given. - - We used to hack our way into the zc.testing framework, but that was - undocumented and way too fragile. Well, this probably is too, but now - we just scan sys.argv for -e/--stderr and enable logging if found. - Then we remove the option from sys.argv. This works because this - method is called before zope.testrunner sees the options. - - As a bonus, we'll check an environment variable too. - """ - if '-e' in sys.argv: - cls.stderr = True - sys.argv.remove('-e') - if '--stderr' in sys.argv: - cls.stderr = True - sys.argv.remove('--stderr') - if len(os.environ.get('MM_VERBOSE_TESTLOG', '').strip()) > 0: - cls.stderr = True - # The top of our source tree, for tests that care (e.g. hooks.txt). root_directory = None diff --git a/src/mailman/testing/nose.py b/src/mailman/testing/nose.py index 86a3e6a01..8ac85a756 100644 --- a/src/mailman/testing/nose.py +++ b/src/mailman/testing/nose.py @@ -47,12 +47,19 @@ class NosePlugin(Plugin): def __init__(self): super(NosePlugin, self).__init__() self.patterns = [] + self.stderr = False + def set_stderr(ignore): + self.stderr = True self.addArgument(self.patterns, 'P', 'pattern', 'Add a test matching pattern') + self.addFlag(set_stderr, 'E', 'stderr', + 'Enable stderr logging to sub-runners') def startTestRun(self, event): MockAndMonkeyLayer.testing_mode = True - ConfigLayer.enable_stderr() + if ( self.stderr or + len(os.environ.get('MM_VERBOSE_TESTLOG', '').strip()) > 0): + ConfigLayer.stderr = True def getTestCaseNames(self, event): if len(self.patterns) == 0: -- cgit v1.2.3-70-g09d2 From 76efb4974c3b7fd71f74f8f460beacc3b917eaa9 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Fri, 18 Oct 2013 18:18:46 -0400 Subject: * Fix importation from MM2.1 to MM3 of the archive policy. Given by Aurélien Bompard. (LP: #1227658) --- src/mailman/docs/NEWS.rst | 2 ++ src/mailman/utilities/importer.py | 13 +++++++ src/mailman/utilities/tests/test_import.py | 55 ++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) (limited to 'src') diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst index 552b396ac..c149494b7 100644 --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -53,6 +53,8 @@ Bugs signals. (LP: #1184376) * Add `subject_prefix` to the `IMailingList` interface, and clarify the docstring for `display_name`. (LP: #1181498) + * Fix importation from MM2.1 to MM3 of the archive policy. Given by Aurélien + Bompard. (LP: #1227658) 3.0 beta 3 -- "Here Again" diff --git a/src/mailman/utilities/importer.py b/src/mailman/utilities/importer.py index f5aa8d10a..ef2324197 100644 --- a/src/mailman/utilities/importer.py +++ b/src/mailman/utilities/importer.py @@ -33,6 +33,7 @@ from mailman.interfaces.autorespond import ResponseAction from mailman.interfaces.digests import DigestFrequency from mailman.interfaces.mailinglist import Personalization, ReplyToMunging from mailman.interfaces.nntp import NewsgroupModeration +from mailman.interfaces.archiver import ArchivePolicy @@ -90,3 +91,15 @@ def import_config_pck(mlist, config_dict): except TypeError: print('Type conversion error:', key, file=sys.stderr) raise + # Handle the archiving policy. In MM2.1 there were two boolean options + # but only three of the four possible states were valid. Now there's just + # an enum. + if config_dict.get('archive'): + # For maximum safety, if for some strange reason there's no + # archive_private key, treat the list as having private archives. + if config_dict.get('archive_private', True): + mlist.archive_policy = ArchivePolicy.private + else: + mlist.archive_policy = ArchivePolicy.public + else: + mlist.archive_policy = ArchivePolicy.never diff --git a/src/mailman/utilities/tests/test_import.py b/src/mailman/utilities/tests/test_import.py index c8da32e42..b64da7501 100644 --- a/src/mailman/utilities/tests/test_import.py +++ b/src/mailman/utilities/tests/test_import.py @@ -21,6 +21,7 @@ from __future__ import absolute_import, print_function, unicode_literals __metaclass__ = type __all__ = [ + 'TestArchiveImport', 'TestBasicImport', ] @@ -29,6 +30,7 @@ import cPickle import unittest from mailman.app.lifecycle import create_list, remove_list +from mailman.interfaces.archiver import ArchivePolicy from mailman.testing.layers import ConfigLayer from mailman.utilities.importer import import_config_pck from pkg_resources import resource_filename @@ -68,3 +70,56 @@ class TestBasicImport(unittest.TestCase): self._import() self.assertTrue(self._mlist.allow_list_posts) self.assertTrue(self._mlist.include_rfc2369_headers) + + + +class TestArchiveImport(unittest.TestCase): + """Test conversion of the archive policies. + + Mailman 2.1 had two variables `archive` and `archive_private`. Now + there's just a single `archive_policy` enum. + """ + layer = ConfigLayer + + def setUp(self): + self._mlist = create_list('blank@example.com') + self._mlist.archive_policy = 'INITIAL-TEST-VALUE' + + def _do_test(self, pckdict, expected): + import_config_pck(self._mlist, pckdict) + self.assertEqual(self._mlist.archive_policy, expected) + + def test_public(self): + self._do_test(dict(archive=True, archive_private=False), + ArchivePolicy.public) + + def test_private(self): + self._do_test(dict(archive=True, archive_private=True), + ArchivePolicy.private) + + def test_no_archive(self): + self._do_test(dict(archive=False, archive_private=False), + ArchivePolicy.never) + + def test_bad_state(self): + # For some reason, the old list has the invalid archiving state where + # `archive` is False and `archive_private` is True. It doesn't matter + # because this still collapses to the same enum value. + self._do_test(dict(archive=False, archive_private=True), + ArchivePolicy.never) + + def test_missing_archive_key(self): + # For some reason, the old list didn't have an `archive` key. We + # treat this as if no archiving is done. + self._do_test(dict(archive_private=False), ArchivePolicy.never) + + def test_missing_archive_key_archive_public(self): + # For some reason, the old list didn't have an `archive` key, and it + # has weird value for archive_private. We treat this as if no + # archiving is done. + self._do_test(dict(archive_private=True), ArchivePolicy.never) + + def test_missing_archive_private_key(self): + # For some reason, the old list was missing an `archive_private` key. + # For maximum safety, we treat this as private archiving. + self._do_test(dict(archive=True), ArchivePolicy.private) -- cgit v1.2.3-70-g09d2 From d370397e38f6357612811ba55af7fdee4552b59e Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Fri, 18 Oct 2013 18:20:38 -0400 Subject: Sort imports. --- src/mailman/utilities/importer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/mailman/utilities/importer.py b/src/mailman/utilities/importer.py index ef2324197..21a1e2f09 100644 --- a/src/mailman/utilities/importer.py +++ b/src/mailman/utilities/importer.py @@ -29,11 +29,11 @@ import sys import datetime from mailman.interfaces.action import FilterAction +from mailman.interfaces.archiver import ArchivePolicy from mailman.interfaces.autorespond import ResponseAction from mailman.interfaces.digests import DigestFrequency from mailman.interfaces.mailinglist import Personalization, ReplyToMunging from mailman.interfaces.nntp import NewsgroupModeration -from mailman.interfaces.archiver import ArchivePolicy -- cgit v1.2.3-70-g09d2