summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-11-20 12:43:54 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2014-11-20 12:43:54 -0500
commit0b63884a2ce2b4b89f2ddf0db7fba47fce5540f0 (patch)
treeee4fb99695ead07c4ff96f1f57b36ea569d771fe
parent9fb12ba776314288040b8228db42616c246229b0 (diff)
downloadalembic-0b63884a2ce2b4b89f2ddf0db7fba47fce5540f0.tar.gz
- changelog + some polish
-rw-r--r--alembic/config.py14
-rw-r--r--docs/build/changelog.rst11
-rw-r--r--tests/test_config.py24
3 files changed, 36 insertions, 13 deletions
diff --git a/alembic/config.py b/alembic/config.py
index 30f3d79..b29a888 100644
--- a/alembic/config.py
+++ b/alembic/config.py
@@ -52,12 +52,20 @@ class Config(object):
..versionadded:: 0.4
:param config_args: A dictionary of keys and values that will be used
- for substitution in the alembic config file.
+ for substitution in the alembic config file. The dictionary as given
+ is **copied** to a new one, stored locally as the attribute
+ ``.config_args``. When the :attr:`.Config.file_config` attribute is
+ first invoked, the replacement variable ``here`` will be added to this
+ dictionary before the dictionary is passed to ``SafeConfigParser()``
+ to parse the .ini file.
+
+ ..versionadded:: 0.7.0
"""
def __init__(self, file_=None, ini_section='alembic', output_buffer=None,
- stdout=sys.stdout, cmd_opts=None, config_args = {}):
+ stdout=sys.stdout, cmd_opts=None,
+ config_args=util.immutabledict()):
"""Construct a new :class:`.Config`
"""
@@ -66,7 +74,7 @@ class Config(object):
self.output_buffer = output_buffer
self.stdout = stdout
self.cmd_opts = cmd_opts
- self.config_args = config_args
+ self.config_args = dict(config_args)
cmd_opts = None
"""The command-line options passed to the ``alembic`` script.
diff --git a/docs/build/changelog.rst b/docs/build/changelog.rst
index c188605..74a9fa2 100644
--- a/docs/build/changelog.rst
+++ b/docs/build/changelog.rst
@@ -6,10 +6,19 @@ Changelog
:version: 0.7.0
.. change::
+ :tags: feature, config
+ :pullreq: bitbucket:33
+
+ Added new argument :paramref:`.Config.config_args`, allows a dictionary
+ of replacement variables to be passed which will serve as substitution
+ values when an API-produced :class:`.Config` consumes the ``.ini``
+ file. Pull request courtesy Noufal Ibrahim.
+
+ .. change::
:tags: bug, oracle
:tickets: 245
- The Oracle dialect sets "transactional DDL" to False by default,
+ The Oracle dialect sets "transactional DDL" to False by default,
as Oracle does not support transactional DDL.
.. change::
diff --git a/tests/test_config.py b/tests/test_config.py
index c8259bd..2d8f964 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -13,21 +13,27 @@ from alembic.testing.mock import Mock, call
from alembic.testing import eq_, assert_raises_message
from alembic.testing.fixtures import capture_db
from alembic.testing.env import _no_sql_testing_config, clear_staging_env,\
- staging_env
+ staging_env, _write_config_file
-class ConfigTest(TestBase):
+class FileConfigTest(TestBase):
def test_config_args(self):
- config_file = tempfile.mktemp()
- with open(config_file, "w") as fp:
- fp.write("""
+ cfg = _write_config_file("""
[alembic]
migrations = %(base_path)s/db/migrations
""")
- cfg = config.Config(config_file, config_args=dict(base_path = "/home/alembic"))
- eq_(cfg.get_section_option("alembic", "migrations"), "/home/alembic/db/migrations")
- print config_file
- os.unlink(config_file)
+ test_cfg = config.Config(
+ cfg.config_file_name, config_args=dict(base_path="/home/alembic")
+ )
+ eq_(
+ test_cfg.get_section_option("alembic", "migrations"),
+ "/home/alembic/db/migrations")
+
+ def tearDown(self):
+ clear_staging_env()
+
+
+class ConfigTest(TestBase):
def test_config_no_file_main_option(self):
cfg = config.Config()