当前位置: 首页>>代码示例>>Python>>正文


Python attr.s方法代码示例

本文整理汇总了Python中attr.s方法的典型用法代码示例。如果您正苦于以下问题:Python attr.s方法的具体用法?Python attr.s怎么用?Python attr.s使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在attr的用法示例。


在下文中一共展示了attr.s方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_default_service

# 需要导入模块: import attr [as 别名]
# 或者: from attr import s [as 别名]
def get_default_service(self):
        """
        Get one of the chute's services designated as the default one.

        This is more for convenience with existing API functions where the
        caller did not need to specify a service because prior to 0.12.0,
        chutes could only have one Docker container. We use some heuristics
        such as the service's name is "main" to identify one of the services as
        the default.
        """
        if "main" in self.services:
            return self.services['main']

        # Sort by name and return the first one.
        name = min(self.services)
        return self.services[name] 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:18,代码来源:chute.py

示例2: print_summary

# 需要导入模块: import attr [as 别名]
# 或者: from attr import s [as 别名]
def print_summary(summary):

    print('The output is valid.')
    print('It contained {} messages for {} streams.'.format(
        summary.num_messages(), len(summary.streams)))
    print('')
    print('{:7} schema messages'.format(summary.num_schemas()))
    print('{:7} record messages'.format(summary.num_records()))
    print('{:7} state messages'.format(summary.num_states))
    print('')
    print('Details by stream:')
    headers = [['stream', 'records', 'schemas']]
    rows = [[s.name, s.num_records, s.num_schemas]
            for s in summary.streams.values()]
    data = headers + rows

    table = AsciiTable(data)
    print(table.table) 
开发者ID:singer-io,项目名称:singer-tools,代码行数:20,代码来源:check_tap.py

示例3: mock_get_swarm

# 需要导入模块: import attr [as 别名]
# 或者: from attr import s [as 别名]
def mock_get_swarm(self, job_def, task_id=None):
    """Mocks the initial job.Definition for the given `led get-swarm` call.

    Args:
      * job_def (job.Definition|None) - The initial job value. If `None`, then
        this marks the builder as non-existant, and the `led get-builder` call
        will be simulated to have an exit code of 1.
      * task_id (str|None) - The swarming task ID for the build or None to
        provide the default basis for all get-swarm calls.

    Returns TestData which can be added to a recipe test case.
    """
    assert isinstance(job_def, (job.Definition, type(None)))
    ret = None
    if job_def is not None:
      ret = job.Definition()
      ret.CopyFrom(job_def)
    key = 'get:swarming/task'
    if task_id:
      key += '/%s' % (task_id,)
    return self._singleton_mod_data(key, ret) 
开发者ID:luci,项目名称:recipes-py,代码行数:23,代码来源:test_api.py

示例4: _derive_build_ids

# 需要导入模块: import attr [as 别名]
# 或者: from attr import s [as 别名]
def _derive_build_ids(build):
    """Because users can set any fields on `build`, it may have multiple IDs."""
    ret = set()

    if build.swarming.task.task_id:
      ret.add('swarming/' + build.swarming.task.task_id)

    if build.buildbucket.bbagent_args.build.id:
      ret.add('buildbucket/build/%s'
              % (build.buildbucket.bbagent_args.build.id,))

    if build.buildbucket.bbagent_args.build.builder.bucket:
      ret.add('buildbucket/builder/%s/%s/%s' % (
        build.buildbucket.bbagent_args.build.builder.project,
        build.buildbucket.bbagent_args.build.builder.bucket,
        build.buildbucket.bbagent_args.build.builder.builder))

    return ret 
开发者ID:luci,项目名称:recipes-py,代码行数:20,代码来源:test_api.py

示例5: make_channel

# 需要导入模块: import attr [as 别名]
# 或者: from attr import s [as 别名]
def make_channel(self):
    """Returns a single-slot communication device for passing data and control
    between concurrent functions.

    This is useful for running 'background helper' type concurrent processes.

    NOTE: It is strongly discouraged to pass Channel objects outside of a recipe
    module. Access to the channel should be mediated via
    a class/contextmanager/function which you return to the caller, and the
    caller can call in a makes-sense-for-your-moudle's-API way.

    See ./tests/background_helper.py for an example of how to use a Channel
    correctly.

    It is VERY RARE to need to use a Channel. You should avoid using this unless
    you carefully consider and avoid the possibility of introducing deadlocks.

    Channels will raise ValueError if used with @@@annotation@@@ mode.
    """
    if not self.concurrency_client.supports_concurrency: # pragma: no cover
      # test mode always supports concurrency, hence the nocover
      raise ValueError('Channels are not allowed in @@@annotation@@@ mode')
    return gevent.queue.Channel() 
开发者ID:luci,项目名称:recipes-py,代码行数:25,代码来源:api.py

示例6: from_step_dict

# 需要导入模块: import attr [as 别名]
# 或者: from attr import s [as 别名]
def from_step_dict(cls, step_dict):
    """Create a `Step` from a step dictionary.

    Args:
      * step_dict - Dictionary containing the data to be written out to the
          expectation file for the step. All keys in the dictionary must match
          the name of one of the fields of `Step`.

    Returns:
      A `Step` object where for each item in `step_dict`, the field whose name
      matches the item's key is set to the item's value.
    """
    if 'name' not in step_dict:
      raise ValueError("step dict must have 'name' key, step dict keys: %r"
                       % sorted(step_dict.iterkeys()))
    if 'cmd' in step_dict or 'cost' in step_dict:
      step_dict = step_dict.copy()
      if 'cmd' in step_dict:
        step_dict['cmd'] = Command(step_dict['cmd'])
      if 'cost' in step_dict and step_dict['cost'] is not None:
        step_dict['cost'] = ResourceCost(**step_dict['cost'])
    return cls(**step_dict) 
开发者ID:luci,项目名称:recipes-py,代码行数:24,代码来源:post_process_inputs.py

示例7: render

# 需要导入模块: import attr [as 别名]
# 或者: from attr import s [as 别名]
def render(self):
    escape_parens = lambda link: link.replace('(', r'\(').replace(')', r'\)')

    paragraphs = []

    if self._step_summary_text:
      paragraphs.append(self._step_summary_text)

    if self._step_text:
      paragraphs.append(self._step_text)

    if self._step_links:
      paragraphs.append(
          '\n'.join(
              '  * [%s](%s)' % (name, escape_parens(link))
              for name, link in self._step_links))

    return '\n\n'.join(paragraphs) 
开发者ID:luci,项目名称:recipes-py,代码行数:20,代码来源:luci.py

示例8: _print_summary_info

# 需要导入模块: import attr [as 别名]
# 或者: from attr import s [as 别名]
def _print_summary_info(verbose, use_emoji, test_name, test_result,
                        space_for_columns):
  # Pick the first populated field in the TestResults.Results
  for field_name in FIELD_TO_DISPLAY:
    (success, verbose_msg, emj, txt), _ = _check_field(test_result, field_name)
    icon = emj if use_emoji else txt
    if icon:
      break

  if verbose:
    msg = '' if not verbose_msg else ' (%s)' % verbose_msg
    print '%s ... %s%s' % (test_name, 'ok' if success else 'FAIL', msg)
  else:
    space_for_columns(1 if len(icon) == 1 else 2)
    sys.stdout.write(icon)
  sys.stdout.flush() 
开发者ID:luci,项目名称:recipes-py,代码行数:18,代码来源:report.py

示例9: gen_tests

# 需要导入模块: import attr [as 别名]
# 或者: from attr import s [as 别名]
def gen_tests(self):
    """Runs this recipe's GenTests function.

    Yields all TestData fixtures for this recipe. Fills in the .expect_file
    property on each with an absolute path to the expectation file.
    """
    api = RecipeTestApi(module=None)
    resolved_deps = _resolve(
      self.repo.recipe_deps, self.normalized_DEPS, 'TEST_API', None, None)
    api.__dict__.update({
      local_name: resolved_dep
      for local_name, resolved_dep in resolved_deps.iteritems()
      if resolved_dep is not None
    })
    for test_data in self.global_symbols['GenTests'](api):
      test_data.expect_file = os.path.join(
          self.expectation_dir, filesystem_safe(test_data.name),
      ) + '.json'
      yield test_data 
开发者ID:luci,项目名称:recipes-py,代码行数:21,代码来源:recipe_deps.py

示例10: register_step_config

# 需要导入模块: import attr [as 别名]
# 或者: from attr import s [as 别名]
def register_step_config(self, name_token, step_config):
    """Called to register the precursor of the step (the StepConfig).

    Only used for the simulation API.

    TODO(iannucci): Change all step expectations to instead reflect the engine's
    intent (i.e. the Step object passed to `run`). Currently this is used to
    provide env_prefixes, env_suffixes as distinct from env. However, it may be
    "just fine" to instead only record env in the test expectations (i.e. using
    FakeEnviron as a basis environment).

    Args:
      * name_tokens (List[str]) - The full name of the step.
      * step_config (StepConfig) - The full precursor of the step.
    """
    pass 
开发者ID:luci,项目名称:recipes-py,代码行数:18,代码来源:__init__.py

示例11: placeholder

# 需要导入模块: import attr [as 别名]
# 或者: from attr import s [as 别名]
def placeholder(self, name_tokens, placeholder):
    """Returns PlaceholderTestData for the given step and placeholder
    combination.

    Note: This may be called multiple times for the same step/placeholder
    combination. It should always return the same test data.

    Args:

      * name_tokens (List[str]) - The full name of the step.
      * placeholder (Placeholder) - The actual placeholder to resolve for.
        This may inspect the placeholder's namespaces and/or name.

    Returns PlaceholderTestData (or BaseTestData with enabled=False).
    """
    return BaseTestData(False) 
开发者ID:luci,项目名称:recipes-py,代码行数:18,代码来源:__init__.py

示例12: resolve_cmd0

# 需要导入模块: import attr [as 别名]
# 或者: from attr import s [as 别名]
def resolve_cmd0(self, name_tokens, debug_log, cmd0, cwd, paths):
    """Should resolve the 0th argument of the command (`cmd0`) to an absolute
    path to the intended executable.

    Args:
      * name_tokens (List[str]) - The full name of the step.
      * debug_log (Stream) - The log where debugging information about the
        StepRunner's thought process should go.
      * cmd0 (str) - The executable to resolve. Note that this may be a relative
        path (e.g. './foo').
      * cwd (str) - The absolute cwd for the step.
      * paths (List[str]) - The current split value of $PATH.

    Returns the absolute path to the intended executable, if found, or None if
    it couldn't be discovered.
    """
    return cmd0 
开发者ID:luci,项目名称:recipes-py,代码行数:19,代码来源:__init__.py

示例13: run_noop

# 需要导入模块: import attr [as 别名]
# 或者: from attr import s [as 别名]
def run_noop(self, name_tokens, debug_log):
    """Runs a no-op step.

    This may occur becuase the recipe needs to establish some step for UI
    purposes, but is also used for some recipes which run test steps without
    actual content (and so the simulations need an API point to return mocked
    ExecutionResult data).

    Args:
      * name_tokens (List[str]) - The full name of the step.
      * debug_log (Stream) - The log where debugging information about the
        StepRunner's thought process should go.

    Returns recipe_engine.step_data.ExecutionResult.
    """
    return ExecutionResult(retcode=0) 
开发者ID:luci,项目名称:recipes-py,代码行数:18,代码来源:__init__.py

示例14: export_steps_ran

# 需要导入模块: import attr [as 别名]
# 或者: from attr import s [as 别名]
def export_steps_ran(self):
    """Returns a dictionary of all steps run.

    This maps from the step's dot-name to dictionaries of:

      * name (str) - The step's dot-name
      * cmd (List[str]) - The command
      * cwd (str) - The current working directory
      * env (Dict[str, (str|None)]) - Mapping of direct environment
        replacements.
      * env_prefixes (Dict[str, List[str]]) - Mapping of direct environment
        replacements which should be joined at the beginning of the env key with
        os.pathsep.
      * env_suffixes (Dict[str, List[str]]) - Mapping of direct environment
        replacements which should be joined at the end of the env key with
        os.pathsep.
      * infra_step (bool) - If this step was intended to be an 'infra step' or
        not.
      * timeout (int) - The timeout, in seconds.

    TODO(iannucci): Make this map to a real type.
    """
    return self._step_history.copy() 
开发者ID:luci,项目名称:recipes-py,代码行数:25,代码来源:sim.py

示例15: record_import_warning

# 需要导入模块: import attr [as 别名]
# 或者: from attr import s [as 别名]
def record_import_warning(self, name, importer):
    """Record the warning issued during DEPS resolution and its cause (
    warning_pb.ImportSite).

    Args:
      * name (str): Fully qualified warning name (e.g. repo_name/WARNING_NAME)
      * importer (Recipe|RecipeModule): The recipe or recipe module which
      depends on a recipe module with given warning name declared

    Raise ValueError if the importer is not instance of Recipe or RecipeModule
    """
    if not isinstance(importer, (Recipe, RecipeModule)):
      raise ValueError(
        "Expect importer to be either type %s or %s. Got %s" % (
          RecipeModule.__name__, Recipe.__name__, type(importer)))
    import_site = ImportSite(
      repo=importer.repo.name,
      module=importer.name if isinstance(importer, RecipeModule) else None,
      recipe=importer.name if isinstance(importer, Recipe) else None,
    )
    if (import_site not in self._recorded_warnings[name]) and (
        self.import_site_filter(name, import_site.cause_pb)):
        self._recorded_warnings[name].add(import_site) 
开发者ID:luci,项目名称:recipes-py,代码行数:25,代码来源:record.py


注:本文中的attr.s方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。