diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-09-25 17:42:51 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-09-26 11:26:43 -0400 |
| commit | cb9215504c0131facc8ed1b22746d3dc53e628b9 (patch) | |
| tree | 8d51c54ef23bc5f16c1a775e622bb1ff2d2141b9 /test/sql | |
| parent | 48d22c040694bbc00bcd0e343770408648616bb6 (diff) | |
| download | sqlalchemy-cb9215504c0131facc8ed1b22746d3dc53e628b9.tar.gz | |
Unify generation between Core and ORM query
generation is to be enhanced to include caching
functionality, so ensure that Query and all generative in Core
(e.g. select, DML etc) are using the same generations system.
Additionally, deprecate Select.append methods and state
Select methods independently of their append versions.
Mutability of expression objects is a special case only when
generating new objects during a visit.
Fixes: #4637
Change-Id: I3dfac00d5e0f710c833b236f7a0913e1ca24dde4
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_compiler.py | 2 | ||||
| -rw-r--r-- | test/sql/test_deprecations.py | 103 | ||||
| -rw-r--r-- | test/sql/test_generative.py | 8 | ||||
| -rw-r--r-- | test/sql/test_selectable.py | 12 | ||||
| -rw-r--r-- | test/sql/test_text.py | 10 |
5 files changed, 118 insertions, 17 deletions
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index c789a879a..7eda0207a 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -792,7 +792,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): s = select( [], exists([1], table2.c.otherid == table1.c.myid), from_obj=table1 ) - s.append_column(table1) + s.column.non_generative(s, table1) self.assert_compile( s, "SELECT mytable.myid, mytable.name, " diff --git a/test/sql/test_deprecations.py b/test/sql/test_deprecations.py index 09deb1294..a75de3f11 100644 --- a/test/sql/test_deprecations.py +++ b/test/sql/test_deprecations.py @@ -809,7 +809,10 @@ class SelectableTest(fixtures.TestBase, AssertsCompiledSQL): "JOIN (SELECT 1 AS a, 2 AS b) AS joinfrom " "ON basefrom.a = joinfrom.a", ) - replaced.append_column(joinfrom.c.b) + + with testing.expect_deprecated(r"The Select.append_column\(\)"): + replaced.append_column(joinfrom.c.b) + self.assert_compile( replaced, "SELECT basefrom.a, joinfrom.b FROM (SELECT 1 AS a) AS basefrom " @@ -1023,3 +1026,101 @@ class TextualSelectTest(fixtures.TestBase, AssertsCompiledSQL): "The SelectBase.c and SelectBase.columns" ): eq_(t.c.c.type._type_affinity, String) + + +class DeprecatedAppendMethTest(fixtures.TestBase, AssertsCompiledSQL): + __dialect__ = "default" + + def _expect_deprecated(self, clsname, methname, newmeth): + return testing.expect_deprecated( + r"The %s.append_%s\(\) method is deprecated " + r"and will be removed in a future release. Use the generative " + r"method %s.%s\(\)." % (clsname, methname, clsname, newmeth) + ) + + def test_append_whereclause(self): + t = table("t", column("q")) + stmt = select([t]) + + with self._expect_deprecated("Select", "whereclause", "where"): + stmt.append_whereclause(t.c.q == 5) + + self.assert_compile(stmt, "SELECT t.q FROM t WHERE t.q = :q_1") + + def test_append_having(self): + t = table("t", column("q")) + stmt = select([t]).group_by(t.c.q) + + with self._expect_deprecated("Select", "having", "having"): + stmt.append_having(t.c.q == 5) + + self.assert_compile( + stmt, "SELECT t.q FROM t GROUP BY t.q HAVING t.q = :q_1" + ) + + def test_append_order_by(self): + t = table("t", column("q"), column("x")) + stmt = select([t]).where(t.c.q == 5) + + with self._expect_deprecated( + "GenerativeSelect", "order_by", "order_by" + ): + stmt.append_order_by(t.c.x) + + self.assert_compile( + stmt, "SELECT t.q, t.x FROM t WHERE t.q = :q_1 ORDER BY t.x" + ) + + def test_append_group_by(self): + t = table("t", column("q")) + stmt = select([t]) + + with self._expect_deprecated( + "GenerativeSelect", "group_by", "group_by" + ): + stmt.append_group_by(t.c.q) + + stmt = stmt.having(t.c.q == 5) + + self.assert_compile( + stmt, "SELECT t.q FROM t GROUP BY t.q HAVING t.q = :q_1" + ) + + def test_append_correlation(self): + t1 = table("t1", column("q")) + t2 = table("t2", column("q"), column("p")) + + inner = select([t2.c.p]).where(t2.c.q == t1.c.q) + + with self._expect_deprecated("Select", "correlation", "correlate"): + inner.append_correlation(t1) + stmt = select([t1]).where(t1.c.q == inner.scalar_subquery()) + + self.assert_compile( + stmt, + "SELECT t1.q FROM t1 WHERE t1.q = " + "(SELECT t2.p FROM t2 WHERE t2.q = t1.q)", + ) + + def test_append_column(self): + t1 = table("t1", column("q"), column("p")) + stmt = select([t1.c.q]) + with self._expect_deprecated("Select", "column", "column"): + stmt.append_column(t1.c.p) + self.assert_compile(stmt, "SELECT t1.q, t1.p FROM t1") + + def test_append_prefix(self): + t1 = table("t1", column("q"), column("p")) + stmt = select([t1.c.q]) + with self._expect_deprecated("Select", "prefix", "prefix_with"): + stmt.append_prefix("FOO BAR") + self.assert_compile(stmt, "SELECT FOO BAR t1.q FROM t1") + + def test_append_from(self): + t1 = table("t1", column("q")) + t2 = table("t2", column("q")) + + stmt = select([t1]) + with self._expect_deprecated("Select", "from", "select_from"): + stmt.append_from(t1.join(t2, t1.c.q == t2.c.q)) + self.assert_compile(stmt, "SELECT t1.q FROM t1 JOIN t2 ON t1.q = t2.q") diff --git a/test/sql/test_generative.py b/test/sql/test_generative.py index 262333dc5..8d347a522 100644 --- a/test/sql/test_generative.py +++ b/test/sql/test_generative.py @@ -527,7 +527,7 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): class Vis(CloningVisitor): def visit_select(self, select): - select.append_whereclause(t1.c.col2 == 7) + select.where.non_generative(select, t1.c.col2 == 7) s3 = Vis().traverse(s2) assert str(s3) == s3_assert @@ -537,7 +537,7 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): class Vis(ClauseVisitor): def visit_select(self, select): - select.append_whereclause(t1.c.col2 == 7) + select.where.non_generative(select, t1.c.col2 == 7) Vis().traverse(s2) assert str(s2) == s3_assert @@ -546,7 +546,7 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): class Vis(CloningVisitor): def visit_select(self, select): - select.append_whereclause(t1.c.col3 == 9) + select.where.non_generative(select, t1.c.col3 == 9) s4 = Vis().traverse(s3) print(str(s3)) @@ -719,7 +719,7 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): class Vis(CloningVisitor): def visit_select(self, select): - select.append_whereclause(t1.c.col2 == 7) + select.where.non_generative(select, t1.c.col2 == 7) self.assert_compile( select([t2]).where( diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index c54f27c23..76cece5e4 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -345,8 +345,8 @@ class SelectableTest( sel = select([literal_column("1").label("a")]) eq_(list(sel.selected_columns.keys()), ["a"]) cloned = visitors.ReplacingCloningVisitor().traverse(sel) - cloned.append_column(literal_column("2").label("b")) - cloned.append_column(func.foo()) + cloned.column.non_generative(cloned, literal_column("2").label("b")) + cloned.column.non_generative(cloned, func.foo()) eq_(list(cloned.selected_columns.keys()), ["a", "b", "foo()"]) def test_clone_col_list_changes_then_proxy(self): @@ -354,7 +354,7 @@ class SelectableTest( stmt = select([t.c.q]).subquery() def add_column(stmt): - stmt.append_column(t.c.p) + stmt.column.non_generative(stmt, t.c.p) stmt2 = visitors.cloned_traverse(stmt, {}, {"select": add_column}) eq_(list(stmt.c.keys()), ["q"]) @@ -365,7 +365,7 @@ class SelectableTest( stmt = select([t.c.q]).subquery() def add_column(stmt): - stmt.append_column(t.c.p) + stmt.column.non_generative(stmt, t.c.p) stmt2 = visitors.cloned_traverse(stmt, {}, {"select": add_column}) eq_(list(stmt.c.keys()), ["q"]) @@ -395,7 +395,7 @@ class SelectableTest( "JOIN (SELECT 1 AS a, 2 AS b) AS joinfrom " "ON basefrom.a = joinfrom.a", ) - replaced.append_column(joinfrom.c.b) + replaced.column.non_generative(replaced, joinfrom.c.b) self.assert_compile( replaced, "SELECT basefrom.a, joinfrom.b FROM (SELECT 1 AS a) AS basefrom " @@ -948,7 +948,7 @@ class SelectableTest( s = select([t]) with testing.expect_deprecated("The SelectBase.c"): - s.append_whereclause(s.c.x > 5) + s.where.non_generative(s, s.c.x > 5) assert_raises_message( exc.InvalidRequestError, r"select\(\) construct refers to itself as a FROM", diff --git a/test/sql/test_text.py b/test/sql/test_text.py index 9483d10b0..bec56f2f7 100644 --- a/test/sql/test_text.py +++ b/test/sql/test_text.py @@ -77,12 +77,12 @@ class SelectCompositionTest(fixtures.TestBase, AssertsCompiledSQL): def test_select_composition_two(self): s = select() - s.append_column(column("column1")) - s.append_column(column("column2")) - s.append_whereclause(text("column1=12")) - s.append_whereclause(text("column2=19")) + s = s.column(column("column1")) + s = s.column(column("column2")) + s = s.where(text("column1=12")) + s = s.where(text("column2=19")) s = s.order_by("column1") - s.append_from(text("table1")) + s = s.select_from(text("table1")) self.assert_compile( s, "SELECT column1, column2 FROM table1 WHERE " |
