diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-01-24 14:07:24 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-02-12 12:44:47 -0500 |
| commit | 9fca5d827d880ccc529c94bb65c46de6aafd227c (patch) | |
| tree | 54383b90c6acfc644c563872f131724fed5ef6ea /test/sql | |
| parent | 47202abbf9823e1058e0b88ce64ffd3b88027e96 (diff) | |
| download | sqlalchemy-9fca5d827d880ccc529c94bb65c46de6aafd227c.tar.gz | |
Create initial future package, RemovedIn20Warning
Reorganization of Select() is the first major element
of the 2.0 restructuring. In order to start this we need
to first create the new Select constructor and apply legacy
elements to the old one. This in turn necessitates
starting up the RemovedIn20Warning concept which itself
need to refer to "sqlalchemy.future", so begin to establish
this basic framework. Additionally, update the
DML constructors with the newer no-keyword style. Remove
the use of the "pending deprecation" and fix Query.add_column()
deprecation which was not acting as deprecated.
Fixes: #4845
Fixes: #4648
Change-Id: I0c7a22b2841a985e1c379a0bb6c94089aae6264c
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_compiler.py | 6 | ||||
| -rw-r--r-- | test/sql/test_deprecations.py | 21 | ||||
| -rw-r--r-- | test/sql/test_external_traversal.py | 2 | ||||
| -rw-r--r-- | test/sql/test_selectable.py | 21 | ||||
| -rw-r--r-- | test/sql/test_text.py | 3 | ||||
| -rw-r--r-- | test/sql/test_update.py | 61 |
6 files changed, 97 insertions, 17 deletions
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index b53acf61e..a7e9916cd 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -963,7 +963,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): s = select( [], exists([1], table2.c.otherid == table1.c.myid), from_obj=table1 ) - s.column.non_generative(s, table1) + s.add_columns.non_generative(s, table1) self.assert_compile( s, "SELECT mytable.myid, mytable.name, " @@ -4932,7 +4932,7 @@ class ResultMapTest(fixtures.TestBase): orig = [t.c.x, t.c.y, l1, l2, l3] stmt = select(orig) wrapped = stmt._generate() - wrapped = wrapped.column( + wrapped = wrapped.add_columns( func.ROW_NUMBER().over(order_by=t.c.z) ).alias() @@ -4968,7 +4968,7 @@ class ResultMapTest(fixtures.TestBase): eq_(len(stmt._columns_plus_names), 7) wrapped = stmt._generate() - wrapped = wrapped.column( + wrapped = wrapped.add_columns( func.ROW_NUMBER().over(order_by=t.c.z) ).alias() diff --git a/test/sql/test_deprecations.py b/test/sql/test_deprecations.py index 4e88dcdb8..b2b1f470b 100644 --- a/test/sql/test_deprecations.py +++ b/test/sql/test_deprecations.py @@ -132,6 +132,17 @@ class DeprecationWarningsTest(fixtures.TestBase, AssertsCompiledSQL): ): self.assert_compile(or_(and_()), "") + def test_fromclause_count(self): + with testing.expect_deprecated( + r"The FromClause.count\(\) method is deprecated, and will be " + r"removed in a future release." + ): + self.assert_compile( + table("q", column("x")).count(), + "SELECT count(q.x) AS tbl_row_count FROM q", + dialect="default", + ) + class ConvertUnicodeDeprecationTest(fixtures.TestBase): @@ -645,6 +656,16 @@ class SelectableTest(fixtures.TestBase, AssertsCompiledSQL): "SELECT anon_1.a FROM (SELECT 1 AS a ORDER BY 1) AS anon_1", ) + def test_column(self): + stmt = select([column("x")]) + with testing.expect_deprecated( + r"The Select.column\(\) method is deprecated and will be " + "removed in a future release." + ): + stmt = stmt.column(column("q")) + + self.assert_compile(stmt, "SELECT x, q") + def test_append_column_after_replace_selectable(self): basesel = select([literal_column("1").label("a")]) tojoin = select( diff --git a/test/sql/test_external_traversal.py b/test/sql/test_external_traversal.py index 7001f757f..84d99d886 100644 --- a/test/sql/test_external_traversal.py +++ b/test/sql/test_external_traversal.py @@ -1831,7 +1831,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile( s, "SELECT table1.col1, table1.col2, " "table1.col3 FROM table1" ) - select_copy = s.column(column("yyy")) + select_copy = s.add_columns(column("yyy")) self.assert_compile( select_copy, "SELECT table1.col1, table1.col2, " "table1.col3, yyy FROM table1", diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index c3655efd2..cc2df16a9 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -346,8 +346,10 @@ class SelectableTest( sel = select([literal_column("1").label("a")]) eq_(list(sel.selected_columns.keys()), ["a"]) cloned = visitors.ReplacingCloningVisitor().traverse(sel) - cloned.column.non_generative(cloned, literal_column("2").label("b")) - cloned.column.non_generative(cloned, func.foo()) + cloned.add_columns.non_generative( + cloned, literal_column("2").label("b") + ) + cloned.add_columns.non_generative(cloned, func.foo()) eq_(list(cloned.selected_columns.keys()), ["a", "b", "foo()"]) def test_clone_col_list_changes_then_proxy(self): @@ -355,7 +357,7 @@ class SelectableTest( stmt = select([t.c.q]).subquery() def add_column(stmt): - stmt.column.non_generative(stmt, t.c.p) + stmt.add_columns.non_generative(stmt, t.c.p) stmt2 = visitors.cloned_traverse(stmt, {}, {"select": add_column}) eq_(list(stmt.c.keys()), ["q"]) @@ -366,7 +368,7 @@ class SelectableTest( stmt = select([t.c.q]).subquery() def add_column(stmt): - stmt.column.non_generative(stmt, t.c.p) + stmt.add_columns.non_generative(stmt, t.c.p) stmt2 = visitors.cloned_traverse(stmt, {}, {"select": add_column}) eq_(list(stmt.c.keys()), ["q"]) @@ -396,7 +398,7 @@ class SelectableTest( "JOIN (SELECT 1 AS a, 2 AS b) AS joinfrom " "ON basefrom.a = joinfrom.a", ) - replaced.column.non_generative(replaced, joinfrom.c.b) + replaced.add_columns.non_generative(replaced, joinfrom.c.b) self.assert_compile( replaced, "SELECT basefrom.a, joinfrom.b FROM (SELECT 1 AS a) AS basefrom " @@ -859,7 +861,7 @@ class SelectableTest( def test_join(self): a = join(table1, table2) - print(str(a.select(use_labels=True))) + print(str(a.select().apply_labels())) b = table2.alias("b") j = join(a, b) print(str(j)) @@ -874,7 +876,7 @@ class SelectableTest( self.assert_(criterion.compare(j.onclause)) def test_subquery_labels_join(self): - a = table1.select(use_labels=True).subquery() + a = table1.select().apply_labels().subquery() j = join(a, table2) criterion = a.c.table1_col1 == table2.c.col2 @@ -1580,7 +1582,7 @@ class JoinConditionTest(fixtures.TestBase, AssertsCompiledSQL): t1t2 = t1.join(t2) t2t3 = t2.join(t3) - st2t3 = t2t3.select(use_labels=True).subquery() + st2t3 = t2t3.select().apply_labels().subquery() j = t1t2.join(st2t3) assert j.onclause.compare(t2.c.id == st2t3.c.t3_t2id) self.assert_compile( @@ -2016,7 +2018,8 @@ class ReduceTest(fixtures.TestBase, AssertsExecutionResults): pjoin = ( people.outerjoin(engineers) .outerjoin(managers) - .select(use_labels=True) + .select() + .apply_labels() .alias("pjoin") ) eq_( diff --git a/test/sql/test_text.py b/test/sql/test_text.py index ae4be65ad..58de41709 100644 --- a/test/sql/test_text.py +++ b/test/sql/test_text.py @@ -91,8 +91,7 @@ class SelectCompositionTest(fixtures.TestBase, AssertsCompiledSQL): def test_select_composition_two(self): s = select() - s = s.column(column("column1")) - s = s.column(column("column2")) + s = s.add_columns(column("column1"), column("column2")) s = s.where(text("column1=12")) s = s.where(text("column2=19")) s = s.order_by("column1") diff --git a/test/sql/test_update.py b/test/sql/test_update.py index 0313db832..68db6270f 100644 --- a/test/sql/test_update.py +++ b/test/sql/test_update.py @@ -505,7 +505,7 @@ class UpdateTest(_UpdateFromTestBase, fixtures.TablesTest, AssertsCompiledSQL): column_keys=["j"], ) - def test_update_ordered_parameters_1(self): + def test_update_ordered_parameters_oldstyle_1(self): table1 = self.tables.mytable # Confirm that we can pass values as list value pairs @@ -534,7 +534,35 @@ class UpdateTest(_UpdateFromTestBase, fixtures.TablesTest, AssertsCompiledSQL): "mytable.name = :param_2 || mytable.name || :param_3", ) - def test_update_ordered_parameters_2(self): + def test_update_ordered_parameters_newstyle_1(self): + table1 = self.tables.mytable + + # Confirm that we can pass values as list value pairs + # note these are ordered *differently* from table.c + values = [ + (table1.c.name, table1.c.name + "lala"), + (table1.c.myid, func.do_stuff(table1.c.myid, literal("hoho"))), + ] + self.assert_compile( + update(table1) + .where( + (table1.c.myid == func.hoho(4)) + & ( + table1.c.name + == literal("foo") + table1.c.name + literal("lala") + ) + ) + .ordered_values(*values), + "UPDATE mytable " + "SET " + "name=(mytable.name || :name_1), " + "myid=do_stuff(mytable.myid, :param_1) " + "WHERE " + "mytable.myid = hoho(:hoho_1) AND " + "mytable.name = :param_2 || mytable.name || :param_3", + ) + + def test_update_ordered_parameters_oldstyle_2(self): table1 = self.tables.mytable # Confirm that we can pass values as list value pairs @@ -564,6 +592,35 @@ class UpdateTest(_UpdateFromTestBase, fixtures.TablesTest, AssertsCompiledSQL): "mytable.name = :param_2 || mytable.name || :param_3", ) + def test_update_ordered_parameters_newstyle_2(self): + table1 = self.tables.mytable + + # Confirm that we can pass values as list value pairs + # note these are ordered *differently* from table.c + values = [ + (table1.c.name, table1.c.name + "lala"), + ("description", "some desc"), + (table1.c.myid, func.do_stuff(table1.c.myid, literal("hoho"))), + ] + self.assert_compile( + update( + table1, + (table1.c.myid == func.hoho(4)) + & ( + table1.c.name + == literal("foo") + table1.c.name + literal("lala") + ), + ).ordered_values(*values), + "UPDATE mytable " + "SET " + "name=(mytable.name || :name_1), " + "description=:description, " + "myid=do_stuff(mytable.myid, :param_1) " + "WHERE " + "mytable.myid = hoho(:hoho_1) AND " + "mytable.name = :param_2 || mytable.name || :param_3", + ) + def test_update_ordered_parameters_fire_onupdate(self): table = self.tables.update_w_default |
