summaryrefslogtreecommitdiff
path: root/test/sql/test_functions.py
diff options
context:
space:
mode:
authorAdrien Berchet <adrien.berchet@gmail.com>2019-05-03 12:02:17 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-05-06 17:41:34 -0400
commit61c47cbdc6058c040b301caa0864710a8d85d3a4 (patch)
tree109d512de7613f2f8496e285b39426b485321d2b /test/sql/test_functions.py
parent1c3e92627362604472ca483055fc827a97942e6b (diff)
downloadsqlalchemy-61c47cbdc6058c040b301caa0864710a8d85d3a4.tar.gz
Do not register the GenericFunction in sql.functions._registry
Fixed that the :class:`.GenericFunction` class was inadvertently registering itself as one of the named functions. Pull request courtesy Adrien Berchet. Fixes: #4653 Closes: #4654 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4654 Pull-request-sha: 1112b89f0d5af8cd5ba88cef744698a79dbdb963 Change-Id: Ia0d366d3bff44a763aa496287814278dff732a19
Diffstat (limited to 'test/sql/test_functions.py')
-rw-r--r--test/sql/test_functions.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/sql/test_functions.py b/test/sql/test_functions.py
index ac711c669..d2cf1d50a 100644
--- a/test/sql/test_functions.py
+++ b/test/sql/test_functions.py
@@ -1075,3 +1075,43 @@ def exec_sorted(statement, *args, **kw):
return sorted(
[tuple(row) for row in statement.execute(*args, **kw).fetchall()]
)
+
+
+class RegisterTest(fixtures.TestBase, AssertsCompiledSQL):
+ __dialect__ = "default"
+
+ def setup(self):
+ self._registry = deepcopy(functions._registry)
+
+ def teardown(self):
+ functions._registry = self._registry
+
+ def test_GenericFunction_is_registered(self):
+ assert 'GenericFunction' not in functions._registry['_default']
+
+ def test_register_function(self):
+
+ # test generic function registering
+ class registered_func(GenericFunction):
+ _register = True
+
+ def __init__(self, *args, **kwargs):
+ GenericFunction.__init__(self, *args, **kwargs)
+
+ class registered_func_child(registered_func):
+ type = sqltypes.Integer
+
+ assert 'registered_func' in functions._registry['_default']
+ assert isinstance(func.registered_func_child().type, Integer)
+
+ class not_registered_func(GenericFunction):
+ _register = False
+
+ def __init__(self, *args, **kwargs):
+ GenericFunction.__init__(self, *args, **kwargs)
+
+ class not_registered_func_child(not_registered_func):
+ type = sqltypes.Integer
+
+ assert 'not_registered_func' not in functions._registry['_default']
+ assert isinstance(func.not_registered_func_child().type, Integer)