本文整理汇总了Python中six.get_unbound_function方法的典型用法代码示例。如果您正苦于以下问题:Python six.get_unbound_function方法的具体用法?Python six.get_unbound_function怎么用?Python six.get_unbound_function使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six
的用法示例。
在下文中一共展示了six.get_unbound_function方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_one_stub_duplicated_as_context_manager
# 需要导入模块: import six [as 别名]
# 或者: from six import get_unbound_function [as 别名]
def test_one_stub_duplicated_as_context_manager(self):
original_client_send_request = Client.send_request
original_client_get_all_responses = Client.get_all_responses
stub = stub_action('test_service', 'test_action_1', body={'value': 1})
with stub as stub_test_action_1, stub as second_stub_test_action_1:
response = self.client.call_action('test_service', 'test_action_1')
# Check stub is correctly reverted
for client_func, original_func in (
(Client.send_request, original_client_send_request),
(Client.get_all_responses, original_client_get_all_responses),
):
self.assertTrue(
six.get_unbound_function(client_func) is six.get_unbound_function(original_func) # type: ignore
)
self.assertEqual({'value': 1}, response.body)
self.assertTrue(stub_test_action_1 is second_stub_test_action_1)
self.assertEqual(1, stub_test_action_1.call_count)
self.assertEqual({}, stub_test_action_1.call_body)
stub_test_action_1.assert_called_once_with({})
示例2: get_unbound_function
# 需要导入模块: import six [as 别名]
# 或者: from six import get_unbound_function [as 别名]
def get_unbound_function(unbound):
# Op.make_thunk isn't bound, so don't have a __func__ attr.
# But bound method, have a __func__ method that point to the
# not bound method. That is what we want.
if hasattr(unbound, '__func__'):
return unbound.__func__
return unbound
示例3: autodoc
# 需要导入模块: import six [as 别名]
# 或者: from six import get_unbound_function [as 别名]
def autodoc(base_doc="", classess=DEFAULT_CLASSESS, add_classess=None, skip_classess=None):
def copy_method(cls, method_name, method):
""" create facade for a method with preservation of original docstring """
@wraps(method)
def shadow_method(self, *args, **kwargs):
return method(self, *args, **kwargs)
shadow_method.__doc__ = method.__doc__
setattr(cls, method_name, shadow_method)
def wrapped(cls):
applies_to = set([])
classess_to_apply = [c for c in classess if not skip_classess or c not in skip_classess]
if add_classess:
classess_to_apply += [c for c in add_classess if not skip_classess or c not in skip_classess]
for autodoc_class in classess_to_apply:
applies_to |= set(autodoc_class.applies_to)
# Create facades for original methods - docstring of methods are immutable, so we need to change docstring of
# functions. But without shadowing the method.__func__ will point to the same function for classes that
# inherits them from the same parents.
for method_name in applies_to:
method = getattr(cls, method_name, None)
if method:
copy_method(cls, method_name, method)
# update docstrings
for autodoc_class in classess_to_apply:
for method_name in autodoc_class.applies_to:
method = getattr(cls, method_name, None)
if method:
six.get_unbound_function(method).__doc__ = \
autodoc_class.update_docstring(cls, base_doc, six.get_unbound_function(method).__doc__,
method_name)
return cls
return wrapped
示例4: test_get_unbound_function
# 需要导入模块: import six [as 别名]
# 或者: from six import get_unbound_function [as 别名]
def test_get_unbound_function():
class X(object):
def m(self):
pass
assert six.get_unbound_function(X.m) is X.__dict__["m"]
示例5: __getattr__
# 需要导入模块: import six [as 别名]
# 或者: from six import get_unbound_function [as 别名]
def __getattr__(self, name):
if name in (_[0] for _ in getmembers(UserEditable, predicate=isroutine)) and \
self.is_content_editable:
self._content_editable = True
setattr(self, name, six.create_bound_method(
six.get_unbound_function(getattr(UserEditable, name)), self))
return getattr(self, name)
else:
raise AttributeError("Element '{}' has no attribute "
"'{}'".format(self.__class__.__name__.capitalize(), name))