diff options
| author | Barry Warsaw | 2015-01-04 20:20:33 -0500 |
|---|---|---|
| committer | Barry Warsaw | 2015-01-04 20:20:33 -0500 |
| commit | 4a612db8e89afed74173b93f3b64fa567b8417a3 (patch) | |
| tree | 81a687d113079a25f93279f35c7eee2aa2572510 /src/mailman/testing | |
| parent | 84af79988a4e916604cba31843778206efb7d1b8 (diff) | |
| parent | de181c1a40965a3a7deedd56a034a946f45b6984 (diff) | |
| download | mailman-4a612db8e89afed74173b93f3b64fa567b8417a3.tar.gz mailman-4a612db8e89afed74173b93f3b64fa567b8417a3.tar.zst mailman-4a612db8e89afed74173b93f3b64fa567b8417a3.zip | |
Merge the Python 3 branch.
Diffstat (limited to 'src/mailman/testing')
| -rw-r--r-- | src/mailman/testing/documentation.py | 9 | ||||
| -rw-r--r-- | src/mailman/testing/helpers.py | 27 | ||||
| -rw-r--r-- | src/mailman/testing/i18n.py | 6 | ||||
| -rw-r--r-- | src/mailman/testing/layers.py | 20 | ||||
| -rw-r--r-- | src/mailman/testing/mta.py | 31 | ||||
| -rw-r--r-- | src/mailman/testing/nose.py | 10 |
6 files changed, 42 insertions, 61 deletions
diff --git a/src/mailman/testing/documentation.py b/src/mailman/testing/documentation.py index b8d852fed..e7511fb9b 100644 --- a/src/mailman/testing/documentation.py +++ b/src/mailman/testing/documentation.py @@ -21,9 +21,6 @@ Note that doctest extraction does not currently work for zip file distributions. doctest discovery currently requires file system traversal. """ -from __future__ import absolute_import, print_function, unicode_literals - -__metaclass__ = type __all__ = [ 'setup', 'teardown' @@ -31,7 +28,6 @@ __all__ = [ from inspect import isfunction, ismethod - from mailman.app.lifecycle import create_list from mailman.config import config from mailman.testing.helpers import call_api, specialized_message_from_string @@ -145,11 +141,6 @@ def dump_json(url, data=None, method=None, username=None, password=None): def setup(testobj): """Test setup.""" - # Make sure future statements in our doctests are the same as everywhere - # else. - testobj.globs['absolute_import'] = absolute_import - testobj.globs['print_function'] = print_function - testobj.globs['unicode_literals'] = unicode_literals # In general, I don't like adding convenience functions, since I think # doctests should do the imports themselves. It makes for better # documentation that way. However, a few are really useful, or help to diff --git a/src/mailman/testing/helpers.py b/src/mailman/testing/helpers.py index 38e210b06..b00534490 100644 --- a/src/mailman/testing/helpers.py +++ b/src/mailman/testing/helpers.py @@ -17,9 +17,6 @@ """Various test helpers.""" -from __future__ import absolute_import, print_function, unicode_literals - -__metaclass__ = type __all__ = [ 'LogFileMark', 'TestableMaster', @@ -60,11 +57,6 @@ from contextlib import contextmanager from email import message_from_string from httplib2 import Http from lazr.config import as_timedelta -from urllib import urlencode -from urllib2 import HTTPError -from zope import event -from zope.component import getUtility - from mailman.bin.master import Loop as Master from mailman.config import config from mailman.database.transaction import transaction @@ -75,6 +67,10 @@ from mailman.interfaces.styles import IStyleManager from mailman.interfaces.usermanager import IUserManager from mailman.runners.digest import DigestRunner from mailman.utilities.mailbox import Mailbox +from six.moves.urllib_error import HTTPError +from six.moves.urllib_parse import urlencode +from zope import event +from zope.component import getUtility NL = '\n' @@ -335,7 +331,10 @@ def call_api(url, data=None, method=None, username=None, password=None): basic_auth = '{0}:{1}'.format( (config.webservice.admin_user if username is None else username), (config.webservice.admin_pass if password is None else password)) - headers['Authorization'] = 'Basic ' + b64encode(basic_auth) + # b64encode() requires a bytes, but the header value must be str. Do the + # necessary conversion dances. + token = b64encode(basic_auth.encode('utf-8')).decode('ascii') + headers['Authorization'] = 'Basic ' + token response, content = Http().request(url, method, data, headers) # If we did not get a 2xx status code, make this look like a urllib2 # exception, for backward compatibility with existing doctests. @@ -470,10 +469,11 @@ def reset_the_world(): """ # Reset the database between tests. config.db._reset() - # Remove any digest files. + # Remove any digest files and members.txt file (for the file-recips + # handler) in the lists' data directories. for dirpath, dirnames, filenames in os.walk(config.LIST_DATA_DIR): for filename in filenames: - if filename.endswith('.mmdf'): + if filename.endswith('.mmdf') or filename == 'members.txt': os.remove(os.path.join(dirpath, filename)) # Remove all residual queue files. for dirpath, dirnames, filenames in os.walk(config.QUEUE_DIR): @@ -508,9 +508,8 @@ def specialized_message_from_string(unicode_text): """ # This mimic what Switchboard.dequeue() does when parsing a message from # text into a Message instance. - text = unicode_text.encode('ascii') - original_size = len(text) - message = message_from_string(text, Message) + original_size = len(unicode_text) + message = message_from_string(unicode_text, Message) message.original_size = original_size return message diff --git a/src/mailman/testing/i18n.py b/src/mailman/testing/i18n.py index 933a5ec0f..6718f5dda 100644 --- a/src/mailman/testing/i18n.py +++ b/src/mailman/testing/i18n.py @@ -17,9 +17,6 @@ """Internationalization for the tests.""" -from __future__ import absolute_import, print_function, unicode_literals - -__metaclass__ = type __all__ = [ 'TestingStrategy', 'initialize', @@ -29,9 +26,8 @@ __all__ = [ from contextlib import closing from flufl.i18n import registry from gettext import GNUTranslations, NullTranslations -from pkg_resources import resource_stream - from mailman.core.i18n import initialize as core_initialize +from pkg_resources import resource_stream diff --git a/src/mailman/testing/layers.py b/src/mailman/testing/layers.py index 74ad99dc8..d38878160 100644 --- a/src/mailman/testing/layers.py +++ b/src/mailman/testing/layers.py @@ -20,14 +20,10 @@ # XXX 2012-03-23 BAW: Layers really really suck. For example, the # test_owners_get_email() test requires that both the SMTPLayer and LMTPLayer # be set up, but there's apparently no way to do that and make zope.testing -# happy. This causes no tests failures, but it does cause errors at the end -# of the full test run. For now, I'll ignore that, but I do want to -# eventually get rid of the zope.test* dependencies and use something like -# testresources or some such. +# happy. This causes no test failures, but it does cause errors at the end of +# the full test run. For now, I'll ignore that, but I do want to eventually +# get rid of the layers and use something like testresources or some such. -from __future__ import absolute_import, print_function, unicode_literals - -__metaclass__ = type __all__ = [ 'ConfigLayer', 'LMTPLayer', @@ -46,10 +42,6 @@ import datetime import tempfile from lazr.config import as_boolean -from pkg_resources import resource_string -from textwrap import dedent -from zope.component import getUtility - from mailman.config import config from mailman.core import initialize from mailman.core.initialize import INHIBIT_CONFIG_FILE @@ -60,6 +52,9 @@ from mailman.testing.helpers import ( TestableMaster, get_lmtp_client, reset_the_world, wait_for_webservice) from mailman.testing.mta import ConnectionCountingController from mailman.utilities.string import expand +from pkg_resources import resource_string as resource_bytes +from textwrap import dedent +from zope.component import getUtility TEST_TIMEOUT = datetime.timedelta(seconds=5) @@ -132,7 +127,8 @@ class ConfigLayer(MockAndMonkeyLayer): configuration: {1} """.format(cls.var_dir, postfix_cfg)) # Read the testing config and push it. - test_config += resource_string('mailman.testing', 'testing.cfg') + more = resource_bytes('mailman.testing', 'testing.cfg') + test_config += more.decode('utf-8') config.create_paths = True config.push('test config', test_config) # Initialize everything else. diff --git a/src/mailman/testing/mta.py b/src/mailman/testing/mta.py index 875647485..81a6bf1ac 100644 --- a/src/mailman/testing/mta.py +++ b/src/mailman/testing/mta.py @@ -17,9 +17,6 @@ """Fake MTA for testing purposes.""" -from __future__ import absolute_import, print_function, unicode_literals - -__metaclass__ = type __all__ = [ 'FakeMTA', ] @@ -27,13 +24,11 @@ __all__ = [ import logging -from Queue import Empty, Queue - from lazr.smtptest.controller import QueueController from lazr.smtptest.server import Channel, QueueServer -from zope.interface import implementer - from mailman.interfaces.mta import IMailTransportAgentLifecycle +from six.moves.queue import Empty, Queue +from zope.interface import implementer log = logging.getLogger('lazr.smtptest') @@ -60,28 +55,28 @@ class StatisticsChannel(Channel): def smtp_EHLO(self, arg): if not arg: - self.push(b'501 Syntax: HELO hostname') + self.push('501 Syntax: HELO hostname') return if self._SMTPChannel__greeting: - self.push(b'503 Duplicate HELO/EHLO') + self.push('503 Duplicate HELO/EHLO') else: self._SMTPChannel__greeting = arg - self.push(b'250-%s' % self._SMTPChannel__fqdn) - self.push(b'250 AUTH PLAIN') + self.push('250-%s' % self._SMTPChannel__fqdn) + self.push('250 AUTH PLAIN') def smtp_STAT(self, arg): """Cause the server to send statistics to its controller.""" self._server.send_statistics() - self.push(b'250 Ok') + self.push('250 Ok') def smtp_AUTH(self, arg): """Record that the AUTH occurred.""" if arg == 'PLAIN AHRlc3R1c2VyAHRlc3RwYXNz': # testuser:testpass - self.push(b'235 Ok') + self.push('235 Ok') self._server.send_auth(arg) else: - self.push(b'571 Bad authentication') + self.push('571 Bad authentication') def smtp_RCPT(self, arg): """For testing, sometimes cause a non-25x response.""" @@ -92,7 +87,7 @@ class StatisticsChannel(Channel): else: # The test suite wants this to fail. The message corresponds to # the exception we expect smtplib.SMTP to raise. - self.push(b'%d Error: SMTPRecipientsRefused' % code) + self.push('%d Error: SMTPRecipientsRefused' % code) def smtp_MAIL(self, arg): """For testing, sometimes cause a non-25x response.""" @@ -103,7 +98,7 @@ class StatisticsChannel(Channel): else: # The test suite wants this to fail. The message corresponds to # the exception we expect smtplib.SMTP to raise. - self.push(b'%d Error: SMTPResponseException' % code) + self.push('%d Error: SMTPResponseException' % code) @@ -211,7 +206,7 @@ class ConnectionCountingController(QueueController): :rtype: integer """ smtpd = self._connect() - smtpd.docmd(b'STAT') + smtpd.docmd('STAT') # An Empty exception will occur if the data isn't available in 10 # seconds. Let that propagate. return self.oob_queue.get(block=True, timeout=10) @@ -232,4 +227,4 @@ class ConnectionCountingController(QueueController): def reset(self): smtpd = self._connect() - smtpd.docmd(b'RSET') + smtpd.docmd('RSET') diff --git a/src/mailman/testing/nose.py b/src/mailman/testing/nose.py index 8fe7017c0..181048b64 100644 --- a/src/mailman/testing/nose.py +++ b/src/mailman/testing/nose.py @@ -17,9 +17,6 @@ """nose2 test infrastructure.""" -from __future__ import absolute_import, print_function, unicode_literals - -__metaclass__ = type __all__ = [ 'NosePlugin', ] @@ -35,6 +32,7 @@ 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__) @@ -116,3 +114,9 @@ class NosePlugin(Plugin): # Suppress the extra "Doctest: ..." line. test.shortDescription = lambda: None event.extraTests.append(test) + + ## def startTest(self, event): + ## import sys; print('vvvvv', event.test, file=sys.stderr) + + ## def stopTest(self, event): + ## import sys; print('^^^^^', event.test, file=sys.stderr) |
