summaryrefslogtreecommitdiff
path: root/tests/gis_tests/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/gis_tests/utils.py')
-rw-r--r--tests/gis_tests/utils.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/tests/gis_tests/utils.py b/tests/gis_tests/utils.py
index 35c7d366ee..2fbfd438eb 100644
--- a/tests/gis_tests/utils.py
+++ b/tests/gis_tests/utils.py
@@ -12,25 +12,30 @@ def skipUnlessGISLookup(*gis_lookups):
"""
Skip a test unless a database supports all of gis_lookups.
"""
+
def decorator(test_func):
@wraps(test_func)
def skip_wrapper(*args, **kwargs):
if any(key not in connection.ops.gis_operators for key in gis_lookups):
raise unittest.SkipTest(
- "Database doesn't support all the lookups: %s" % ", ".join(gis_lookups)
+ "Database doesn't support all the lookups: %s"
+ % ", ".join(gis_lookups)
)
return test_func(*args, **kwargs)
+
return skip_wrapper
+
return decorator
-_default_db = settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'].rsplit('.')[-1]
+_default_db = settings.DATABASES[DEFAULT_DB_ALIAS]["ENGINE"].rsplit(".")[-1]
# MySQL spatial indices can't handle NULL geometries.
-gisfield_may_be_null = _default_db != 'mysql'
+gisfield_may_be_null = _default_db != "mysql"
class FuncTestMixin:
"""Assert that Func expressions aren't mutated during their as_sql()."""
+
def setUp(self):
def as_sql_wrapper(original_as_sql):
def inner(*args, **kwargs):
@@ -40,9 +45,12 @@ class FuncTestMixin:
func.output_field
__dict__original = copy.deepcopy(func.__dict__)
result = original_as_sql(*args, **kwargs)
- msg = '%s Func was mutated during compilation.' % func.__class__.__name__
+ msg = (
+ "%s Func was mutated during compilation." % func.__class__.__name__
+ )
self.assertEqual(func.__dict__, __dict__original, msg)
return result
+
return inner
def __getattribute__(self, name):
@@ -51,12 +59,14 @@ class FuncTestMixin:
try:
as_sql = __getattribute__original(self, vendor_impl)
except AttributeError:
- as_sql = __getattribute__original(self, 'as_sql')
+ as_sql = __getattribute__original(self, "as_sql")
return as_sql_wrapper(as_sql)
- vendor_impl = 'as_' + connection.vendor
+ vendor_impl = "as_" + connection.vendor
__getattribute__original = Func.__getattribute__
- self.func_patcher = mock.patch.object(Func, '__getattribute__', __getattribute__)
+ self.func_patcher = mock.patch.object(
+ Func, "__getattribute__", __getattribute__
+ )
self.func_patcher.start()
super().setUp()