except sa_exceptions.DBAPIError as exc:
eq_(
str(exc),
- "(test.base.test_except.OperationalError) "
- "[SQL: 'this is a message'] (Background on this error at: "
- "http://sqlalche.me/e/e3q8)",
+ "(test.base.test_except.OperationalError) \n"
+ "[SQL: this is a message]\n"
+ "(Background on this error at: http://sqlalche.me/e/e3q8)",
+ )
+
+ def test_tostring_with_newlines(self):
+ try:
+ raise sa_exceptions.DBAPIError.instance(
+ "this is a message\nthis is the next line\nthe last line",
+ None,
+ OperationalError(),
+ DatabaseError,
+ )
+ except sa_exceptions.DBAPIError as exc:
+ eq_(
+ str(exc),
+ "(test.base.test_except.OperationalError) \n"
+ "[SQL: this is a message\nthis is the next line\n"
+ "the last line]\n"
+ "(Background on this error at: http://sqlalche.me/e/e3q8)",
)
def test_statement_error_no_code(self):
except sa_exceptions.StatementError as err:
eq_(
str(err),
- "(sqlalchemy.exc.InvalidRequestError) hello "
- "[SQL: 'select * from table'] [parameters: [{'x': 1}]]",
+ "(sqlalchemy.exc.InvalidRequestError) hello\n"
+ "[SQL: select * from table]\n[parameters: [{'x': 1}]]",
)
eq_(err.args, ("(sqlalchemy.exc.InvalidRequestError) hello",))
except sa_exceptions.StatementError as err:
eq_(
str(err),
- "(sqlalchemy.exc.InvalidRequestError) hello "
- "[SQL: 'select * from table'] [parameters: [{'x': 1}]] "
+ "(sqlalchemy.exc.InvalidRequestError) hello\n"
+ "[SQL: select * from table]\n"
+ "[parameters: [{'x': 1}]]\n"
"(Background on this error at: http://sqlalche.me/e/abcd)",
)
eq_(err.args, ("(sqlalchemy.exc.InvalidRequestError) hello",))
orig.args = [2006, "Test raise operational error"]
eq_(
str(orig),
- "(2006, 'Test raise operational error') "
+ "(2006, 'Test raise operational error')\n"
"(Background on this error at: http://sqlalche.me/e/dbapi)",
)
eq_(
compat.text_type(orig),
compat.u(
- "méil (Background on this error at: "
+ "méil\n(Background on this error at: "
"http://sqlalche.me/e/dbapi)"
),
)
)
except sa_exceptions.DBAPIError as exc:
assert str(exc).startswith(
- "(test.base.test_except.OperationalError) "
- "[SQL: 'this is a message'] [parameters: {"
+ "(test.base.test_except.OperationalError) \n"
+ "[SQL: this is a message]\n"
+ "[parameters: {"
)
def test_tostring_large_list(self):
OperationalError(),
DatabaseError,
)
- except sa_exceptions.DBAPIError as exc:
- assert str(exc).startswith(
- "(test.base.test_except.OperationalError) "
- "[SQL: 'this is a message'] [parameters: "
+ except sa_exceptions.DBAPIError as ex:
+ assert str(ex).startswith(
+ "(test.base.test_except.OperationalError) \n"
+ "[SQL: this is a message]\n[parameters: "
"[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]"
)
except sa_exceptions.DBAPIError as exc:
eq_(
str(exc),
- "(test.base.test_except.OperationalError) sql error "
- "[SQL: 'this is a message'] [parameters: [{1: 1}, "
- "{1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: "
- "1}, {1: 1}, {1: 1}]] (Background on this error at: "
- "http://sqlalche.me/e/e3q8)",
+ "(test.base.test_except.OperationalError) sql error\n"
+ "[SQL: this is a message]\n"
+ "[parameters: [{1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1},"
+ " {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}]]\n"
+ "(Background on this error at: http://sqlalche.me/e/e3q8)",
)
eq_(
exc.args,
except sa_exceptions.DBAPIError as exc:
eq_(
str(exc),
- "(test.base.test_except.OperationalError) "
- "[SQL: 'this is a message'] [parameters: [{1: 1}, "
+ "(test.base.test_except.OperationalError) \n"
+ "[SQL: this is a message]\n"
+ "[parameters: [{1: 1}, "
"{1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, "
"{1: 1}, {1: 1} ... displaying 10 of 11 total "
- "bound parameter sets ... {1: 1}, {1: 1}]] "
+ "bound parameter sets ... {1: 1}, {1: 1}]]\n"
"(Background on this error at: http://sqlalche.me/e/e3q8)",
)
try:
except sa_exceptions.DBAPIError as exc:
eq_(
str(exc),
- "(test.base.test_except.OperationalError) "
- "[SQL: 'this is a message'] [parameters: [(1,), "
- "(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,)]] "
+ "(test.base.test_except.OperationalError) \n"
+ "[SQL: this is a message]\n"
+ "[parameters: [(1,), "
+ "(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,)]]\n"
"(Background on this error at: http://sqlalche.me/e/e3q8)",
)
try:
except sa_exceptions.DBAPIError as exc:
eq_(
str(exc),
- "(test.base.test_except.OperationalError) "
- "[SQL: 'this is a message'] [parameters: [(1,), "
+ "(test.base.test_except.OperationalError) \n"
+ "[SQL: this is a message]\n"
+ "[parameters: [(1,), "
"(1,), (1,), (1,), (1,), (1,), (1,), (1,) "
"... displaying 10 of 11 total bound "
- "parameter sets ... (1,), (1,)]] "
+ "parameter sets ... (1,), (1,)]]\n"
"(Background on this error at: http://sqlalche.me/e/e3q8)",
)
exception = tsa.exc.IntegrityError("foo", {"x": "y"}, None)
eq_regex(
str(exception),
- r"\(.*.NoneType\) None \[SQL: 'foo'\] \[parameters: {'x': 'y'}\]",
+ r"\(.*.NoneType\) None\n\[SQL: foo\]\n\[parameters: {'x': 'y'}\]",
)
def test_exception_format_unexpected_parameter(self):
exception = tsa.exc.IntegrityError("foo", "bar", "bat")
eq_regex(
str(exception),
- r"\(.*.str\) bat \[SQL: 'foo'\] \[parameters: 'bar'\]",
+ r"\(.*.str\) bat\n\[SQL: foo\]\n\[parameters: 'bar'\]",
)
def test_exception_format_unexpected_member_parameter(self):
exception = tsa.exc.IntegrityError("foo", ["bar", "bat"], "hoho")
eq_regex(
str(exception),
- r"\(.*.str\) hoho \[SQL: 'foo'\] \[parameters: \['bar', 'bat'\]\]",
+ r"\(.*.str\) hoho\n\[SQL: foo\]\n\[parameters: \['bar', 'bat'\]\]",
)
def test_result_large_param(self):
def test_error_large_dict(self):
assert_raises_message(
tsa.exc.DBAPIError,
- r".*'INSERT INTO nonexistent \(data\) values \(:data\)'\] "
+ r".*INSERT INTO nonexistent \(data\) values \(:data\)\]\n"
r"\[parameters: "
r"\[{'data': '0'}, {'data': '1'}, {'data': '2'}, "
r"{'data': '3'}, {'data': '4'}, {'data': '5'}, "
assert_raises_message(
tsa.exc.DBAPIError,
r".*INSERT INTO nonexistent \(data\) values "
- r"\(\?\)'\] \[parameters: \[\('0',\), \('1',\), \('2',\), "
+ r"\(\?\)\]\n\[parameters: \[\('0',\), \('1',\), \('2',\), "
r"\('3',\), \('4',\), \('5',\), \('6',\), \('7',\) "
r"... displaying "
r"10 of 100 total bound parameter sets ... "