MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_orderby_groupby

Method test_orderby_groupby

test/sql/test_compiler.py:2109–2183  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2107 )
2108
2109 def test_orderby_groupby(self):
2110 self.assert_compile(
2111 table2.select().order_by(
2112 table2.c.otherid, asc(table2.c.othername)
2113 ),
2114 "SELECT myothertable.otherid, myothertable.othername FROM "
2115 "myothertable ORDER BY myothertable.otherid, "
2116 "myothertable.othername ASC",
2117 )
2118
2119 self.assert_compile(
2120 table2.select().order_by(
2121 table2.c.otherid, table2.c.othername.desc()
2122 ),
2123 "SELECT myothertable.otherid, myothertable.othername FROM "
2124 "myothertable ORDER BY myothertable.otherid, "
2125 "myothertable.othername DESC",
2126 )
2127
2128 # generative order_by
2129 self.assert_compile(
2130 table2.select()
2131 .order_by(table2.c.otherid)
2132 .order_by(table2.c.othername.desc()),
2133 "SELECT myothertable.otherid, myothertable.othername FROM "
2134 "myothertable ORDER BY myothertable.otherid, "
2135 "myothertable.othername DESC",
2136 )
2137
2138 self.assert_compile(
2139 table2.select()
2140 .order_by(table2.c.otherid)
2141 .order_by(table2.c.othername.desc())
2142 .order_by(None),
2143 "SELECT myothertable.otherid, myothertable.othername "
2144 "FROM myothertable",
2145 )
2146
2147 self.assert_compile(
2148 select(table2.c.othername, func.count(table2.c.otherid)).group_by(
2149 table2.c.othername
2150 ),
2151 "SELECT myothertable.othername, "
2152 "count(myothertable.otherid) AS count_1 "
2153 "FROM myothertable GROUP BY myothertable.othername",
2154 )
2155
2156 # generative group by
2157 self.assert_compile(
2158 select(table2.c.othername, func.count(table2.c.otherid)).group_by(
2159 table2.c.othername
2160 ),
2161 "SELECT myothertable.othername, "
2162 "count(myothertable.otherid) AS count_1 "
2163 "FROM myothertable GROUP BY myothertable.othername",
2164 )
2165
2166 self.assert_compile(

Callers

nothing calls this directly

Calls 8

ascFunction · 0.90
selectFunction · 0.90
assert_compileMethod · 0.80
order_byMethod · 0.45
selectMethod · 0.45
descMethod · 0.45
group_byMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected