本文整理汇总了Python中citest.base.JournalLogger.execute_in_context方法的典型用法代码示例。如果您正苦于以下问题:Python JournalLogger.execute_in_context方法的具体用法?Python JournalLogger.execute_in_context怎么用?Python JournalLogger.execute_in_context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类citest.base.JournalLogger
的用法示例。
在下文中一共展示了JournalLogger.execute_in_context方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: call_method
# 需要导入模块: from citest.base import JournalLogger [as 别名]
# 或者: from citest.base.JournalLogger import execute_in_context [as 别名]
def call_method(self, method, context, *pos_args, **kwargs):
"""Invokes method and returns result.
This is a wrapper around calling the method that will log the
call and result.
Args:
method: callable method to invoke with *pos_args and **kwargs.
context: [ExecutionContext]
pos_args: [list] positional arguments to pass to method.
kwargs: [kwargs]to pass to method.
_citest_log
Raises:
Exceptions thrown by method
Returns:
result of method
"""
if hasattr(method, 'im_class'):
method_name = '{0}.{1}'.format(method.im_class.__name__,
method.im_func.__name__)
else:
method_name = str(method)
return JournalLogger.execute_in_context(
'Call {0}'.format(method_name),
lambda: self.__do_call_method(
method_name, method, context, *pos_args, **kwargs))
示例2: test_context_logging
# 需要导入模块: from citest.base import JournalLogger [as 别名]
# 或者: from citest.base.JournalLogger import execute_in_context [as 别名]
def test_context_logging(self):
offset = len(_journal_file.getvalue())
logger = JournalLogger('test_journal_logger')
logger.addHandler(JournalLogHandler(path=None))
citest_extra = {'foo':'bar'}
start_time = _journal_clock.last_time
JournalLogger.execute_in_context(
'The Test Context',
lambda: {logger.debug('Test Log Message')},
**citest_extra)
expect_sequence = [
{
'_title': 'The Test Context',
'_type': 'JournalContextControl',
'_timestamp': start_time + 1,
'_thread': current_thread().ident,
'control': 'BEGIN',
'foo': 'bar',
},
{
'_value': 'Test Log Message',
'_type': 'JournalMessage',
'_level': logging.DEBUG,
'_timestamp': start_time + 2,
'_thread': current_thread().ident,
'format': 'pre'
},
{
'_type': 'JournalContextControl',
'_timestamp': start_time + 3,
'_thread': current_thread().ident,
'control': 'END'
}
]
entry_str = _journal_file.getvalue()[offset:]
input_stream = RecordInputStream(BytesIO(entry_str))
for expect in expect_sequence:
json_str = next(input_stream)
json_dict = json_module.JSONDecoder().decode(json_str)
self.assertEqual(expect, json_dict)
示例3: invoke_resource
# 需要导入模块: from citest.base import JournalLogger [as 别名]
# 或者: from citest.base.JournalLogger import execute_in_context [as 别名]
def invoke_resource(self, context, method, resource_type,
resource_id=None, **kwargs):
"""Invoke a method on a resource type or instance.
Args:
method: [string] The operation to perform as named under the
|resource_type| in the discovery document.
resource_type: [string] The type of the resource instance to operate on.
resource_id: [string] The id of the resource instance, or None to operate
on the resource type or collection.
kwargs: [kwargs] Additional parameters may be required depending
on the resource type and method.
"""
return JournalLogger.execute_in_context(
'Invoke "{method}" {type}'.format(method=method, type=resource_type),
lambda: self.__do_invoke_resource(
context, method, resource_type,
resource_id=resource_id, **kwargs))
示例4: list_resource
# 需要导入模块: from citest.base import JournalLogger [as 别名]
# 或者: from citest.base.JournalLogger import execute_in_context [as 别名]
def list_resource(self, context, resource_type, method_variant='list',
item_list_transform=None, **kwargs):
"""List the contents of the specified resource.
Args:
resource_type: [string] The name of the resource to list.
method_variant: [string] The API method name to invoke.
item_list_transform: [lambda items] Converts the list of items into
a result list, or None for the identity.
kwargs: [kwargs] Additional parameters may be required depending
on the resource type (such as zone, etc).
Returns:
A list of resources.
"""
return JournalLogger.execute_in_context(
'List {}'.format(resource_type),
lambda: self.__do_list_resource(
context, resource_type, method_variant=method_variant,
item_list_transform=item_list_transform, **kwargs))