summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2016-02-17 16:53:01 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2016-02-17 16:53:01 -0500
commit2965da0a5d89119787bd45ac6f5459a7b755656d (patch)
treea9444e1311b5b39d736ce1d248d464b95c27a9aa
parentbf1d03a9e58a0256db0b1f7389e23a6d11c4a964 (diff)
downloadsqlalchemy-2965da0a5d89119787bd45ac6f5459a7b755656d.tar.gz
- handle parameter sets that aren't correctly formed, so that
for example an exception object made within a test suite can still repr (error seen in Keystone)
-rw-r--r--lib/sqlalchemy/sql/util.py2
-rw-r--r--lib/sqlalchemy/testing/__init__.py2
-rw-r--r--lib/sqlalchemy/testing/assertions.py4
-rw-r--r--test/engine/test_logging.py28
4 files changed, 33 insertions, 3 deletions
diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py
index d40bf48f1..5f180646c 100644
--- a/lib/sqlalchemy/sql/util.py
+++ b/lib/sqlalchemy/sql/util.py
@@ -345,7 +345,7 @@ class _repr_params(_repr_base):
typ = self._DICT
ismulti = False
else:
- assert False, "Unknown parameter type %s" % (type(self.params), )
+ return self.trunc(self.params)
if ismulti and len(self.params) > self.batches:
msg = " ... displaying %i of %i total bound parameter sets ... "
diff --git a/lib/sqlalchemy/testing/__init__.py b/lib/sqlalchemy/testing/__init__.py
index a2663b810..f4a23d238 100644
--- a/lib/sqlalchemy/testing/__init__.py
+++ b/lib/sqlalchemy/testing/__init__.py
@@ -22,7 +22,7 @@ from .assertions import emits_warning, emits_warning_on, uses_deprecated, \
eq_, ne_, le_, is_, is_not_, startswith_, assert_raises, \
assert_raises_message, AssertsCompiledSQL, ComparesTables, \
AssertsExecutionResults, expect_deprecated, expect_warnings, \
- in_, not_in_, eq_ignore_whitespace
+ in_, not_in_, eq_ignore_whitespace, eq_regex
from .util import run_as_contextmanager, rowset, fail, \
provide_metadata, adict, force_drop_names, \
diff --git a/lib/sqlalchemy/testing/assertions.py b/lib/sqlalchemy/testing/assertions.py
index 21f9f68fb..ea50c0738 100644
--- a/lib/sqlalchemy/testing/assertions.py
+++ b/lib/sqlalchemy/testing/assertions.py
@@ -204,6 +204,10 @@ def _assert_no_stray_pool_connections():
_STRAY_CONNECTION_FAILURES = 0
+def eq_regex(a, b, msg=None):
+ assert re.match(b, a), msg or "%r !~ %r" % (a, b)
+
+
def eq_(a, b, msg=None):
"""Assert a == b, with repr messaging on failure."""
assert a == b, msg or "%r != %r" % (a, b)
diff --git a/test/engine/test_logging.py b/test/engine/test_logging.py
index efdee8aef..51ebc5250 100644
--- a/test/engine/test_logging.py
+++ b/test/engine/test_logging.py
@@ -1,4 +1,4 @@
-from sqlalchemy.testing import eq_, assert_raises_message
+from sqlalchemy.testing import eq_, assert_raises_message, eq_regex
from sqlalchemy import select
import sqlalchemy as tsa
from sqlalchemy.testing import engines
@@ -8,6 +8,7 @@ from sqlalchemy.testing import mock
from sqlalchemy.testing.util import lazy_gc
from sqlalchemy import util
+
class LogParamsTest(fixtures.TestBase):
__only_on__ = 'sqlite'
__requires__ = 'ad_hoc_engines',
@@ -106,6 +107,31 @@ class LogParamsTest(fixtures.TestBase):
)
)
+ def test_exception_format_dict_param(self):
+ exception = tsa.exc.IntegrityError("foo", {"x": "y"}, None)
+ eq_regex(
+ str(exception),
+ r"\(.*.NoneType\) None \[SQL: 'foo'\] \[parameters: {'x': 'y'}\]"
+ )
+
+ def test_exception_format_unexpected_parameter(self):
+ # test that if the parameters aren't any known type, we just
+ # run through repr()
+ exception = tsa.exc.IntegrityError("foo", "bar", "bat")
+ eq_regex(
+ str(exception),
+ r"\(.*.str\) bat \[SQL: 'foo'\] \[parameters: 'bar'\]"
+ )
+
+ def test_exception_format_unexpected_member_parameter(self):
+ # test that if the parameters aren't any known type, we just
+ # run through repr()
+ exception = tsa.exc.IntegrityError("foo", ["bar", "bat"], "hoho")
+ eq_regex(
+ str(exception),
+ r"\(.*.str\) hoho \[SQL: 'foo'\] \[parameters: \['bar', 'bat'\]\]"
+ )
+
def test_result_large_param(self):
import random
largeparam = ''.join(chr(random.randint(52, 85)) for i in range(5000))