| 121 | ) |
| 122 | |
| 123 | def test_stateful(self): |
| 124 | class MyThingy(ColumnClause): |
| 125 | inherit_cache = False |
| 126 | |
| 127 | def __init__(self): |
| 128 | super().__init__("MYTHINGY!") |
| 129 | |
| 130 | @compiles(MyThingy) |
| 131 | def visit_thingy(thingy, compiler, **kw): |
| 132 | if not hasattr(compiler, "counter"): |
| 133 | compiler.counter = 0 |
| 134 | compiler.counter += 1 |
| 135 | return str(compiler.counter) |
| 136 | |
| 137 | self.assert_compile( |
| 138 | select(column("foo"), MyThingy()).order_by(desc(MyThingy())), |
| 139 | "SELECT foo, 1 ORDER BY 2 DESC", |
| 140 | ) |
| 141 | |
| 142 | self.assert_compile( |
| 143 | select(MyThingy(), MyThingy()).where(MyThingy() == 5), |
| 144 | "SELECT 1, 2 WHERE 3 = :MYTHINGY!_1", |
| 145 | ) |
| 146 | |
| 147 | def test_callout_to_compiler(self): |
| 148 | class InsertFromSelect(ClauseElement): |