summaryrefslogtreecommitdiff
path: root/test/sql/test_case_statement.py
diff options
context:
space:
mode:
authorMiguel Ventura <miguel.ventura@gmail.com>2018-05-14 16:56:58 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2018-05-17 12:23:10 -0400
commit0b0b58c938c6a38fccc3e0ba59876b3b6b4f8009 (patch)
tree7482bb46bf1e352b184644ce549686ee8befe0e6 /test/sql/test_case_statement.py
parent432d24ab1aac04a8ec881919964ff47ad8154659 (diff)
downloadsqlalchemy-0b0b58c938c6a38fccc3e0ba59876b3b6b4f8009.tar.gz
Fix string formatting TypeError if tuple is passed
Fixed issue where the "ambiguous literal" error message used when interpreting literal values as SQL expression values would encounter a tuple value, and fail to format the message properly. Pull request courtesy Miguel Ventura. Change-Id: I50d5d32d5f80ec79703a42d4b19b42c2f9701f24 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/442
Diffstat (limited to 'test/sql/test_case_statement.py')
-rw-r--r--test/sql/test_case_statement.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/test/sql/test_case_statement.py b/test/sql/test_case_statement.py
index f7025b360..d81ff20cd 100644
--- a/test/sql/test_case_statement.py
+++ b/test/sql/test_case_statement.py
@@ -1,4 +1,4 @@
-from sqlalchemy.testing import assert_raises, eq_
+from sqlalchemy.testing import assert_raises, eq_, assert_raises_message
from sqlalchemy.testing import fixtures, AssertsCompiledSQL
from sqlalchemy import (
testing, exc, case, select, literal_column, text, and_, Integer, cast,
@@ -102,11 +102,23 @@ class CaseTest(fixtures.TestBase, AssertsCompiledSQL):
(0, 6, 'pk_6_data')
]
+ def test_literal_interpretation_ambiguous(self):
+ assert_raises_message(
+ exc.ArgumentError,
+ r"Ambiguous literal: 'x'. Use the 'text\(\)' function",
+ case, [("x", "y")]
+ )
+
+ def test_literal_interpretation_ambiguous_tuple(self):
+ assert_raises_message(
+ exc.ArgumentError,
+ r"Ambiguous literal: \('x', 'y'\). Use the 'text\(\)' function",
+ case, [(("x", "y"), "z")]
+ )
+
def test_literal_interpretation(self):
t = table('test', column('col1'))
- assert_raises(exc.ArgumentError, case, [("x", "y")])
-
self.assert_compile(
case([("x", "y")], value=t.c.col1),
"CASE test.col1 WHEN :param_1 THEN :param_2 END")