Barry Warsaw pushed to branch master at mailman / Mailman
Commits:
e61e9b73 by Barry Warsaw at 2016-05-01T16:53:16-04:00
A better solution to the test creating a var dir.
Instead of shutil.rmtree'ing the create var directory, prevent it from
happening altogether. This way we won't accidentally blow away a live
one created for operational purposes.
- - - - -
dd659b75 by Barry Warsaw at 2016-05-01T17:10:43-04:00
Replace another rmtree() with a better solution.
- - - - -
3 changed files:
- src/mailman/config/tests/test_configuration.py
- src/mailman/docs/CONTRIBUTE.rst
- src/mailman/testing/layers.py
Changes:
=====================================
src/mailman/config/tests/test_configuration.py
=====================================
--- a/src/mailman/config/tests/test_configuration.py
+++ b/src/mailman/config/tests/test_configuration.py
@@ -18,7 +18,6 @@
"""Test the system-wide global configuration."""
import os
-import shutil
import unittest
from contextlib import ExitStack
@@ -29,7 +28,7 @@ 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 tempfile import NamedTemporaryFile, TemporaryDirectory
from unittest import mock
@@ -54,13 +53,18 @@ class TestConfiguration(unittest.TestCase):
def test_config_template_dir_is_source(self):
# This test will leave a 'var' directory in the top-level source
# directory. Be sure to clean it up.
- self.addCleanup(shutil.rmtree, 'var')
config = Configuration()
- with NamedTemporaryFile('w', encoding='utf-8') as fp:
+ with ExitStack() as resources:
+ fp = resources.enter_context(
+ NamedTemporaryFile('w', encoding='utf-8'))
+ var_dir = resources.enter_context(TemporaryDirectory())
+ # Don't let the post-processing after the config.load() to put a
+ # 'var' directory in the source tree's top level directory.
print("""\
[paths.here]
template_dir: :source:
-""", file=fp)
+var_dir: {}
+""".format(var_dir), file=fp)
fp.flush()
config.load(fp.name)
import mailman.templates
=====================================
src/mailman/docs/CONTRIBUTE.rst
=====================================
--- a/src/mailman/docs/CONTRIBUTE.rst
+++ b/src/mailman/docs/CONTRIBUTE.rst
@@ -174,8 +174,7 @@ defines these basic overrides in
``src/mailman/config/mailman.cfg``. Your own
configuration file will override those.
By default, all runtime files are put under a ``var`` directory in the current
-working directory. **Be careful though because running the test suite will
-blow this directory away.**
+working directory.
Mailman searches for its configuration file using the following search path.
The first existing file found wins.
=====================================
src/mailman/testing/layers.py
=====================================
--- a/src/mailman/testing/layers.py
+++ b/src/mailman/testing/layers.py
@@ -185,11 +185,15 @@ class ConfigLayer(MockAndMonkeyLayer):
# no data in case the tests are rerun with a database layer like mysql
# or postgresql which are not deleted in teardown.
shutil.rmtree(cls.var_dir)
+ # Prevent the bit of post-processing on the .pop() that creates
+ # directories. We're basically shutting down everything and we don't
+ # need the directories created. Plus, doing so leaves a var directory
+ # turd in the source tree's top-level directory. We do it this way
+ # rather than shutil.rmtree'ing the resulting var directory because
+ # it's possible the user created a valid such directory for
+ # operational or test purposes.
+ config.create_paths = False
config.pop('test config')
- # Now config.VAR_DIR will point to the current directory's 'var'
- # directory, which will have been created in config.pop()'s post
- # processing. Clean that up too.
- shutil.rmtree(config.VAR_DIR, ignore_errors=True)
cls.var_dir = None
@classmethod
View it on GitLab:
https://gitlab.com/mailman/mailman/compare/9150dac0b5e7a959cbac121762b86f1de39cab99...dd659b75659f8727425d3102777b850bb32e11be
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe:
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org