diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-06-13 12:37:22 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-07-06 13:02:22 -0400 |
| commit | ef7ff058eb67d73ebeac7b125ab2a7806e14629c (patch) | |
| tree | 9a09162961f7bcdb6d16837adacabb99f10b4410 /test/sql/test_functions.py | |
| parent | 1ce98ca83a4b2da12e52aa0f4ab181c83063abc2 (diff) | |
| download | sqlalchemy-ef7ff058eb67d73ebeac7b125ab2a7806e14629c.tar.gz | |
SelectBase no longer a FromClause
As part of the SQLAlchemy 2.0 migration project, a conceptual change has
been made to the role of the :class:`.SelectBase` class hierarchy,
which is the root of all "SELECT" statement constructs, in that they no
longer serve directly as FROM clauses, that is, they no longer subclass
:class:`.FromClause`. For end users, the change mostly means that any
placement of a :func:`.select` construct in the FROM clause of another
:func:`.select` requires first that it be wrapped in a subquery first,
which historically is through the use of the :meth:`.SelectBase.alias`
method, and is now also available through the use of
:meth:`.SelectBase.subquery`. This was usually a requirement in any
case since several databases don't accept unnamed SELECT subqueries
in their FROM clause in any case.
See the documentation in this change for lots more detail.
Fixes: #4617
Change-Id: I0f6174ee24b9a1a4529168e52e855e12abd60667
Diffstat (limited to 'test/sql/test_functions.py')
| -rw-r--r-- | test/sql/test_functions.py | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/test/sql/test_functions.py b/test/sql/test_functions.py index d2cf1d50a..e0efb1008 100644 --- a/test/sql/test_functions.py +++ b/test/sql/test_functions.py @@ -92,7 +92,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): dialect=dialect, ) - functions._registry['_default'].pop('fake_func') + functions._registry["_default"].pop("fake_func") def test_use_labels(self): self.assert_compile( @@ -238,7 +238,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_replace_function(self): class replaceable_func(GenericFunction): type = Integer - identifier = 'replaceable_func' + identifier = "replaceable_func" assert isinstance(func.Replaceable_Func().type, Integer) assert isinstance(func.RePlAcEaBlE_fUnC().type, Integer) @@ -247,11 +247,12 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): with expect_warnings( "The GenericFunction 'replaceable_func' is already registered and " "is going to be overriden.", - regex=False + regex=False, ): + class replaceable_func_override(GenericFunction): type = DateTime - identifier = 'replaceable_func' + identifier = "replaceable_func" assert isinstance(func.Replaceable_Func().type, DateTime) assert isinstance(func.RePlAcEaBlE_fUnC().type, DateTime) @@ -260,7 +261,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_replace_function_case_insensitive(self): class replaceable_func(GenericFunction): type = Integer - identifier = 'replaceable_func' + identifier = "replaceable_func" assert isinstance(func.Replaceable_Func().type, Integer) assert isinstance(func.RePlAcEaBlE_fUnC().type, Integer) @@ -269,11 +270,12 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): with expect_warnings( "The GenericFunction 'replaceable_func' is already registered and " "is going to be overriden.", - regex=False + regex=False, ): + class replaceable_func_override(GenericFunction): type = DateTime - identifier = 'REPLACEABLE_Func' + identifier = "REPLACEABLE_Func" assert isinstance(func.Replaceable_Func().type, DateTime) assert isinstance(func.RePlAcEaBlE_fUnC().type, DateTime) @@ -458,14 +460,14 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): from_obj=[ func.calculate(bindparam("x", None), bindparam("y", None)) ], - ) + ).subquery() self.assert_compile( select([users], users.c.id > calculate.c.z), "SELECT users.id, users.name, users.fullname " "FROM users, (SELECT q, z, r " - "FROM calculate(:x, :y)) " - "WHERE users.id > z", + "FROM calculate(:x, :y)) AS anon_1 " + "WHERE users.id > anon_1.z", ) s = select( @@ -504,8 +506,8 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_select_method_two(self): expr = func.rows("foo") self.assert_compile( - select(["*"]).select_from(expr.select()), - "SELECT * FROM (SELECT rows(:rows_2) AS rows_1)", + select(["*"]).select_from(expr.select().subquery()), + "SELECT * FROM (SELECT rows(:rows_2) AS rows_1) AS anon_1", ) def test_select_method_three(self): @@ -1087,7 +1089,7 @@ class RegisterTest(fixtures.TestBase, AssertsCompiledSQL): functions._registry = self._registry def test_GenericFunction_is_registered(self): - assert 'GenericFunction' not in functions._registry['_default'] + assert "GenericFunction" not in functions._registry["_default"] def test_register_function(self): @@ -1101,7 +1103,7 @@ class RegisterTest(fixtures.TestBase, AssertsCompiledSQL): class registered_func_child(registered_func): type = sqltypes.Integer - assert 'registered_func' in functions._registry['_default'] + assert "registered_func" in functions._registry["_default"] assert isinstance(func.registered_func_child().type, Integer) class not_registered_func(GenericFunction): @@ -1113,5 +1115,5 @@ class RegisterTest(fixtures.TestBase, AssertsCompiledSQL): class not_registered_func_child(not_registered_func): type = sqltypes.Integer - assert 'not_registered_func' not in functions._registry['_default'] + assert "not_registered_func" not in functions._registry["_default"] assert isinstance(func.not_registered_func_child().type, Integer) |
