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 ... "
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, \
_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)
-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
from sqlalchemy.testing.util import lazy_gc
from sqlalchemy import util
+
class LogParamsTest(fixtures.TestBase):
__only_on__ = 'sqlite'
__requires__ = 'ad_hoc_engines',
)
)
+ 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))