test: 修正列渲染断言——SQLAlchemy 会对保留字加反引号
monitor_run.trigger 是 MySQL 保留字,渲染出来是 `trigger`。这比之前手写的列清单更正确: 清单里的裸 trigger 会直接语法错误。断言改为剥掉引号后比对列名。
This commit is contained in:
@@ -34,7 +34,12 @@ def _ddl(column: Column) -> str:
|
||||
def test_column_renders_as_ddl(column):
|
||||
ddl = db._column_ddl(column)
|
||||
|
||||
assert ddl.startswith(column.name)
|
||||
# SQLAlchemy back-quotes an identifier only when it has to, so the rendered
|
||||
# name matches the column's with the quoting stripped -- which is the case for
|
||||
# reserved words like monitor_run.trigger. That quoting is a feature: the
|
||||
# hand-kept list this replaced would have emitted bare `trigger` and died on a
|
||||
# syntax error.
|
||||
assert ddl.split(" ", 1)[0].strip("`") == column.name
|
||||
# MySQL refuses AUTO_INCREMENT together with the DEFAULT this helper appends
|
||||
# to NOT NULL columns.
|
||||
assert "AUTO_INCREMENT" not in ddl
|
||||
|
||||
Reference in New Issue
Block a user