]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
- Fixed bug where :meth:`.EnvironmentContext.get_x_argument`
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 4 Apr 2014 15:09:34 +0000 (11:09 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 4 Apr 2014 15:09:34 +0000 (11:09 -0400)
would fail if the :class:`.Config` in use didn't actually
originate from a command line call. fixes #195

alembic/environment.py
docs/build/changelog.rst
tests/test_environment.py [new file with mode: 0644]

index 0c9095d3c0bd47174be9e91ad4b1850b6948aa0c..cba3beb590ceb96e1fe8de54269aa2ec7a7997fa 100644 (file)
@@ -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
index b763c74290fb662197121bf412deb241199770e4..a6cefc6fcb13df4fa6edbd7f1bbd1cbe3f9ded9d 100644 (file)
@@ -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 (file)
index 0000000..d7a4554
--- /dev/null
@@ -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"
+        )
+