util.warn("Could not parse CHECK constraint text: %r" % src)
sqltext = ""
else:
- match_without_newlines = ''.join(m.group(1).splitlines())
+ match_without_newlines = ' '.join(m.group(1).splitlines()).strip()
sqltext = re.sub(r"^\((.+)\)$", r"\1", match_without_newlines)
entry = {"name": name, "sqltext": sqltext}
if m and m.group(2):
testing.db.dialect.get_check_constraints(conn, "foo")
def test_reflect_extra_newlines(self):
- rows = [("some name", "CHECK (\n(a \nIS\n NOT\n\n NULL\n)\n)")]
+ rows = [
+ ("some name", "CHECK (\n(a \nIS\n NOT\n\n NULL\n)\n)"),
+ ("some other name", "CHECK ((b\nIS\nNOT\nNULL))"),
+ ("some CRLF name", "CHECK ((c\r\n\r\nIS\r\nNOT\r\nNULL))"),
+ ]
conn = mock.Mock(
execute=lambda *arg, **kw: mock.MagicMock(
fetchall=lambda: rows, __iter__=lambda self: iter(rows)
[
{
"name": "some name",
- "sqltext": "a IS NOT NULL",
+ "sqltext": "a IS NOT NULL ",
+ },
+ {
+ "name": "some other name",
+ "sqltext": "b IS NOT NULL",
+ },
+ {
+ "name": "some CRLF name",
+ "sqltext": "c IS NOT NULL",
}
],
)