From 591e0cf08a798fb16e0ee9b56df5c3141aa48959 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 17 Feb 2016 13:31:29 -0500 Subject: - All string formatting of bound parameter sets and result rows for logging, exception, and ``repr()`` purposes now truncate very large scalar values within each collection, including an "N characters truncated" notation, similar to how the display for large multiple-parameter sets are themselves truncated. fixes #2837 --- test/engine/test_logging.py | 86 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) (limited to 'test/engine') diff --git a/test/engine/test_logging.py b/test/engine/test_logging.py index 180ea9388..847ba06c4 100644 --- a/test/engine/test_logging.py +++ b/test/engine/test_logging.py @@ -6,7 +6,7 @@ import logging.handlers from sqlalchemy.testing import fixtures from sqlalchemy.testing import mock from sqlalchemy.testing.util import lazy_gc - +from sqlalchemy import util class LogParamsTest(fixtures.TestBase): __only_on__ = 'sqlite' @@ -53,6 +53,90 @@ class LogParamsTest(fixtures.TestBase): "bound parameter sets ... ('98',), ('99',)]" ) + def test_log_large_parameter_single(self): + import random + largeparam = ''.join(chr(random.randint(52, 85)) for i in range(5000)) + + self.eng.execute( + "INSERT INTO foo (data) values (?)", + (largeparam, ) + ) + + eq_( + self.buf.buffer[1].message, + "('%s ... (4702 characters truncated) ... %s',)" % ( + largeparam[0:149], largeparam[-149:] + ) + ) + + def test_log_large_parameter_multiple(self): + import random + lp1 = ''.join(chr(random.randint(52, 85)) for i in range(5000)) + lp2 = ''.join(chr(random.randint(52, 85)) for i in range(200)) + lp3 = ''.join(chr(random.randint(52, 85)) for i in range(670)) + + self.eng.execute( + "INSERT INTO foo (data) values (?)", + [(lp1, ), (lp2, ), (lp3, )] + ) + + eq_( + self.buf.buffer[1].message, + "[('%s ... (4702 characters truncated) ... %s',), ('%s',), " + "('%s ... (372 characters truncated) ... %s',)]" % ( + lp1[0:149], lp1[-149:], lp2, lp3[0:149], lp3[-149:] + ) + ) + + def test_result_large_param(self): + import random + largeparam = ''.join(chr(random.randint(52, 85)) for i in range(5000)) + + self.eng.echo = 'debug' + result = self.eng.execute( + "SELECT ?", + (largeparam, ) + ) + + row = result.first() + + eq_( + self.buf.buffer[1].message, + "('%s ... (4702 characters truncated) ... %s',)" % ( + largeparam[0:149], largeparam[-149:] + ) + ) + + if util.py3k: + eq_( + self.buf.buffer[3].message, + "Row ('%s ... (4702 characters truncated) ... %s',)" % ( + largeparam[0:149], largeparam[-149:] + ) + ) + else: + eq_( + self.buf.buffer[3].message, + "Row (u'%s ... (4703 characters truncated) ... %s',)" % ( + largeparam[0:148], largeparam[-149:] + ) + ) + + if util.py3k: + eq_( + repr(row), + "('%s ... (4702 characters truncated) ... %s',)" % ( + largeparam[0:149], largeparam[-149:] + ) + ) + else: + eq_( + repr(row), + "(u'%s ... (4703 characters truncated) ... %s',)" % ( + largeparam[0:148], largeparam[-149:] + ) + ) + def test_error_large_dict(self): assert_raises_message( tsa.exc.DBAPIError, -- cgit v1.2.1