summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mailman/commands/cli_aliases.py8
-rw-r--r--src/mailman/commands/cli_conf.py11
-rw-r--r--src/mailman/commands/cli_control.py18
-rw-r--r--src/mailman/commands/cli_digests.py10
-rw-r--r--src/mailman/commands/cli_help.py8
-rw-r--r--src/mailman/commands/cli_import.py10
-rw-r--r--src/mailman/commands/cli_info.py10
-rw-r--r--src/mailman/commands/cli_inject.py8
-rw-r--r--src/mailman/commands/cli_lists.py31
-rw-r--r--src/mailman/commands/cli_members.py32
-rw-r--r--src/mailman/commands/cli_qfile.py10
-rw-r--r--src/mailman/commands/cli_status.py12
-rw-r--r--src/mailman/commands/cli_unshunt.py8
-rw-r--r--src/mailman/commands/cli_version.py8
-rw-r--r--src/mailman/commands/cli_withlist.py13
-rw-r--r--src/mailman/commands/eml_confirm.py8
-rw-r--r--src/mailman/commands/eml_echo.py8
-rw-r--r--src/mailman/commands/eml_end.py10
-rw-r--r--src/mailman/commands/eml_help.py12
-rw-r--r--src/mailman/commands/eml_membership.py22
-rw-r--r--src/mailman/commands/tests/test_conf.py7
-rw-r--r--src/mailman/commands/tests/test_confirm.py25
-rw-r--r--src/mailman/commands/tests/test_control.py26
-rw-r--r--src/mailman/commands/tests/test_create.py20
-rw-r--r--src/mailman/commands/tests/test_digests.py57
-rw-r--r--src/mailman/commands/tests/test_help.py6
-rw-r--r--src/mailman/commands/tests/test_import.py7
-rw-r--r--src/mailman/commands/tests/test_lists.py5
-rw-r--r--src/mailman/commands/tests/test_members.py7
29 files changed, 117 insertions, 300 deletions
diff --git a/src/mailman/commands/cli_aliases.py b/src/mailman/commands/cli_aliases.py
index a8dab2ebb..76713555a 100644
--- a/src/mailman/commands/cli_aliases.py
+++ b/src/mailman/commands/cli_aliases.py
@@ -17,11 +17,7 @@
"""Generate Mailman alias files for your MTA."""
-__all__ = [
- 'Aliases',
- ]
-
-
+from mailman import public
from mailman.config import config
from mailman.core.i18n import _
from mailman.interfaces.command import ICLISubCommand
@@ -29,7 +25,7 @@ from mailman.utilities.modules import call_name
from zope.interface import implementer
-
+@public
@implementer(ICLISubCommand)
class Aliases:
"""Regenerate the aliases appropriate for your MTA."""
diff --git a/src/mailman/commands/cli_conf.py b/src/mailman/commands/cli_conf.py
index fcf48b312..67db4ac53 100644
--- a/src/mailman/commands/cli_conf.py
+++ b/src/mailman/commands/cli_conf.py
@@ -17,22 +17,18 @@
"""Print the mailman configuration."""
-__all__ = [
- 'Conf'
- ]
-
-
import sys
from contextlib import closing
from lazr.config._config import Section
+from mailman import public
from mailman.config import config
from mailman.core.i18n import _
from mailman.interfaces.command import ICLISubCommand
from zope.interface import implementer
-
+@public
@implementer(ICLISubCommand)
class Conf:
"""Print the mailman configuration."""
@@ -114,8 +110,7 @@ class Conf:
# We have to ensure that the current section actually exists
# and that it contains the given key.
if (self._section_exists(current_section) and
- hasattr(getattr(config, current_section), key)):
- # Then...
+ hasattr(getattr(config, current_section), key)):
self._print_full_syntax(
current_section, key,
self._get_value(current_section, key),
diff --git a/src/mailman/commands/cli_control.py b/src/mailman/commands/cli_control.py
index 22e7cb501..6a90a510d 100644
--- a/src/mailman/commands/cli_control.py
+++ b/src/mailman/commands/cli_control.py
@@ -17,20 +17,13 @@
"""Start/stop/reopen/restart commands."""
-__all__ = [
- 'Reopen',
- 'Restart',
- 'Start',
- 'Stop',
- ]
-
-
import os
import sys
import errno
import signal
import logging
+from mailman import public
from mailman.bin.master import WatcherState, master_state
from mailman.config import config
from mailman.core.i18n import _
@@ -41,7 +34,7 @@ from zope.interface import implementer
qlog = logging.getLogger('mailman.runner')
-
+@public
@implementer(ICLISubCommand)
class Start:
"""Start the Mailman master and runner processes."""
@@ -100,7 +93,7 @@ class Start:
self.parser.error(
_('A previous run of GNU Mailman did not exit '
'cleanly. Try using --force.'))
- def log(message):
+ def log(message): # flake8: noqa
if not args.quiet:
print(message)
# Try to find the path to a valid, existing configuration file, and
@@ -149,7 +142,6 @@ Use -C/--config to specify a valid configuration file."""), file=sys.stderr)
raise RuntimeError('os.execl() failed')
-
def kill_watcher(sig):
try:
with open(config.PID_FILE) as fp:
@@ -171,7 +163,6 @@ def kill_watcher(sig):
os.unlink(config.PID_FILE)
-
@implementer(ICLISubCommand)
class SignalCommand:
"""Common base class for simple, signal sending commands."""
@@ -196,6 +187,7 @@ class SignalCommand:
kill_watcher(self.signal)
+@public
class Stop(SignalCommand):
"""Stop the Mailman master and runner processes."""
@@ -204,6 +196,7 @@ class Stop(SignalCommand):
signal = signal.SIGTERM
+@public
class Reopen(SignalCommand):
"""Signal the Mailman processes to re-open their log files."""
@@ -212,6 +205,7 @@ class Reopen(SignalCommand):
signal = signal.SIGHUP
+@public
@implementer(ICLISubCommand)
class Restart(SignalCommand):
"""Stop and restart the Mailman runner subprocesses."""
diff --git a/src/mailman/commands/cli_digests.py b/src/mailman/commands/cli_digests.py
index 143df4ec5..c4623259e 100644
--- a/src/mailman/commands/cli_digests.py
+++ b/src/mailman/commands/cli_digests.py
@@ -17,13 +17,9 @@
"""The `send_digests` subcommand."""
-__all__ = [
- 'Digests',
- ]
-
-
import sys
+from mailman import public
from mailman.app.digests import (
bump_digest_number_and_volume, maybe_send_digest_now)
from mailman.core.i18n import _
@@ -33,7 +29,7 @@ from zope.component import getUtility
from zope.interface import implementer
-
+@public
@implementer(ICLISubCommand)
class Digests:
"""Operate on digests."""
@@ -78,7 +74,7 @@ class Digests:
else:
lists.append(mlist)
else:
- lists = list(list_manager.mailing_lists)
+ lists = list(list_manager.mailing_lists)
if args.bump:
for mlist in lists:
bump_digest_number_and_volume(mlist)
diff --git a/src/mailman/commands/cli_help.py b/src/mailman/commands/cli_help.py
index 0a68d0339..9222cd00f 100644
--- a/src/mailman/commands/cli_help.py
+++ b/src/mailman/commands/cli_help.py
@@ -17,16 +17,12 @@
"""The 'help' subcommand."""
-__all__ = [
- 'Help',
- ]
-
-
+from mailman import public
from mailman.interfaces.command import ICLISubCommand
from zope.interface import implementer
-
+@public
@implementer(ICLISubCommand)
class Help:
# Lowercase, to match argparse's default --help text.
diff --git a/src/mailman/commands/cli_import.py b/src/mailman/commands/cli_import.py
index e94f10a69..ecb879a5a 100644
--- a/src/mailman/commands/cli_import.py
+++ b/src/mailman/commands/cli_import.py
@@ -17,15 +17,11 @@
"""Importing list data into Mailman 3."""
-__all__ = [
- 'Import21',
- ]
-
-
import sys
import pickle
from contextlib import ExitStack, contextmanager
+from mailman import public
from mailman.core.i18n import _
from mailman.database.transaction import transactional
from mailman.interfaces.command import ICLISubCommand
@@ -35,7 +31,6 @@ from zope.component import getUtility
from zope.interface import implementer
-
# A fake Bouncer class from Mailman 2.1, we don't use it but there are
# instances in the .pck files.
class Bouncer:
@@ -53,8 +48,7 @@ def hacked_sys_modules():
del sys.modules['Mailman.Bouncer']
-
-
+@public
@implementer(ICLISubCommand)
class Import21:
"""Import Mailman 2.1 list data."""
diff --git a/src/mailman/commands/cli_info.py b/src/mailman/commands/cli_info.py
index 76e8e55da..fd6c83f88 100644
--- a/src/mailman/commands/cli_info.py
+++ b/src/mailman/commands/cli_info.py
@@ -17,14 +17,10 @@
"""Information about this Mailman instance."""
-__all__ = [
- 'Info'
- ]
-
-
import sys
from lazr.config import as_boolean
+from mailman import public
from mailman.config import config
from mailman.core.api import API30, API31
from mailman.core.i18n import _
@@ -33,7 +29,7 @@ from mailman.version import MAILMAN_VERSION_FULL
from zope.interface import implementer
-
+@public
@implementer(ICLISubCommand)
class Info:
"""Information about this Mailman instance."""
@@ -70,7 +66,7 @@ class Info:
file=output)
api = (API30 if config.webservice.api_version == '3.0' else API31)
print('REST root url:', api.path_to('/'), file=output)
- print('REST credentials: {0}:{1}'.format(
+ print('REST credentials: {}:{}'.format(
config.webservice.admin_user, config.webservice.admin_pass),
file=output)
if args.verbose:
diff --git a/src/mailman/commands/cli_inject.py b/src/mailman/commands/cli_inject.py
index b5cfab190..acbc37d67 100644
--- a/src/mailman/commands/cli_inject.py
+++ b/src/mailman/commands/cli_inject.py
@@ -17,13 +17,9 @@
"""The `mailman inject` subcommand."""
-__all__ = [
- 'Inject',
- ]
-
-
import sys
+from mailman import public
from mailman.app.inject import inject_text
from mailman.config import config
from mailman.core.i18n import _
@@ -33,7 +29,7 @@ from zope.component import getUtility
from zope.interface import implementer
-
+@public
@implementer(ICLISubCommand)
class Inject:
"""Inject a message from a file into a mailing list's queue."""
diff --git a/src/mailman/commands/cli_lists.py b/src/mailman/commands/cli_lists.py
index 3f31fda76..8720f91c5 100644
--- a/src/mailman/commands/cli_lists.py
+++ b/src/mailman/commands/cli_lists.py
@@ -17,13 +17,7 @@
"""The 'lists' subcommand."""
-__all__ = [
- 'Create',
- 'Lists',
- 'Remove',
- ]
-
-
+from mailman import public
from mailman.app.lifecycle import create_list, remove_list
from mailman.core.constants import system_preferences
from mailman.core.i18n import _
@@ -44,7 +38,7 @@ from zope.interface import implementer
COMMASPACE = ', '
-
+@public
@implementer(ICLISubCommand)
class Lists:
"""List all mailing lists"""
@@ -95,7 +89,7 @@ class Lists:
if not args.quiet:
print(_('No matching mailing lists found'))
return
- count = len(mailing_lists)
+ count = len(mailing_lists) # flake8: noqa
if not args.quiet:
print(_('$count matching mailing lists found:'))
# Calculate the longest identifier.
@@ -103,7 +97,7 @@ class Lists:
output = []
for mlist in mailing_lists:
if args.names:
- identifier = '{0} [{1}]'.format(
+ identifier = '{} [{}]'.format(
mlist.fqdn_listname, mlist.display_name)
else:
identifier = mlist.fqdn_listname
@@ -119,7 +113,7 @@ class Lists:
identifier, description, longest, 70 - longest))
-
+@public
@implementer(ICLISubCommand)
class Create:
"""Create a mailing list."""
@@ -204,7 +198,8 @@ class Create:
invalid_owners = [owner for owner in args.owners
if not validator.is_valid(owner)]
if invalid_owners:
- invalid = COMMASPACE.join(sorted(invalid_owners))
+ invalid = COMMASPACE.join( # flake8: noqa
+ sorted(invalid_owners))
self.parser.error(_('Illegal owner addresses: $invalid'))
return
try:
@@ -228,11 +223,11 @@ class Create:
print(_('Created mailing list: $mlist.fqdn_listname'))
if args.notify:
d = dict(
- listname = mlist.fqdn_listname,
- admin_url = mlist.script_url('admin'),
- listinfo_url = mlist.script_url('listinfo'),
- requestaddr = mlist.request_address,
- siteowner = mlist.no_reply_address,
+ listname = mlist.fqdn_listname,
+ admin_url = mlist.script_url('admin'),
+ listinfo_url = mlist.script_url('listinfo'),
+ requestaddr = mlist.request_address,
+ siteowner = mlist.no_reply_address,
)
text = make('newlist.txt', mailing_list=mlist, **d)
# Set the I18N language to the list's preferred language so the
@@ -246,7 +241,7 @@ class Create:
msg.send(mlist)
-
+@public
@implementer(ICLISubCommand)
class Remove:
"""Remove a mailing list."""
diff --git a/src/mailman/commands/cli_members.py b/src/mailman/commands/cli_members.py
index f27622571..476d1f77d 100644
--- a/src/mailman/commands/cli_members.py
+++ b/src/mailman/commands/cli_members.py
@@ -17,15 +17,11 @@
"""The 'members' subcommand."""
-__all__ = [
- 'Members',
- ]
-
-
import sys
from contextlib import ExitStack
from email.utils import formataddr, parseaddr
+from mailman import public
from mailman.app.membership import add_member
from mailman.core.i18n import _
from mailman.database.transaction import transactional
@@ -39,7 +35,7 @@ from zope.component import getUtility
from zope.interface import implementer
-
+@public
@implementer(ICLISubCommand)
class Members:
"""Manage list memberships. With no arguments, list all members."""
@@ -132,9 +128,11 @@ class Members:
:type args: `argparse.Namespace`
"""
if args.digest == 'any':
- digest_types = [DeliveryMode.plaintext_digests,
- DeliveryMode.mime_digests,
- DeliveryMode.summary_digests]
+ digest_types = [
+ DeliveryMode.plaintext_digests,
+ DeliveryMode.mime_digests,
+ DeliveryMode.summary_digests,
+ ]
elif args.digest is not None:
digest_types = [DeliveryMode[args.digest + '_digests']]
else:
@@ -153,13 +151,14 @@ class Members:
elif args.nomail == 'unknown':
status_types = [DeliveryStatus.unknown]
elif args.nomail == 'any':
- status_types = [DeliveryStatus.by_user,
- DeliveryStatus.by_bounces,
- DeliveryStatus.by_moderator,
- DeliveryStatus.unknown]
+ status_types = [
+ DeliveryStatus.by_user,
+ DeliveryStatus.by_bounces,
+ DeliveryStatus.by_moderator,
+ DeliveryStatus.unknown,
+ ]
else:
- status = args.nomail
- self.parser.error(_('Unknown delivery status: $status'))
+ self.parser.error(_('Unknown delivery status: $args.nomail'))
if args.role is None:
# By default, filter on members.
@@ -172,8 +171,7 @@ class Members:
try:
roster = mlist.get_roster(MemberRole[args.role])
except KeyError:
- role = args.role
- self.parser.error(_('Unknown member role: $role'))
+ self.parser.error(_('Unknown member role: $args.role'))
with ExitStack() as resources:
if args.output_filename == '-' or args.output_filename is None:
diff --git a/src/mailman/commands/cli_qfile.py b/src/mailman/commands/cli_qfile.py
index c0a64c003..c66ed85d7 100644
--- a/src/mailman/commands/cli_qfile.py
+++ b/src/mailman/commands/cli_qfile.py
@@ -17,13 +17,9 @@
"""Getting information out of a qfile."""
-__all__ = [
- 'QFile',
- ]
-
-
import pickle
+from mailman import public
from mailman.core.i18n import _
from mailman.interfaces.command import ICLISubCommand
from mailman.utilities.interact import interact
@@ -35,7 +31,7 @@ from zope.interface import implementer
m = []
-
+@public
@implementer(ICLISubCommand)
class QFile:
"""Get information out of a queue file."""
@@ -84,7 +80,7 @@ class QFile:
else:
printer.pprint(obj)
print(_('[----- end pickle -----]'))
- count = len(m)
+ count = len(m) # flake8: noqa
banner = _("The variable 'm' contains $count objects")
if args.interactive:
interact(banner=banner)
diff --git a/src/mailman/commands/cli_status.py b/src/mailman/commands/cli_status.py
index 5673d33d6..7cc69850a 100644
--- a/src/mailman/commands/cli_status.py
+++ b/src/mailman/commands/cli_status.py
@@ -17,20 +17,16 @@
"""The `mailman status` subcommand."""
-__all__ = [
- 'Status',
- ]
-
-
import socket
+from mailman import public
from mailman.bin.master import WatcherState, master_state
from mailman.core.i18n import _
from mailman.interfaces.command import ICLISubCommand
from zope.interface import implementer
-
+@public
@implementer(ICLISubCommand)
class Status:
"""Status of the Mailman system."""
@@ -51,10 +47,10 @@ class Status:
message = _('GNU Mailman is running (master pid: $pid)')
elif status is WatcherState.stale_lock:
hostname, pid, tempfile = lock.details
- message =_('GNU Mailman is stopped (stale pid: $pid)')
+ message = _('GNU Mailman is stopped (stale pid: $pid)')
else:
hostname, pid, tempfile = lock.details
- fqdn_name = socket.getfqdn()
+ fqdn_name = socket.getfqdn() # flake8: noqa
assert status is WatcherState.host_mismatch, (
'Invalid enum value: %s' % status)
message = _('GNU Mailman is in an unexpected state '
diff --git a/src/mailman/commands/cli_unshunt.py b/src/mailman/commands/cli_unshunt.py
index 59fdd03d6..6bb1a9800 100644
--- a/src/mailman/commands/cli_unshunt.py
+++ b/src/mailman/commands/cli_unshunt.py
@@ -17,20 +17,16 @@
"""The 'unshunt' command."""
-__all__ = [
- 'Unshunt',
- ]
-
-
import sys
+from mailman import public
from mailman.config import config
from mailman.core.i18n import _
from mailman.interfaces.command import ICLISubCommand
from zope.interface import implementer
-
+@public
@implementer(ICLISubCommand)
class Unshunt:
"""Unshunt messages."""
diff --git a/src/mailman/commands/cli_version.py b/src/mailman/commands/cli_version.py
index 6f2b1cd9a..4660087de 100644
--- a/src/mailman/commands/cli_version.py
+++ b/src/mailman/commands/cli_version.py
@@ -17,17 +17,13 @@
"""The Mailman version."""
-__all__ = [
- 'Version',
- ]
-
-
+from mailman import public
from mailman.interfaces.command import ICLISubCommand
from mailman.version import MAILMAN_VERSION_FULL
from zope.interface import implementer
-
+@public
@implementer(ICLISubCommand)
class Version:
"""Mailman's version."""
diff --git a/src/mailman/commands/cli_withlist.py b/src/mailman/commands/cli_withlist.py
index 6c8579d81..e7329f4e7 100644
--- a/src/mailman/commands/cli_withlist.py
+++ b/src/mailman/commands/cli_withlist.py
@@ -17,16 +17,11 @@
"""The `mailman shell` subcommand."""
-__all__ = [
- 'Shell',
- 'Withlist',
- ]
-
-
import re
import sys
from lazr.config import as_boolean
+from mailman import public
from mailman.config import config
from mailman.core.i18n import _
from mailman.interfaces.command import ICLISubCommand
@@ -43,7 +38,7 @@ m = None
r = None
-
+@public
@implementer(ICLISubCommand)
class Withlist:
"""Operate on a mailing list.
@@ -164,7 +159,7 @@ class Withlist:
def _start_python(self, overrides, banner):
# Set the tab completion.
try:
- import readline, rlcompleter
+ import readline, rlcompleter # flake8: noqa
readline.parse_and_bind('tab: complete')
except ImportError:
pass
@@ -235,7 +230,7 @@ and run this from the command line:
% mailman withlist -r change mylist@example.com 'My List'"""))
-
+@public
class Shell(Withlist):
"""An alias for `withlist`."""
diff --git a/src/mailman/commands/eml_confirm.py b/src/mailman/commands/eml_confirm.py
index 0726ae212..6a3e389bd 100644
--- a/src/mailman/commands/eml_confirm.py
+++ b/src/mailman/commands/eml_confirm.py
@@ -17,11 +17,7 @@
"""The 'confirm' email command."""
-__all__ = [
- 'Confirm',
- ]
-
-
+from mailman import public
from mailman.core.i18n import _
from mailman.interfaces.command import ContinueProcessing, IEmailCommand
from mailman.interfaces.registrar import IRegistrar
@@ -29,7 +25,7 @@ from mailman.interfaces.subscriptions import TokenOwner
from zope.interface import implementer
-
+@public
@implementer(IEmailCommand)
class Confirm:
"""The email 'confirm' command."""
diff --git a/src/mailman/commands/eml_echo.py b/src/mailman/commands/eml_echo.py
index eecfca643..67f917d3e 100644
--- a/src/mailman/commands/eml_echo.py
+++ b/src/mailman/commands/eml_echo.py
@@ -17,11 +17,7 @@
"""The email command 'echo'."""
-__all__ = [
- 'Echo',
- ]
-
-
+from mailman import public
from mailman.core.i18n import _
from mailman.interfaces.command import ContinueProcessing, IEmailCommand
from zope.interface import implementer
@@ -30,7 +26,7 @@ from zope.interface import implementer
SPACE = ' '
-
+@public
@implementer(IEmailCommand)
class Echo:
"""The email 'echo' command."""
diff --git a/src/mailman/commands/eml_end.py b/src/mailman/commands/eml_end.py
index 1e14a262d..82b66a1a6 100644
--- a/src/mailman/commands/eml_end.py
+++ b/src/mailman/commands/eml_end.py
@@ -17,18 +17,13 @@
"""The email commands 'end' and 'stop'."""
-__all__ = [
- 'End',
- 'Stop',
- ]
-
-
+from mailman import public
from mailman.core.i18n import _
from mailman.interfaces.command import ContinueProcessing, IEmailCommand
from zope.interface import implementer
-
+@public
@implementer(IEmailCommand)
class End:
"""The email 'end' command."""
@@ -44,6 +39,7 @@ class End:
return ContinueProcessing.no
+@public
class Stop(End):
"""The email 'stop' command (an alias for 'end')."""
diff --git a/src/mailman/commands/eml_help.py b/src/mailman/commands/eml_help.py
index 12599b161..8df4c666a 100644
--- a/src/mailman/commands/eml_help.py
+++ b/src/mailman/commands/eml_help.py
@@ -17,11 +17,7 @@
"""The email command 'help'."""
-__all__ = [
- 'Help',
- ]
-
-
+from mailman import public
from mailman.config import config
from mailman.core.i18n import _
from mailman.interfaces.command import ContinueProcessing, IEmailCommand
@@ -32,7 +28,7 @@ from zope.interface import implementer
SPACE = ' '
-
+@public
@implementer(IEmailCommand)
class Help:
"""The email 'help' command."""
@@ -63,14 +59,14 @@ class Help:
print(_('$self.name: no such command: $command_name'),
file=results)
return ContinueProcessing.no
- print('{0} {1}'.format(command.name, command.argument_description),
+ print('{} {}'.format(command.name, command.argument_description),
file=results)
print(command.short_description, file=results)
if command.short_description != command.description:
print(wrap(command.description), file=results)
return ContinueProcessing.yes
else:
- printable_arguments = SPACE.join(arguments)
+ printable_arguments = SPACE.join(arguments) # flake8: noqa
print(_('$self.name: too many arguments: $printable_arguments'),
file=results)
return ContinueProcessing.no
diff --git a/src/mailman/commands/eml_membership.py b/src/mailman/commands/eml_membership.py
index 49af269e4..4f8e62a69 100644
--- a/src/mailman/commands/eml_membership.py
+++ b/src/mailman/commands/eml_membership.py
@@ -17,15 +17,8 @@
"""The email commands 'join' and 'subscribe'."""
-__all__ = [
- 'Join',
- 'Subscribe',
- 'Leave',
- 'Unsubscribe',
- ]
-
-
from email.utils import formataddr, parseaddr
+from mailman import public
from mailman.core.i18n import _
from mailman.interfaces.command import ContinueProcessing, IEmailCommand
from mailman.interfaces.member import DeliveryMode, MemberRole
@@ -36,7 +29,6 @@ from zope.component import getUtility
from zope.interface import implementer
-
def match_subscriber(email, display_name):
# Return something matching the email which should be used as the
# subscriber by the IRegistrar interface.
@@ -58,7 +50,7 @@ def match_subscriber(email, display_name):
return list(user.addresses)[0]
-
+@public
@implementer(IEmailCommand)
class Join:
"""The email 'join' command."""
@@ -100,7 +92,7 @@ used.
return ContinueProcessing.yes
joins.add(email)
results.joins = joins
- person = formataddr((display_name, email))
+ person = formataddr((display_name, email)) # flake8: noqa
# Is this person already a member of the list? Search for all
# matching memberships.
members = getUtility(ISubscriptionService).find_members(
@@ -140,7 +132,7 @@ used.
return mode
-
+@public
class Subscribe(Join):
"""The email 'subscribe' command (an alias for 'join')."""
@@ -149,7 +141,7 @@ class Subscribe(Join):
short_description = description
-
+@public
@implementer(IEmailCommand)
class Leave:
"""The email 'leave' command."""
@@ -195,12 +187,12 @@ You may be asked to confirm your request.""")
file=results)
return ContinueProcessing.no
member.unsubscribe()
- person = formataddr((user.display_name, email))
+ person = formataddr((user.display_name, email)) # flake8: noqa
print(_('$person left $mlist.fqdn_listname'), file=results)
return ContinueProcessing.yes
-
+@public
class Unsubscribe(Leave):
"""The email 'unsubscribe' command (an alias for 'leave')."""
diff --git a/src/mailman/commands/tests/test_conf.py b/src/mailman/commands/tests/test_conf.py
index 2fae55f17..745d4bda3 100644
--- a/src/mailman/commands/tests/test_conf.py
+++ b/src/mailman/commands/tests/test_conf.py
@@ -17,11 +17,6 @@
"""Test the conf subcommand."""
-__all__ = [
- 'TestConf',
- ]
-
-
import os
import sys
import tempfile
@@ -33,7 +28,6 @@ from mailman.testing.layers import ConfigLayer
from unittest import mock
-
class FakeArgs:
section = None
key = None
@@ -50,7 +44,6 @@ class FakeParser:
sys.exit(1)
-
class TestConf(unittest.TestCase):
"""Test the conf subcommand."""
diff --git a/src/mailman/commands/tests/test_confirm.py b/src/mailman/commands/tests/test_confirm.py
index 5f62331c0..7cce4c3c7 100644
--- a/src/mailman/commands/tests/test_confirm.py
+++ b/src/mailman/commands/tests/test_confirm.py
@@ -17,12 +17,6 @@
"""Test the `confirm` command."""
-__all__ = [
- 'TestConfirm',
- 'TestEmailResponses',
- ]
-
-
import unittest
from mailman.app.lifecycle import create_list
@@ -39,7 +33,6 @@ from mailman.testing.layers import ConfigLayer
from zope.component import getUtility
-
class TestConfirm(unittest.TestCase):
"""Test the `confirm` command."""
@@ -62,10 +55,9 @@ class TestConfirm(unittest.TestCase):
self._mlist, Message(), {}, (self._token,), Results())
self.assertEqual(status, ContinueProcessing.yes)
# There should be one messages in the queue; the welcome message.
- messages = get_queue_messages('virgin')
- self.assertEqual(len(messages), 1)
+ items = get_queue_messages('virgin', expected_count=1)
# Grab the welcome message.
- welcome = messages[0].msg
+ welcome = items[0].msg
self.assertEqual(welcome['subject'],
'Welcome to the "Test" mailing list')
self.assertEqual(welcome['to'], 'Anne Person <anne@example.com>')
@@ -77,8 +69,7 @@ class TestConfirm(unittest.TestCase):
self._mlist, Message(), {}, (self._token,), Results())
self.assertEqual(status, ContinueProcessing.yes)
# There will be no messages in the queue.
- messages = get_queue_messages('virgin')
- self.assertEqual(len(messages), 0)
+ get_queue_messages('virgin', expected_count=0)
class TestEmailResponses(unittest.TestCase):
@@ -91,8 +82,8 @@ class TestEmailResponses(unittest.TestCase):
def test_confirm_then_moderate_workflow(self):
# Issue #114 describes a problem when confirming the moderation email.
- self._mlist.subscription_policy = \
- SubscriptionPolicy.confirm_then_moderate
+ self._mlist.subscription_policy = (
+ SubscriptionPolicy.confirm_then_moderate)
bart = getUtility(IUserManager).create_address(
'bart@example.com', 'Bart Person')
# Clear any previously queued confirmation messages.
@@ -101,8 +92,7 @@ class TestEmailResponses(unittest.TestCase):
bart)
# There should now be one email message in the virgin queue, i.e. the
# confirmation message sent to Bart.
- items = get_queue_messages('virgin')
- self.assertEqual(len(items), 1)
+ items = get_queue_messages('virgin', expected_count=1)
msg = items[0].msg
# Confirmations come first, so this one goes to the subscriber.
self.assertEqual(msg['to'], 'bart@example.com')
@@ -123,8 +113,7 @@ class TestEmailResponses(unittest.TestCase):
# subscriber containing the results of their confirmation message, and
# the other is to the moderators informing them that they need to
# handle the moderation queue.
- items = get_queue_messages('virgin')
- self.assertEqual(len(items), 2)
+ items = get_queue_messages('virgin', expected_count=2)
if items[0].msg['to'] == 'bart@example.com':
results = items[0].msg
moderator_msg = items[1].msg
diff --git a/src/mailman/commands/tests/test_control.py b/src/mailman/commands/tests/test_control.py
index 58702c70e..b25c63185 100644
--- a/src/mailman/commands/tests/test_control.py
+++ b/src/mailman/commands/tests/test_control.py
@@ -17,14 +17,6 @@
"""Test some additional corner cases for starting/stopping."""
-__all__ = [
- 'TestBinDir',
- 'TestStart',
- 'find_master',
- 'make_config',
- ]
-
-
import os
import sys
import time
@@ -34,7 +26,7 @@ import shutil
import socket
import unittest
-from contextlib import ExitStack
+from contextlib import ExitStack, suppress
from datetime import timedelta, datetime
from mailman.commands.cli_control import Start, kill_watcher
from mailman.config import Configuration, config
@@ -46,7 +38,6 @@ from tempfile import TemporaryDirectory
SEP = '|'
-
def make_config():
# All we care about is the master process; normally it starts a bunch of
# runners, but we don't care about any of them, so write a test
@@ -56,7 +47,7 @@ def make_config():
shutil.copyfile(config.filename, config_file)
with open(config_file, 'a') as fp:
for runner_config in config.runner_configs:
- print('[{0}]\nstart:no\n'.format(runner_config.name), file=fp)
+ print('[{}]\nstart:no\n'.format(runner_config.name), file=fp)
return config_file
@@ -83,7 +74,6 @@ def find_master():
return None
-
class FakeArgs:
force = None
run_as_user = None
@@ -100,7 +90,6 @@ class FakeParser:
sys.exit(1)
-
class TestStart(unittest.TestCase):
"""Test various starting scenarios."""
@@ -152,20 +141,17 @@ class TestStart(unittest.TestCase):
t = time.mktime(expiration_date.timetuple())
os.utime(claim_file, (t, t))
# Start without --force; no master will be running.
- try:
+ with suppress(SystemExit):
self.command.process(self.args)
- except SystemExit:
- pass
- self.assertEqual(find_master(), None)
- self.assertTrue('--force' in self.command.parser.message)
+ self.assertIsNone(find_master())
+ self.assertIn('--force', self.command.parser.message)
# Start again, this time with --force.
self.args.force = True
self.command.process(self.args)
pid = find_master()
- self.assertNotEqual(pid, None)
+ self.assertIsNotNone(pid)
-
class TestBinDir(unittest.TestCase):
"""Test issues related to bin_dir, e.g. issue #3"""
diff --git a/src/mailman/commands/tests/test_create.py b/src/mailman/commands/tests/test_create.py
index 97a8d895e..392dbdbb2 100644
--- a/src/mailman/commands/tests/test_create.py
+++ b/src/mailman/commands/tests/test_create.py
@@ -17,21 +17,16 @@
"""Test the `mailman create` subcommand."""
-__all__ = [
- 'TestCreate',
- ]
-
-
import sys
import unittest
from argparse import ArgumentParser
+from contextlib import suppress
from mailman.app.lifecycle import create_list
from mailman.commands.cli_lists import Create
from mailman.testing.layers import ConfigLayer
-
class FakeArgs:
language = None
owners = []
@@ -50,7 +45,6 @@ class FakeParser:
sys.exit(1)
-
class TestCreate(unittest.TestCase):
layer = ConfigLayer
@@ -63,20 +57,16 @@ class TestCreate(unittest.TestCase):
# Cannot create a mailing list if it already exists.
create_list('test@example.com')
self.args.listname = ['test@example.com']
- try:
+ with suppress(SystemExit):
self.command.process(self.args)
- except SystemExit:
- pass
self.assertEqual(self.command.parser.message,
'List already exists: test@example.com')
def test_invalid_posting_address(self):
# Cannot create a mailing list with an invalid posting address.
self.args.listname = ['foo']
- try:
+ with suppress(SystemExit):
self.command.process(self.args)
- except SystemExit:
- pass
self.assertEqual(self.command.parser.message,
'Illegal list name: foo')
@@ -84,10 +74,8 @@ class TestCreate(unittest.TestCase):
# Cannot create a list with invalid owner addresses. LP: #778687
self.args.listname = ['test@example.com']
self.args.owners = ['main=True']
- try:
+ with suppress(SystemExit):
self.command.process(self.args)
- except SystemExit:
- pass
self.assertEqual(self.command.parser.message,
'Illegal owner addresses: main=True')
diff --git a/src/mailman/commands/tests/test_digests.py b/src/mailman/commands/tests/test_digests.py
index 2fe59dc57..b14820cbd 100644
--- a/src/mailman/commands/tests/test_digests.py
+++ b/src/mailman/commands/tests/test_digests.py
@@ -17,12 +17,6 @@
"""Test the send-digests subcommand."""
-__all__ = [
- 'TestBumpVolume',
- 'TestSendDigests',
- ]
-
-
import os
import unittest
@@ -42,7 +36,6 @@ from mailman.utilities.datetime import now as right_now
from unittest.mock import patch
-
class FakeArgs:
def __init__(self):
self.lists = []
@@ -50,7 +43,6 @@ class FakeArgs:
self.bump = False
-
class TestSendDigests(unittest.TestCase):
layer = ConfigLayer
@@ -79,8 +71,7 @@ Subject: message 1
self._handler.process(self._mlist, msg, {})
# There are no digests already being sent, but the ant mailing list
# does have a digest mbox collecting messages.
- items = get_queue_messages('digest')
- self.assertEqual(len(items), 0)
+ get_queue_messages('digest', expected_count=0)
mailbox_path = os.path.join(self._mlist.data_path, 'digest.mmdf')
self.assertGreater(os.path.getsize(mailbox_path), 0)
args = FakeArgs()
@@ -91,8 +82,7 @@ Subject: message 1
# Now, there's no digest mbox and there's a plaintext digest in the
# outgoing queue.
self.assertFalse(os.path.exists(mailbox_path))
- items = get_queue_messages('virgin')
- self.assertEqual(len(items), 1)
+ items = get_queue_messages('virgin', expected_count=1)
digest_contents = str(items[0].msg)
self.assertIn('Subject: message 1', digest_contents)
self.assertIn('Subject: message 2', digest_contents)
@@ -110,8 +100,7 @@ Subject: message 1
self._handler.process(self._mlist, msg, {})
# There are no digests already being sent, but the ant mailing list
# does have a digest mbox collecting messages.
- items = get_queue_messages('digest')
- self.assertEqual(len(items), 0)
+ get_queue_messages('digest', expected_count=0)
mailbox_path = os.path.join(self._mlist.data_path, 'digest.mmdf')
self.assertGreater(os.path.getsize(mailbox_path), 0)
args = FakeArgs()
@@ -122,8 +111,7 @@ Subject: message 1
# Now, there's no digest mbox and there's a plaintext digest in the
# outgoing queue.
self.assertFalse(os.path.exists(mailbox_path))
- items = get_queue_messages('virgin')
- self.assertEqual(len(items), 1)
+ items = get_queue_messages('virgin', expected_count=1)
digest_contents = str(items[0].msg)
self.assertIn('Subject: message 1', digest_contents)
self.assertIn('Subject: message 2', digest_contents)
@@ -141,8 +129,7 @@ Subject: message 1
self._handler.process(self._mlist, msg, {})
# There are no digests already being sent, but the ant mailing list
# does have a digest mbox collecting messages.
- items = get_queue_messages('digest')
- self.assertEqual(len(items), 0)
+ get_queue_messages('digest', expected_count=0)
mailbox_path = os.path.join(self._mlist.data_path, 'digest.mmdf')
self.assertGreater(os.path.getsize(mailbox_path), 0)
args = FakeArgs()
@@ -157,8 +144,7 @@ Subject: message 1
'No such list found: bee.example.com\n')
# And no digest was prepared.
self.assertGreater(os.path.getsize(mailbox_path), 0)
- items = get_queue_messages('virgin')
- self.assertEqual(len(items), 0)
+ get_queue_messages('virgin', expected_count=0)
def test_send_one_digest_to_missing_fqdn_listname(self):
msg = mfs("""\
@@ -173,8 +159,7 @@ Subject: message 1
self._handler.process(self._mlist, msg, {})
# There are no digests already being sent, but the ant mailing list
# does have a digest mbox collecting messages.
- items = get_queue_messages('digest')
- self.assertEqual(len(items), 0)
+ get_queue_messages('digest', expected_count=0)
mailbox_path = os.path.join(self._mlist.data_path, 'digest.mmdf')
self.assertGreater(os.path.getsize(mailbox_path), 0)
args = FakeArgs()
@@ -189,8 +174,7 @@ Subject: message 1
'No such list found: bee@example.com\n')
# And no digest was prepared.
self.assertGreater(os.path.getsize(mailbox_path), 0)
- items = get_queue_messages('virgin')
- self.assertEqual(len(items), 0)
+ get_queue_messages('virgin', expected_count=0)
def test_send_digest_to_one_missing_and_one_existing_list(self):
msg = mfs("""\
@@ -205,8 +189,7 @@ Subject: message 1
self._handler.process(self._mlist, msg, {})
# There are no digests already being sent, but the ant mailing list
# does have a digest mbox collecting messages.
- items = get_queue_messages('digest')
- self.assertEqual(len(items), 0)
+ get_queue_messages('digest', expected_count=0)
mailbox_path = os.path.join(self._mlist.data_path, 'digest.mmdf')
self.assertGreater(os.path.getsize(mailbox_path), 0)
args = FakeArgs()
@@ -221,8 +204,7 @@ Subject: message 1
'No such list found: bee.example.com\n')
# But ant's digest was still prepared.
self.assertFalse(os.path.exists(mailbox_path))
- items = get_queue_messages('virgin')
- self.assertEqual(len(items), 1)
+ items = get_queue_messages('virgin', expected_count=1)
digest_contents = str(items[0].msg)
self.assertIn('Subject: message 1', digest_contents)
self.assertIn('Subject: message 2', digest_contents)
@@ -265,8 +247,7 @@ Subject: message 3
bee_mailbox_path = os.path.join(bee.data_path, 'digest.mmdf')
self.assertGreater(os.path.getsize(bee_mailbox_path), 0)
# Both.
- items = get_queue_messages('digest')
- self.assertEqual(len(items), 0)
+ get_queue_messages('digest', expected_count=0)
# Process both list's digests.
args = FakeArgs()
args.send = True
@@ -277,8 +258,7 @@ Subject: message 3
# digest in the outgoing queue for both.
self.assertFalse(os.path.exists(ant_mailbox_path))
self.assertFalse(os.path.exists(bee_mailbox_path))
- items = get_queue_messages('virgin')
- self.assertEqual(len(items), 2)
+ items = get_queue_messages('virgin', expected_count=2)
# Figure out which digest is going to ant and which to bee.
if items[0].msg['to'] == 'ant@example.com':
ant = items[0].msg
@@ -334,8 +314,7 @@ Subject: message 3
bee_mailbox_path = os.path.join(bee.data_path, 'digest.mmdf')
self.assertGreater(os.path.getsize(bee_mailbox_path), 0)
# Both.
- items = get_queue_messages('digest')
- self.assertEqual(len(items), 0)
+ get_queue_messages('digest', expected_count=0)
# Process all mailing list digests by not setting any arguments.
args = FakeArgs()
args.send = True
@@ -345,8 +324,7 @@ Subject: message 3
# digest in the outgoing queue for both.
self.assertFalse(os.path.exists(ant_mailbox_path))
self.assertFalse(os.path.exists(bee_mailbox_path))
- items = get_queue_messages('virgin')
- self.assertEqual(len(items), 2)
+ items = get_queue_messages('virgin', expected_count=2)
# Figure out which digest is going to ant and which to bee.
if items[0].msg['to'] == 'ant@example.com':
ant = items[0].msg
@@ -374,8 +352,7 @@ Subject: message 3
args.lists.append('ant.example.com')
self._command.process(args)
self._runner.run()
- items = get_queue_messages('virgin')
- self.assertEqual(len(items), 0)
+ get_queue_messages('virgin', expected_count=0)
def test_bump_before_send(self):
self._mlist.digest_volume_frequency = DigestFrequency.monthly
@@ -401,12 +378,10 @@ Subject: message 1
self.assertEqual(self._mlist.volume, 8)
self.assertEqual(self._mlist.next_digest_number, 2)
self.assertEqual(self._mlist.digest_last_sent_at, right_now())
- items = get_queue_messages('virgin')
- self.assertEqual(len(items), 1)
+ items = get_queue_messages('virgin', expected_count=1)
self.assertEqual(items[0].msg['subject'], 'Ant Digest, Vol 8, Issue 1')
-
class TestBumpVolume(unittest.TestCase):
layer = ConfigLayer
diff --git a/src/mailman/commands/tests/test_help.py b/src/mailman/commands/tests/test_help.py
index 2155b21cd..a45fc7c6c 100644
--- a/src/mailman/commands/tests/test_help.py
+++ b/src/mailman/commands/tests/test_help.py
@@ -17,11 +17,6 @@
"""Additional tests for the `help` email command."""
-__all__ = [
- 'TestHelp',
- ]
-
-
import unittest
from mailman.app.lifecycle import create_list
@@ -32,7 +27,6 @@ from mailman.runners.command import Results
from mailman.testing.layers import ConfigLayer
-
class TestHelp(unittest.TestCase):
"""Test email help."""
diff --git a/src/mailman/commands/tests/test_import.py b/src/mailman/commands/tests/test_import.py
index 59992c07b..32f6c4df9 100644
--- a/src/mailman/commands/tests/test_import.py
+++ b/src/mailman/commands/tests/test_import.py
@@ -17,11 +17,6 @@
"""Test the `mailman import21` subcommand."""
-__all__ = [
- 'TestImport',
- ]
-
-
import unittest
from mailman.app.lifecycle import create_list
@@ -31,7 +26,6 @@ from pkg_resources import resource_filename
from unittest.mock import patch
-
class FakeArgs:
listname = ['test@example.com']
pickle_file = [
@@ -39,7 +33,6 @@ class FakeArgs:
]
-
class TestImport(unittest.TestCase):
layer = ConfigLayer
diff --git a/src/mailman/commands/tests/test_lists.py b/src/mailman/commands/tests/test_lists.py
index d7cb2ce66..392e3f36e 100644
--- a/src/mailman/commands/tests/test_lists.py
+++ b/src/mailman/commands/tests/test_lists.py
@@ -17,11 +17,6 @@
"""Additional tests for the `lists` command line subcommand."""
-__all__ = [
- 'TestLists',
- ]
-
-
import unittest
from io import StringIO
diff --git a/src/mailman/commands/tests/test_members.py b/src/mailman/commands/tests/test_members.py
index 1ef9037b0..7f90da20b 100644
--- a/src/mailman/commands/tests/test_members.py
+++ b/src/mailman/commands/tests/test_members.py
@@ -17,11 +17,6 @@
"""Test the `mailman members` command."""
-__all__ = [
- 'TestCLIMembers',
- ]
-
-
import sys
import unittest
@@ -36,7 +31,6 @@ from tempfile import NamedTemporaryFile
from unittest.mock import patch
-
class FakeArgs:
input_filename = None
output_filename = None
@@ -56,7 +50,6 @@ class FakeParser:
sys.exit(1)
-
class TestCLIMembers(unittest.TestCase):
layer = ConfigLayer