]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix PEP8 and tests.
authorAdrien Berchet <adrien.berchet@gmail.com>
Thu, 28 Mar 2019 17:32:00 +0000 (18:32 +0100)
committerAdrien Berchet <adrien.berchet@gmail.com>
Thu, 28 Mar 2019 17:32:00 +0000 (18:32 +0100)
lib/sqlalchemy/sql/functions.py
test/sql/test_functions.py

index c914b3dd630504d6811ae4c61834dc82ae6a78ce..d104925a33fc4de8c82fce1a9da4b723f1d14795 100644 (file)
@@ -71,9 +71,9 @@ def register_function(identifier, fn, package="_default"):
                     raw_identifier),
                 sa_exc.SADeprecationWarning)
         else:
-                warnings.warn(
-                    "The GenericFunction '{}' is already registered and "
-                    "is going to be overriden.".format(identifier))
+            warnings.warn(
+                "The GenericFunction '{}' is already registered and "
+                "is going to be overriden.".format(identifier))
 
         # If a function with the same lowercase identifier is registered, then
         # these 2 functions are considered as case-sensitive.
index 0518ee4e49b56404648d719762b8be5149e54801..311b476a806a59dc6d8f9e4c831bf69af9f5f90a 100644 (file)
@@ -1,5 +1,7 @@
+from copy import deepcopy
 import datetime
 import decimal
+
 import pytest
 
 from sqlalchemy import ARRAY
@@ -55,9 +57,13 @@ table1 = table(
 class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
     __dialect__ = "default"
 
-    def tear_down(self):
-        functions._registry.clear()
-        functions._case_sensitive_functions.clear()
+    def setup_method(self):
+        self._registry = deepcopy(functions._registry)
+        self._case_sensitive_reg = deepcopy(functions._case_sensitive_reg)
+
+    def teardown_method(self):
+        functions._registry = self._registry
+        functions._case_sensitive_reg = self._case_sensitive_reg
 
     def test_compile(self):
         for dialect in all_dialects(exclude=("sybase",)):
@@ -222,6 +228,26 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
 
         assert isinstance(func.myfunc().type, DateTime)
 
+    def test_case_sensitive(self):
+        class MYFUNC(GenericFunction):
+            type = DateTime
+
+        assert isinstance(func.MYFUNC().type, DateTime)
+        assert isinstance(func.MyFunc().type, DateTime)
+        assert isinstance(func.mYfUnC().type, DateTime)
+        assert isinstance(func.myfunc().type, DateTime)
+
+        with testing.expect_deprecated():
+            class MyFunc(GenericFunction):
+                type = Integer
+
+        assert isinstance(func.MYFUNC().type, DateTime)
+        assert isinstance(func.MyFunc().type, Integer)
+        with pytest.raises(AssertionError):
+            assert isinstance(func.mYfUnC().type, Integer)
+        with pytest.raises(AssertionError):
+            assert isinstance(func.myfunc().type, Integer)
+
     def test_replace_function(self):
 
         class replacable_func(GenericFunction):
@@ -253,18 +279,6 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
         assert isinstance(func.RePlAcaBlE_fUnC().type, NullType)
         assert isinstance(func.replacable_func().type, DateTime)
 
-    def test_custom_legacy_case_sensitive(self):
-        # in case someone was using this system
-        with testing.expect_deprecated():
-            class MyFunc(GenericFunction):
-                __return_type__ = Integer
-
-        assert isinstance(func.MyFunc().type, Integer)
-        with pytest.raises(AssertionError):
-            assert isinstance(func.mYfUnC().type, Integer)
-        with pytest.raises(AssertionError):
-            assert isinstance(func.myfunc().type, Integer)
-
     def test_custom_w_custom_name(self):
         class myfunc(GenericFunction):
             name = "notmyfunc"