本文整理匯總了Python中tornado.options.options.mockable方法的典型用法代碼示例。如果您正苦於以下問題:Python options.mockable方法的具體用法?Python options.mockable怎麽用?Python options.mockable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tornado.options.options
的用法示例。
在下文中一共展示了options.mockable方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: mockable
# 需要導入模塊: from tornado.options import options [as 別名]
# 或者: from tornado.options.options import mockable [as 別名]
def mockable(self):
"""Returns a wrapper around self that is compatible with
`mock.patch <unittest.mock.patch>`.
The `mock.patch <unittest.mock.patch>` function (included in
the standard library `unittest.mock` package since Python 3.3,
or in the third-party ``mock`` package for older versions of
Python) is incompatible with objects like ``options`` that
override ``__getattr__`` and ``__setattr__``. This function
returns an object that can be used with `mock.patch.object
<unittest.mock.patch.object>` to modify option values::
with mock.patch.object(options.mockable(), 'name', value):
assert options.name == value
"""
return _Mockable(self)
示例2: mockable
# 需要導入模塊: from tornado.options import options [as 別名]
# 或者: from tornado.options.options import mockable [as 別名]
def mockable(self) -> "_Mockable":
"""Returns a wrapper around self that is compatible with
`mock.patch <unittest.mock.patch>`.
The `mock.patch <unittest.mock.patch>` function (included in
the standard library `unittest.mock` package since Python 3.3,
or in the third-party ``mock`` package for older versions of
Python) is incompatible with objects like ``options`` that
override ``__getattr__`` and ``__setattr__``. This function
returns an object that can be used with `mock.patch.object
<unittest.mock.patch.object>` to modify option values::
with mock.patch.object(options.mockable(), 'name', value):
assert options.name == value
"""
return _Mockable(self)
示例3: __setattr__
# 需要導入模塊: from tornado.options import options [as 別名]
# 或者: from tornado.options.options import mockable [as 別名]
def __setattr__(self, name, value):
assert name not in self._originals, "don't reuse mockable objects"
self._originals[name] = getattr(self._options, name)
setattr(self._options, name, value)
示例4: __setattr__
# 需要導入模塊: from tornado.options import options [as 別名]
# 或者: from tornado.options.options import mockable [as 別名]
def __setattr__(self, name: str, value: Any) -> None:
assert name not in self._originals, "don't reuse mockable objects"
self._originals[name] = getattr(self._options, name)
setattr(self._options, name, value)
示例5: mock_option
# 需要導入模塊: from tornado.options import options [as 別名]
# 或者: from tornado.options.options import mockable [as 別名]
def mock_option(self, name, value):
return mock.patch.object(options.mockable(), name, value)