MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_stateful

Method test_stateful

test/ext/test_compiler.py:123–145  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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):

Callers

nothing calls this directly

Calls 7

selectFunction · 0.90
columnFunction · 0.90
descFunction · 0.90
MyThingyClass · 0.85
assert_compileMethod · 0.80
order_byMethod · 0.45
whereMethod · 0.45

Tested by

no test coverage detected