~sambuddhabasu1/mailman/fix_mailman_run_error

« back to all changes in this revision

Viewing changes to src/mailman/testing/helpers.py

  • Committer: Barry Warsaw
  • Date: 2012-04-01 18:53:38 UTC
  • mfrom: (7139.1.4 bug-967409)
  • Revision ID: barry@list.org-20120401185338-5qujo0c3kc9a8wtr
 * The `news` runner and queue has been renamed to the more accurate `nntp`.
   The runner has also been ported to Mailman 3 (LP: #967409).  Beta testers
   can can safely remove `$var_dir/queue/news`.

 * Configuration schema variable changes:
   [nntp]username -> [nntp]user
   [nntp]port (added)

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
    'TestableMaster',
26
26
    'body_line_iterator',
27
27
    'call_api',
 
28
    'configuration',
28
29
    'digest_mbox',
29
30
    'event_subscribers',
30
31
    'get_lmtp_client',
40
41
import os
41
42
import json
42
43
import time
 
44
import uuid
43
45
import errno
44
46
import signal
45
47
import socket
68
70
from mailman.utilities.mailbox import Mailbox
69
71
 
70
72
 
 
73
NL = '\n'
 
74
 
 
75
 
71
76
 
72
77
def make_testable_runner(runner_class, name=None, predicate=None):
73
78
    """Create a runner that runs until its queue is empty.
331
336
 
332
337
 
333
338
 
 
339
class configuration:
 
340
    """A decorator/context manager for temporarily setting configurations."""
 
341
 
 
342
    def __init__(self, section, **kws):
 
343
        self._section = section
 
344
        self._values = kws.copy()
 
345
        self._uuid = uuid.uuid4().hex
 
346
 
 
347
    def _apply(self):
 
348
        lines = ['[{0}]'.format(self._section)]
 
349
        for key, value in self._values.items():
 
350
            lines.append('{0}: {1}'.format(key, value))
 
351
        config.push(self._uuid, NL.join(lines))
 
352
 
 
353
    def _remove(self):
 
354
        config.pop(self._uuid)
 
355
 
 
356
    def __enter__(self):
 
357
        self._apply()
 
358
 
 
359
    def __exit__(self, *exc_info):
 
360
        self._remove()
 
361
        # Do not suppress exceptions.
 
362
        return False
 
363
 
 
364
    def __call__(self, func):
 
365
        def wrapper(*args, **kws):
 
366
            self._apply()
 
367
            try:
 
368
                return func(*args, **kws)
 
369
            finally:
 
370
                self._remove()
 
371
        return wrapper
 
372
 
 
373
 
 
374
 
334
375
def subscribe(mlist, first_name, role=MemberRole.member):
335
376
    """Helper for subscribing a sample person to a mailing list."""
336
377
    user_manager = getUtility(IUserManager)