From: Adrien Berchet Date: Tue, 2 Apr 2019 16:47:41 +0000 (+0200) Subject: Fix if statement and update tests. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=537fa192fa77f979fe2502bacf8809b20c29b9c7;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix if statement and update tests. --- diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py index 3c268a5972..ed3fbaf2f4 100644 --- a/lib/sqlalchemy/sql/functions.py +++ b/lib/sqlalchemy/sql/functions.py @@ -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] ): diff --git a/test/sql/test_deprecations.py b/test/sql/test_deprecations.py index 2df211a0fb..27cd8dcc53 100644 --- a/test/sql/test_deprecations.py +++ b/test/sql/test_deprecations.py @@ -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):