From: Mike Bayer Date: Fri, 4 Apr 2014 15:09:34 +0000 (-0400) Subject: - Fixed bug where :meth:`.EnvironmentContext.get_x_argument` X-Git-Tag: rel_0_6_5~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e0b345af1f6d64e184a87fd3d03f5f73665afb6;p=thirdparty%2Fsqlalchemy%2Falembic.git - Fixed bug where :meth:`.EnvironmentContext.get_x_argument` would fail if the :class:`.Config` in use didn't actually originate from a command line call. fixes #195 --- diff --git a/alembic/environment.py b/alembic/environment.py index 0c9095d3..cba3beb5 100644 --- a/alembic/environment.py +++ b/alembic/environment.py @@ -246,7 +246,10 @@ class EnvironmentContext(object): :attr:`.Config.cmd_opts` """ - value = self.config.cmd_opts.x or [] + if self.config.cmd_opts is not None: + value = self.config.cmd_opts.x or [] + else: + value = [] if as_dictionary: value = dict( arg.split('=', 1) for arg in value diff --git a/docs/build/changelog.rst b/docs/build/changelog.rst index b763c742..a6cefc6f 100644 --- a/docs/build/changelog.rst +++ b/docs/build/changelog.rst @@ -5,6 +5,14 @@ Changelog .. changelog:: :version: 0.6.5 + .. change:: + :tags: bug, environment + :tickets: 195 + + Fixed bug where :meth:`.EnvironmentContext.get_x_argument` + would fail if the :class:`.Config` in use didn't actually + originate from a command line call. + .. change:: :tags: bug, autogenerate :tickets: 194 diff --git a/tests/test_environment.py b/tests/test_environment.py new file mode 100644 index 00000000..d7a4554a --- /dev/null +++ b/tests/test_environment.py @@ -0,0 +1,64 @@ +#!coding: utf-8 + +from alembic.config import Config +from alembic.script import ScriptDirectory +from alembic.environment import EnvironmentContext +import unittest +from . import Mock, call, _no_sql_testing_config, staging_env, clear_staging_env + +from . import eq_ + +class EnvironmentTest(unittest.TestCase): + def setUp(self): + staging_env() + self.cfg = _no_sql_testing_config() + + def tearDown(self): + clear_staging_env() + + def _fixture(self, **kw): + script = ScriptDirectory.from_config(self.cfg) + env = EnvironmentContext( + self.cfg, + script, + **kw + ) + return env + + def test_x_arg(self): + env = self._fixture() + self.cfg.cmd_opts = Mock(x="y=5") + eq_( + env.get_x_argument(), + "y=5" + ) + + def test_x_arg_asdict(self): + env = self._fixture() + self.cfg.cmd_opts = Mock(x=["y=5"]) + eq_( + env.get_x_argument(as_dictionary=True), + {"y": "5"} + ) + + def test_x_arg_no_opts(self): + env = self._fixture() + eq_( + env.get_x_argument(), + [] + ) + + def test_x_arg_no_opts_asdict(self): + env = self._fixture() + eq_( + env.get_x_argument(as_dictionary=True), + {} + ) + + def test_tag_arg(self): + env = self._fixture(tag="x") + eq_( + env.get_tag_argument(), + "x" + ) +