Skip to content

Commit

Permalink
- Fixed bug where :meth:.EnvironmentContext.get_x_argument
Browse files Browse the repository at this point in the history
would fail if the :class:`.Config` in use didn't actually
originate from a command line call. fixes #195
  • Loading branch information
zzzeek committed Apr 4, 2014
1 parent a9fa7d9 commit 4e0b345
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
5 changes: 4 additions & 1 deletion alembic/environment.py
Expand Up @@ -246,7 +246,10 @@ def get_x_argument(self, as_dictionary=False):
: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
Expand Down
8 changes: 8 additions & 0 deletions docs/build/changelog.rst
Expand Up @@ -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
Expand Down
64 changes: 64 additions & 0 deletions 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"
)

0 comments on commit 4e0b345

Please sign in to comment.