MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_order_by_labels_enabled

Method test_order_by_labels_enabled

test/sql/test_compiler.py:1728–1798  ·  view source on GitHub ↗

test positive cases with order_by_labels enabled. this is multiplied out to all the ORDER BY modifier operators (see #11592)

(self, operator, expected)

Source from the content-addressed store, hash-verified

1726 (lambda c: c.nulls_first().asc(), "NULLS FIRST ASC"),
1727 )
1728 def test_order_by_labels_enabled(self, operator, expected):
1729 """test positive cases with order_by_labels enabled. this is
1730 multiplied out to all the ORDER BY modifier operators
1731 (see #11592)
1732
1733
1734 """
1735 lab1 = (table1.c.myid + 12).label("foo")
1736 lab2 = func.somefunc(table1.c.name).label("bar")
1737 dialect = default.DefaultDialect()
1738
1739 self.assert_compile(
1740 select(lab1, lab2).order_by(lab1, operator(lab2)),
1741 "SELECT mytable.myid + :myid_1 AS foo, "
1742 "somefunc(mytable.name) AS bar FROM mytable "
1743 f"ORDER BY foo, bar {expected}",
1744 dialect=dialect,
1745 )
1746
1747 # the function embedded label renders as the function
1748 self.assert_compile(
1749 select(lab1, lab2).order_by(func.hoho(lab1), operator(lab2)),
1750 "SELECT mytable.myid + :myid_1 AS foo, "
1751 "somefunc(mytable.name) AS bar FROM mytable "
1752 f"ORDER BY hoho(mytable.myid + :myid_1), bar {expected}",
1753 dialect=dialect,
1754 )
1755
1756 lx = (table1.c.myid + table1.c.myid).label("lx")
1757 ly = (func.lower(table1.c.name) + table1.c.description).label("ly")
1758
1759 self.assert_compile(
1760 select(lx, ly).order_by(lx, operator(ly)),
1761 "SELECT mytable.myid + mytable.myid AS lx, "
1762 "lower(mytable.name) || mytable.description AS ly "
1763 f"FROM mytable ORDER BY lx, ly {expected}",
1764 dialect=dialect,
1765 )
1766
1767 # expression isn't actually the same thing (even though label is)
1768 self.assert_compile(
1769 select(lab1, lab2).order_by(
1770 table1.c.myid.label("foo"),
1771 operator(table1.c.name.label("bar")),
1772 ),
1773 "SELECT mytable.myid + :myid_1 AS foo, "
1774 "somefunc(mytable.name) AS bar FROM mytable "
1775 f"ORDER BY mytable.myid, mytable.name {expected}",
1776 dialect=dialect,
1777 )
1778
1779 # it's also an exact match, not aliased etc.
1780 self.assert_compile(
1781 select(lab1, lab2).order_by(
1782 operator(table1.alias().c.name.label("bar"))
1783 ),
1784 "SELECT mytable.myid + :myid_1 AS foo, "
1785 "somefunc(mytable.name) AS bar FROM mytable "

Callers

nothing calls this directly

Calls 8

selectFunction · 0.90
somefuncMethod · 0.80
assert_compileMethod · 0.80
lowerMethod · 0.80
labelMethod · 0.45
order_byMethod · 0.45
aliasMethod · 0.45
_cloneMethod · 0.45

Tested by

no test coverage detected