summaryrefslogtreecommitdiff
path: root/oslo
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2014-09-16 13:02:10 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2014-09-19 13:03:26 -0700
commitfc8eb627a7dd20a7c3f2e17cda55a72e66c04bf4 (patch)
tree93e209df4204ebbcd8887ee9aaa82fa1be0ce060 /oslo
parentcc7ae9fecc705924c4dc1d8d104338afc0e2437e (diff)
downloadoslo-db-fc8eb627a7dd20a7c3f2e17cda55a72e66c04bf4.tar.gz
Use __qualname__ if we can
Due to pep-3155 functions and methods will now have more uniform qualified names that we can and should use when we can (mainly applicable to python 3.x). Once https://review.openstack.org/#/c/122495/ goes in we can just use that module instead to get similar functionality. Change-Id: Iea9e74aca38aa79c9294fd6e786551e91143900c
Diffstat (limited to 'oslo')
-rw-r--r--oslo/db/sqlalchemy/test_base.py3
-rw-r--r--oslo/db/sqlalchemy/utils.py25
2 files changed, 27 insertions, 1 deletions
diff --git a/oslo/db/sqlalchemy/test_base.py b/oslo/db/sqlalchemy/test_base.py
index 849e726..4aa6cb6 100644
--- a/oslo/db/sqlalchemy/test_base.py
+++ b/oslo/db/sqlalchemy/test_base.py
@@ -91,7 +91,8 @@ def backend_specific(*dialects):
if self.engine.name not in dialects:
msg = ('The test "%s" can be run '
'only on %s. Current engine is %s.')
- args = (f.__name__, ' '.join(dialects), self.engine.name)
+ args = (utils.get_callable_name(f), ' '.join(dialects),
+ self.engine.name)
self.skip(msg % args)
else:
return f(self)
diff --git a/oslo/db/sqlalchemy/utils.py b/oslo/db/sqlalchemy/utils.py
index 3edd8dd..adc9bef 100644
--- a/oslo/db/sqlalchemy/utils.py
+++ b/oslo/db/sqlalchemy/utils.py
@@ -54,6 +54,31 @@ LOG = logging.getLogger(__name__)
_DBURL_REGEX = re.compile(r"[^:]+://([^:]+):([^@]+)@.+")
+def get_callable_name(function):
+ # TODO(harlowja): Replace this once
+ # it is possible to use https://review.openstack.org/#/c/122495/ which is
+ # a more complete and expansive module that does a similar thing...
+ try:
+ method_self = six.get_method_self(function)
+ except AttributeError:
+ method_self = None
+ if method_self is not None:
+ if isinstance(method_self, six.class_types):
+ im_class = method_self
+ else:
+ im_class = type(method_self)
+ try:
+ parts = (im_class.__module__, function.__qualname__)
+ except AttributeError:
+ parts = (im_class.__module__, im_class.__name__, function.__name__)
+ else:
+ try:
+ parts = (function.__module__, function.__qualname__)
+ except AttributeError:
+ parts = (function.__module__, function.__name__)
+ return '.'.join(parts)
+
+
def sanitize_db_url(url):
match = _DBURL_REGEX.match(url)
if match: