]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix if statement and update tests.
authorAdrien Berchet <adrien.berchet@gmail.com>
Tue, 2 Apr 2019 16:47:41 +0000 (18:47 +0200)
committerAdrien Berchet <adrien.berchet@gmail.com>
Tue, 2 Apr 2019 16:47:41 +0000 (18:47 +0200)
lib/sqlalchemy/sql/functions.py
test/sql/test_deprecations.py

index 3c268a59723e5a42c4336aefc4c5971975335207..ed3fbaf2f4d95bb5d5e94b7e1d763454a30270ab 100644 (file)
@@ -60,7 +60,7 @@ def register_function(identifier, fn, package="_default"):
     identifier = identifier.lower()
 
     # Check if a function with the same lowercase identifier is registered.
-    if identifier in _registry[package]:
+    if identifier in _case_sensitive_reg[package]:
         if (
             raw_identifier not in _case_sensitive_reg[package][identifier]
         ):
index 2df211a0fbc88ef3aeb444668283658885fb9771..27cd8dcc53a66cc2b6809d2cf389dfe512bb24cd 100644 (file)
@@ -154,6 +154,9 @@ class DeprecationWarningsTest(fixtures.TestBase):
             )
 
     def test_case_sensitive(self):
+        reg = functions._registry
+        cs_reg = functions._case_sensitive_reg
+
         class MYFUNC(GenericFunction):
             type = DateTime
 
@@ -162,6 +165,12 @@ class DeprecationWarningsTest(fixtures.TestBase):
         assert isinstance(func.mYfUnC().type, DateTime)
         assert isinstance(func.myfunc().type, DateTime)
 
+        assert "myfunc" in reg['_default']
+        assert "MYFUNC" not in reg['_default']
+        assert "MyFunc" not in reg['_default']
+        assert "myfunc" in cs_reg['_default']
+        assert cs_reg['_default']['myfunc'] == ['MYFUNC']
+
         with testing.expect_deprecated():
             class MyFunc(GenericFunction):
                 type = Integer
@@ -173,38 +182,75 @@ class DeprecationWarningsTest(fixtures.TestBase):
         with pytest.raises(AssertionError):
             assert isinstance(func.myfunc().type, Integer)
 
+        assert "myfunc" not in reg['_default']
+        assert "MYFUNC" in reg['_default']
+        assert "MyFunc" in reg['_default']
+        assert "myfunc" in cs_reg['_default']
+        assert cs_reg['_default']['myfunc'] == ['MYFUNC', 'MyFunc']
+
     def test_replace_function_case_sensitive(self):
+        reg = functions._registry
+        cs_reg = functions._case_sensitive_reg
 
-        class replacable_func(GenericFunction):
-            __return_type__ = Integer
-            identifier = 'replacable_func'
+        class replaceable_func(GenericFunction):
+            type = Integer
+            identifier = 'REPLACEABLE_FUNC'
 
-        assert isinstance(func.Replacable_Func().type, Integer)
-        assert isinstance(func.RePlAcaBlE_fUnC().type, Integer)
-        assert isinstance(func.replacable_func().type, Integer)
+        assert isinstance(func.REPLACEABLE_FUNC().type, Integer)
+        assert isinstance(func.Replaceable_Func().type, Integer)
+        assert isinstance(func.RePlAcEaBlE_fUnC().type, Integer)
+        assert isinstance(func.replaceable_func().type, Integer)
 
-        with testing.expect_deprecated():
-            class Replacable_Func(GenericFunction):
-                __return_type__ = DateTime
-                identifier = 'Replacable_Func'
+        assert "replaceable_func" in reg['_default']
+        assert "REPLACEABLE_FUNC" not in reg['_default']
+        assert "Replaceable_Func" not in reg['_default']
+        assert "replaceable_func" in cs_reg['_default']
+        assert cs_reg['_default']['replaceable_func'] == ['REPLACEABLE_FUNC']
 
-        assert isinstance(func.Replacable_Func().type, DateTime)
-        assert isinstance(func.RePlAcaBlE_fUnC().type, NullType)
-        assert isinstance(func.replacable_func().type, Integer)
+        with testing.expect_deprecated():
+            class Replaceable_Func(GenericFunction):
+                type = DateTime
+                identifier = 'Replaceable_Func'
+
+        assert isinstance(func.REPLACEABLE_FUNC().type, Integer)
+        assert isinstance(func.Replaceable_Func().type, DateTime)
+        assert isinstance(func.RePlAcEaBlE_fUnC().type, NullType)
+        assert isinstance(func.replaceable_func().type, NullType)
+
+        assert "replaceable_func" not in reg['_default']
+        assert "REPLACEABLE_FUNC" in reg['_default']
+        assert "Replaceable_Func" in reg['_default']
+        assert "replaceable_func" in cs_reg['_default']
+        assert cs_reg['_default']['replaceable_func'] == ['REPLACEABLE_FUNC',
+                                                          'Replaceable_Func']
 
         with expect_warnings():
-            class replacable_func_override(GenericFunction):
-                __return_type__ = DateTime
-                identifier = 'replacable_func'
+            class replaceable_func_override(GenericFunction):
+                type = DateTime
+                identifier = 'REPLACEABLE_FUNC'
 
-        with expect_warnings():
-            class Replacable_Func_override(GenericFunction):
-                __return_type__ = Integer
-                identifier = 'Replacable_Func'
+        with testing.expect_deprecated():
+            class replaceable_func_lowercase(GenericFunction):
+                type = String
+                identifier = 'replaceable_func'
 
-        assert isinstance(func.Replacable_Func().type, Integer)
-        assert isinstance(func.RePlAcaBlE_fUnC().type, NullType)
-        assert isinstance(func.replacable_func().type, DateTime)
+        with expect_warnings():
+            class Replaceable_Func_override(GenericFunction):
+                type = Integer
+                identifier = 'Replaceable_Func'
+
+        assert isinstance(func.REPLACEABLE_FUNC().type, DateTime)
+        assert isinstance(func.Replaceable_Func().type, Integer)
+        assert isinstance(func.RePlAcEaBlE_fUnC().type, NullType)
+        assert isinstance(func.replaceable_func().type, String)
+
+        assert "replaceable_func" in reg['_default']
+        assert "REPLACEABLE_FUNC" in reg['_default']
+        assert "Replaceable_Func" in reg['_default']
+        assert "replaceable_func" in cs_reg['_default']
+        assert cs_reg['_default']['replaceable_func'] == ['REPLACEABLE_FUNC',
+                                                          'Replaceable_Func',
+                                                          'replaceable_func']
 
 
 class DDLListenerDeprecationsTest(fixtures.TestBase):