當前位置: 首頁>>代碼示例>>Python>>正文


Python JournalLogger.execute_in_context方法代碼示例

本文整理匯總了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))
開發者ID:ewiseblatt,項目名稱:citest,代碼行數:29,代碼來源:aws_python_agent.py

示例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)
開發者ID:ewiseblatt,項目名稱:citest,代碼行數:45,代碼來源:journal_logger_test.py

示例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))
開發者ID:ewiseblatt,項目名稱:citest,代碼行數:20,代碼來源:gcp_agent.py

示例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))
開發者ID:ewiseblatt,項目名稱:citest,代碼行數:22,代碼來源:gcp_agent.py


注:本文中的citest.base.JournalLogger.execute_in_context方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。