From 0b63884a2ce2b4b89f2ddf0db7fba47fce5540f0 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 20 Nov 2014 12:43:54 -0500 Subject: - changelog + some polish --- alembic/config.py | 14 +++++++++++--- docs/build/changelog.rst | 11 ++++++++++- tests/test_config.py | 24 +++++++++++++++--------- 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 @@ -5,11 +5,20 @@ Changelog .. 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() -- cgit v1.2.1