From: Adrien Berchet Date: Thu, 28 Mar 2019 17:32:00 +0000 (+0100) Subject: Fix PEP8 and tests. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c84dc82b8937dcbd9219ea6601820cf5402be5d;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix PEP8 and tests. --- diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py index c914b3dd63..d104925a33 100644 --- a/lib/sqlalchemy/sql/functions.py +++ b/lib/sqlalchemy/sql/functions.py @@ -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. diff --git a/test/sql/test_functions.py b/test/sql/test_functions.py index 0518ee4e49..311b476a80 100644 --- a/test/sql/test_functions.py +++ b/test/sql/test_functions.py @@ -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"