diff options
Diffstat (limited to 'src/mailman/testing/helpers.py')
| -rw-r--r-- | src/mailman/testing/helpers.py | 68 |
1 files changed, 7 insertions, 61 deletions
diff --git a/src/mailman/testing/helpers.py b/src/mailman/testing/helpers.py index 7c225d788..a10898d5d 100644 --- a/src/mailman/testing/helpers.py +++ b/src/mailman/testing/helpers.py @@ -40,11 +40,8 @@ import smtplib import datetime import threading -from Queue import Empty, Queue - from mailman.bin.master import Loop as Master from mailman.config import config -from mailman.testing.smtplistener import Server from mailman.utilities.mailbox import Mailbox @@ -140,6 +137,12 @@ class TestableMaster(Master): self.thread.daemon = True self._started_kids = None + def _pause(self): + """See `Master`.""" + # No-op this because the tests generally do not signal the master, + # which would mean the signal.pause() never exits. + pass + def start(self, *qrunners): """Start the master.""" self.start_qrunners(qrunners) @@ -162,7 +165,7 @@ class TestableMaster(Master): try: os.kill(pid, 0) starting_kids.remove(pid) - except OSError, error: + except OSError as error: if error.errno == errno.ESRCH: # The child has not yet started. pass @@ -185,63 +188,6 @@ class TestableMaster(Master): -class SMTPServer: - """An smtp server for testing.""" - - def __init__(self): - self._messages = [] - self._queue = Queue() - self.host = config.mta.smtp_host - self.port = int(config.mta.smtp_port) - self._server = Server((self.host, self.port), self._queue) - self._thread = threading.Thread(target=self._server.start) - self._thread.daemon = True - - def start(self): - """Start the smtp server in a thread.""" - log.info('test SMTP server starting') - self._thread.start() - smtpd = smtplib.SMTP() - log.info('connecting to %s:%s', self.host, self.port) - smtpd.connect(self.host, self.port) - response = smtpd.helo('test.localhost') - smtpd.quit() - log.info('SMTP server is running: %s', response) - - def stop(self): - """Stop the smtp server.""" - smtpd = smtplib.SMTP() - smtpd.connect(self.host, self.port) - smtpd.docmd('EXIT') - self.clear() - # Wait for the thread to exit. - self._thread.join() - log.info('test SMTP server stopped') - - @property - def messages(self): - """Return all the messages received by the smtp server.""" - # Look at the thread queue and append any messages from there to our - # internal list of messages. - while True: - try: - message = self._queue.get_nowait() - except Empty: - break - else: - self._messages.append(message) - # Now return all the messages we know about. - for message in self._messages: - yield message - - def clear(self): - """Clear all messages from the queue.""" - # Just throw these away. - list(self._messages) - self._messages = [] - - - class LMTP(smtplib.SMTP): """Like a normal SMTP client, but for LMTP.""" def lhlo(self, name=''): |
