diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/config/__init__.py | 6 | ||||
| -rw-r--r-- | src/mailman/config/config.py | 46 | ||||
| -rw-r--r-- | src/mailman/config/tests/test_archivers.py | 6 | ||||
| -rw-r--r-- | src/mailman/config/tests/test_configuration.py | 60 |
4 files changed, 40 insertions, 78 deletions
diff --git a/src/mailman/config/__init__.py b/src/mailman/config/__init__.py index e5ceaa03a..7711fba09 100644 --- a/src/mailman/config/__init__.py +++ b/src/mailman/config/__init__.py @@ -17,11 +17,7 @@ """Mailman configuration package.""" -__all__ = [ - 'config', - ] - - from mailman.config.config import Configuration config = Configuration() +__all__ = ['config'] diff --git a/src/mailman/config/config.py b/src/mailman/config/config.py index 424ad03c0..415e1e3d2 100644 --- a/src/mailman/config/config.py +++ b/src/mailman/config/config.py @@ -17,13 +17,6 @@ """Configuration file loading and management.""" -__all__ = [ - 'Configuration', - 'external_configuration', - 'load_external' - ] - - import os import sys import mailman.templates @@ -31,7 +24,7 @@ import mailman.templates from configparser import ConfigParser from flufl.lock import Lock from lazr.config import ConfigSchema, as_boolean -from mailman import version +from mailman import public, version from mailman.interfaces.configuration import ( ConfigurationUpdatedEvent, IConfiguration, MissingConfigurationFileError) from mailman.interfaces.languages import ILanguageManager @@ -47,7 +40,6 @@ from zope.interface import implementer SPACE = ' ' SPACERS = '\n' - MAILMAN_CFG_TEMPLATE = """\ # AUTOMATICALLY GENERATED BY MAILMAN ON {} # @@ -64,7 +56,7 @@ MAILMAN_CFG_TEMPLATE = """\ # recipient: your.address@your.domain""" - +@public @implementer(IConfiguration) class Configuration: """The core global configuration object.""" @@ -155,28 +147,23 @@ class Configuration: # relative. var_dir = os.environ.get('MAILMAN_VAR_DIR', category.var_dir) substitutions = dict( - cwd = os.getcwd(), - argv = default_bin_dir, - # Directories. - bin_dir = category.bin_dir, - data_dir = category.data_dir, - etc_dir = category.etc_dir, - ext_dir = category.ext_dir, - list_data_dir = category.list_data_dir, - lock_dir = category.lock_dir, - log_dir = category.log_dir, - messages_dir = category.messages_dir, - archive_dir = category.archive_dir, - queue_dir = category.queue_dir, - var_dir = var_dir, - template_dir = ( + cwd=os.getcwd(), + argv=default_bin_dir, + var_dir=var_dir, + template_dir=( os.path.dirname(mailman.templates.__file__) if category.template_dir == ':source:' else category.template_dir), - # Files. - lock_file = category.lock_file, - pid_file = category.pid_file, ) + # Directories. + for name in ('archive', 'bin', 'data', 'etc', 'ext', 'list_data', + 'lock', 'log', 'messages', 'queue'): + key = '{}_dir'.format(name) + substitutions[key] = getattr(category, key) + # Files. + for name in ('lock', 'pid'): + key = '{}_file'.format(name) + substitutions[key] = getattr(category, key) # Add the path to the .cfg file, if one was given on the command line. if self.filename is not None: substitutions['cfg_file'] = self.filename @@ -264,7 +251,7 @@ class Configuration: yield from self._config.getByCategory('language', []) - +@public def load_external(path): """Load the configuration file named by path. @@ -286,6 +273,7 @@ def load_external(path): return fp.read() +@public def external_configuration(path): """Parse the configuration file named by path. diff --git a/src/mailman/config/tests/test_archivers.py b/src/mailman/config/tests/test_archivers.py index d5a8e5b77..322a5040d 100644 --- a/src/mailman/config/tests/test_archivers.py +++ b/src/mailman/config/tests/test_archivers.py @@ -17,11 +17,6 @@ """Site-wide archiver configuration tests.""" -__all__ = [ - 'TestArchivers', - ] - - import unittest from mailman.config import config @@ -29,7 +24,6 @@ from mailman.testing.helpers import configuration from mailman.testing.layers import ConfigLayer - class TestArchivers(unittest.TestCase): layer = ConfigLayer diff --git a/src/mailman/config/tests/test_configuration.py b/src/mailman/config/tests/test_configuration.py index abbfce2c2..a969ce586 100644 --- a/src/mailman/config/tests/test_configuration.py +++ b/src/mailman/config/tests/test_configuration.py @@ -17,15 +17,7 @@ """Test the system-wide global configuration.""" -__all__ = [ - 'TestConfiguration', - 'TestConfigurationErrors', - 'TestExternal', - ] - - import os -import tempfile import unittest from contextlib import ExitStack @@ -36,10 +28,10 @@ from mailman.interfaces.configuration import ( from mailman.testing.helpers import configuration, event_subscribers from mailman.testing.layers import ConfigLayer from pkg_resources import resource_filename +from tempfile import NamedTemporaryFile from unittest import mock - class TestConfiguration(unittest.TestCase): layer = ConfigLayer @@ -47,7 +39,7 @@ class TestConfiguration(unittest.TestCase): # Pushing a new configuration onto the stack triggers a # post-processing event. events = [] - def on_event(event): + def on_event(event): # flake8: noqa if isinstance(event, ConfigurationUpdatedEvent): # Record both the event and the top overlay. events.append(event.config.overlays[0].name) @@ -59,22 +51,19 @@ class TestConfiguration(unittest.TestCase): self.assertEqual(events, ['first', 'second', 'first']) def test_config_template_dir_is_source(self): - fd, filename = tempfile.mkstemp() - self.addCleanup(os.remove, filename) - os.close(fd) - with open(filename, 'w') as fp: + config = Configuration() + with NamedTemporaryFile('w', encoding='utf-8') as fp: print("""\ [paths.here] template_dir: :source: """, file=fp) - config = Configuration() - config.load(filename) + fp.flush() + config.load(fp.name) import mailman.templates self.assertEqual(config.TEMPLATE_DIR, os.path.dirname(mailman.templates.__file__)) - class TestExternal(unittest.TestCase): """Test external configuration file loading APIs.""" @@ -104,49 +93,44 @@ class TestExternal(unittest.TestCase): self.assertEqual(cm.exception.path, 'path:mailman.config.missing') - class TestConfigurationErrors(unittest.TestCase): layer = ConfigLayer def test_bad_path_layout_specifier(self): # Using a [mailman]layout name that doesn't exist is a fatal error. - fd, filename = tempfile.mkstemp() - self.addCleanup(os.remove, filename) - os.close(fd) - with open(filename, 'w') as fp: + config = Configuration() + with ExitStack() as resources: + fp = resources.enter_context( + NamedTemporaryFile('w', encoding='utf-8')) print("""\ [mailman] layout: nonesuch """, file=fp) - # Use a fake sys.exit() function that records that it was called, and - # that prevents further processing. - config = Configuration() - # Suppress warning messages in the test output. Also, make sure that - # the config.load() call doesn't break global state. - with ExitStack() as resources: + fp.flush() + # Suppress warning messages in the test output. Also, make sure + # that the config.load() call doesn't break global state. resources.enter_context(mock.patch('sys.stderr')) resources.enter_context(mock.patch.object(config, '_clear')) cm = resources.enter_context(self.assertRaises(SystemExit)) - config.load(filename) + config.load(fp.name) self.assertEqual(cm.exception.args, (1,)) def test_path_expansion_infloop(self): # A path expansion never completes because it references a non-existent # substitution variable. - fd, filename = tempfile.mkstemp() - self.addCleanup(os.remove, filename) - os.close(fd) - with open(filename, 'w') as fp: + config = Configuration() + with ExitStack() as resources: + fp = resources.enter_context( + NamedTemporaryFile('w', encoding='utf-8')) print("""\ [paths.here] log_dir: $nopath/log_dir """, file=fp) - config = Configuration() - # Suppress warning messages in the test output. Also, make sure that - # the config.load() call doesn't break global state. - with ExitStack() as resources: + fp.flush() + # Suppress warning messages in the test output. Also, make sure + # that the config.load() call doesn't break global state. resources.enter_context(mock.patch('sys.stderr')) resources.enter_context(mock.patch.object(config, '_clear')) cm = resources.enter_context(self.assertRaises(SystemExit)) - config.load(filename) + config.load(fp.name) self.assertEqual(cm.exception.args, (1,)) |
