<commit_before># Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from recipe_engine import recipe_api
from recipe_engine.config_types import Path, NamedBasePath


class InfraPathsApi(recipe_api.RecipeApi):
  def get_config_defaults(self):
    return {
      'PLATFORM': self.m.platform.name,
      'CURRENT_WORKING_DIR': self.m.path['cwd'],
      'ROOT': self.m.path['root'],
    }

  def __init__(self, **kwargs):
    super(InfraPathsApi, self).__init__(**kwargs)
    self._config_set = False

  def _lazy_set_config(self):
    if self._config_set:
      return
    self._config_set = True

    path_config = self.m.properties.get('path_config')
    if path_config in ('kitchen',):
      self.set_config(path_config)
    else:
      self.set_config('buildbot')

    for path in self._test_data.get('exists', []):
      assert isinstance(path.base, NamedBasePath)
      self.m.path.mock_add_paths(self[path.base.name].join(*path.pieces))

  def __getitem__(self, name):
    self._lazy_set_config()
    return self.c.paths[name]
<commit_msg>depot_tools: only add mock infra_paths when test data is enabled<commit_after># Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from recipe_engine import recipe_api
from recipe_engine.config_types import Path, NamedBasePath


class InfraPathsApi(recipe_api.RecipeApi):
  def get_config_defaults(self):
    return {
      'PLATFORM': self.m.platform.name,
      'CURRENT_WORKING_DIR': self.m.path['cwd'],
      'ROOT': self.m.path['root'],
    }

  def __init__(self, **kwargs):
    super(InfraPathsApi, self).__init__(**kwargs)
    self._config_set = False

  def _lazy_set_config(self):
    if self._config_set:
      return
    self._config_set = True

    path_config = self.m.properties.get('path_config')
    if path_config in ('kitchen',):
      self.set_config(path_config)
    else:
      self.set_config('buildbot')

    if self._test_data.enabled:
      for path in self._test_data.get('exists', []):
        assert isinstance(path.base, NamedBasePath)
        self.m.path.mock_add_paths(self[path.base.name].join(*path.pieces))

  def __getitem__(self, name):
    self._lazy_set_config()
    return self.c.paths[name]

{'fraction_non_alphanumeric': 0.1127348643006263, 'fraction_numerical': 0.003340292275574113, 'mean_word_length': 3.753968253968254, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5195985', 'n_tokens_mistral': 802, 'n_tokens_neox': 776, 'n_words': 181}