From a697fcc1cb87b5a4e4f0c70361bd598086f4210f Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 6 Jan 2020 14:09:01 -0500 Subject: Support GenericFunction.name passed as a quoted_name A function created using :class:`.GenericFunction` can now specify that the name of the function should be rendered with or without quotes by assigning the :class:`.quoted_name` construct to the .name element of the object. Prior to 1.3.4, quoting was never applied to function names, and some quoting was introduced in :ticket:`4467` but no means to force quoting for a mixed case name was available. Additionally, the :class:`.quoted_name` construct when used as the name will properly register its lowercase name in the function registry so that the name continues to be available via the ``func.`` registry. Fixes: #5079 Change-Id: I0653ab8b16e75e628ce82dbbc3d0f77f8336c407 --- test/sql/test_functions.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test/sql/test_functions.py') diff --git a/test/sql/test_functions.py b/test/sql/test_functions.py index a46d1af54..6ee8a67b7 100644 --- a/test/sql/test_functions.py +++ b/test/sql/test_functions.py @@ -29,6 +29,7 @@ from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import sqlite from sqlalchemy.sql import column from sqlalchemy.sql import functions +from sqlalchemy.sql import quoted_name from sqlalchemy.sql import table from sqlalchemy.sql.compiler import BIND_TEMPLATES from sqlalchemy.sql.functions import FunctionElement @@ -303,6 +304,21 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): assert isinstance(func.notmyfunc(), myfunc) assert not isinstance(func.myfunc(), myfunc) + def test_custom_w_quoted_name(self): + class myfunc(GenericFunction): + name = quoted_name("NotMyFunc", quote=True) + identifier = "myfunc" + + self.assert_compile(func.myfunc(), '"NotMyFunc"()') + + def test_custom_w_quoted_name_no_identifier(self): + class myfunc(GenericFunction): + name = quoted_name("NotMyFunc", quote=True) + + # note this requires that the quoted name be lower cased for + # correct lookup + self.assert_compile(func.notmyfunc(), '"NotMyFunc"()') + def test_custom_package_namespace(self): def cls1(pk_name): class myfunc(GenericFunction): -- cgit v1.2.1